ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilPortfolioAccessHandler.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
6 include_once "Modules/Group/classes/class.ilGroupParticipants.php";
7 include_once "Modules/Course/classes/class.ilCourseParticipants.php";
8 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
9 
19 {
20  public function __construct()
21  {
22  global $lng;
23  $lng->loadLanguageModule("wsp");
24  }
25 
35  public function checkAccess($a_permission, $a_cmd, $a_node_id, $a_type = "")
36  {
37  global $ilUser;
38 
39  return $this->checkAccessOfUser($ilUser->getId(),$a_permission, $a_cmd, $a_node_id, $a_type);
40  }
41 
52  public function checkAccessOfUser($a_user_id, $a_permission, $a_cmd, $a_node_id, $a_type = "")
53  {
54  global $rbacreview, $ilUser, $ilSetting;
55 
56  // #12059
57  if (!$ilSetting->get('user_portfolios'))
58  {
59  return false;
60  }
61 
62  // :TODO: create permission for parent node with type ?!
63 
64  $pf = new ilObjPortfolio($a_node_id, false);
65  if(!$pf->getId())
66  {
67  return false;
68  }
69 
70  // portfolio owner has all rights
71  if($pf->getOwner() == $a_user_id)
72  {
73  return true;
74  }
75 
76  // other users can only read
77  if($a_permission == "read" || $a_permission == "visible")
78  {
79  // get all objects with explicit permission
80  $objects = $this->getPermissions($a_node_id);
81  if($objects)
82  {
83  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
84 
85  // check if given user is member of object or has role
86  foreach($objects as $obj_id)
87  {
88  switch($obj_id)
89  {
91  return true;
92 
94  // check against input kept in session
95  if(self::getSharedNodePassword($a_node_id) == self::getSharedSessionPassword($a_node_id) ||
96  $a_permission == "visible")
97  {
98  return true;
99  }
100  break;
101 
103  if($ilUser->getId() != ANONYMOUS_USER_ID)
104  {
105  return true;
106  }
107  break;
108 
109  default:
110  switch(ilObject::_lookupType($obj_id))
111  {
112  case "grp":
113  // member of group?
114  if(ilGroupParticipants::_getInstanceByObjId($obj_id)->isAssigned($a_user_id))
115  {
116  return true;
117  }
118  break;
119 
120  case "crs":
121  // member of course?
122  if(ilCourseParticipants::_getInstanceByObjId($obj_id)->isAssigned($a_user_id))
123  {
124  return true;
125  }
126  break;
127 
128  case "role":
129  // has role?
130  if($rbacreview->isAssigned($a_user_id, $obj_id))
131  {
132  return true;
133  }
134  break;
135 
136  case "usr":
137  // direct assignment
138  if($a_user_id == $obj_id)
139  {
140  return true;
141  }
142  break;
143  }
144  break;
145  }
146  }
147  }
148  }
149 
150  return false;
151  }
152 
159  public function setPermissions($a_parent_node_id, $a_node_id)
160  {
161  // nothing to do as owner has irrefutable rights to any portfolio object
162  }
163 
171  public function addPermission($a_node_id, $a_object_id, $a_extended_data = null)
172  {
173  global $ilDB, $ilUser;
174 
175  // current owner must not be added
176  if($a_object_id == $ilUser->getId())
177  {
178  return;
179  }
180 
181  $ilDB->manipulate("INSERT INTO usr_portf_acl (node_id, object_id, extended_data)".
182  " VALUES (".$ilDB->quote($a_node_id, "integer").", ".
183  $ilDB->quote($a_object_id, "integer").",".
184  $ilDB->quote($a_extended_data, "text").")");
185 
186  // portfolio as profile
187  $this->syncProfile($a_node_id);
188  }
189 
196  public function removePermission($a_node_id, $a_object_id = null)
197  {
198  global $ilDB;
199 
200  $query = "DELETE FROM usr_portf_acl".
201  " WHERE node_id = ".$ilDB->quote($a_node_id, "integer");
202 
203  if($a_object_id)
204  {
205  $query .= " AND object_id = ".$ilDB->quote($a_object_id, "integer");
206  }
207 
208  $ilDB->manipulate($query);
209 
210  // portfolio as profile
211  $this->syncProfile($a_node_id);
212  }
213 
220  public function getPermissions($a_node_id)
221  {
222  global $ilDB;
223 
224  $set = $ilDB->query("SELECT object_id FROM usr_portf_acl".
225  " WHERE node_id = ".$ilDB->quote($a_node_id, "integer"));
226  $res = array();
227  while($row = $ilDB->fetchAssoc($set))
228  {
229  $res[] = $row["object_id"];
230  }
231  return $res;
232  }
233 
234  public function hasRegisteredPermission($a_node_id)
235  {
236  global $ilDB;
237 
238  $set = $ilDB->query("SELECT object_id FROM usr_portf_acl".
239  " WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
240  " AND object_id = ".$ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_REGISTERED, "integer"));
241  return (bool)$ilDB->numRows($set);
242  }
243 
244  public function hasGlobalPermission($a_node_id)
245  {
246  global $ilDB;
247 
248  $set = $ilDB->query("SELECT object_id FROM usr_portf_acl".
249  " WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
250  " AND object_id = ".$ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_ALL, "integer"));
251  return (bool)$ilDB->numRows($set);
252  }
253 
254  public function hasGlobalPasswordPermission($a_node_id)
255  {
256  global $ilDB;
257 
258  $set = $ilDB->query("SELECT object_id FROM usr_portf_acl".
259  " WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
260  " AND object_id = ".$ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, "integer"));
261  return (bool)$ilDB->numRows($set);
262  }
263 
264  public function getObjectsIShare()
265  {
266  global $ilDB, $ilUser;
267 
268  $res = array();
269  $set = $ilDB->query("SELECT obj.obj_id".
270  " FROM object_data obj".
271  " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)".
272  " WHERE obj.owner = ".$ilDB->quote($ilUser->getId(), "integer"));
273  while ($row = $ilDB->fetchAssoc($set))
274  {
275  $res[] = $row["obj_id"];
276  }
277 
278  return $res;
279  }
280 
281  public static function getPossibleSharedTargets()
282  {
283  global $ilUser;
284 
285  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
286  include_once "Services/Membership/classes/class.ilParticipants.php";
287  $grp_ids = ilParticipants::_getMembershipByType($ilUser->getId(), "grp");
288  $crs_ids = ilParticipants::_getMembershipByType($ilUser->getId(), "crs");
289 
290  $obj_ids = array_merge($grp_ids, $crs_ids);
291  $obj_ids[] = $ilUser->getId();
295 
296  return $obj_ids;
297  }
298 
299  public function getSharedOwners()
300  {
301  global $ilUser, $ilDB;
302 
303  $obj_ids = $this->getPossibleSharedTargets();
304 
305  $user_ids = array();
306  $set = $ilDB->query("SELECT DISTINCT(obj.owner), u.lastname, u.firstname, u.title".
307  " FROM object_data obj".
308  " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)".
309  " JOIN usr_data u on (u.usr_id = obj.owner)".
310  " WHERE ".$ilDB->in("acl.object_id", $obj_ids, "", "integer").
311  " AND obj.owner <> ".$ilDB->quote($ilUser->getId(), "integer").
312  " ORDER BY u.lastname, u.firstname, u.title");
313  while ($row = $ilDB->fetchAssoc($set))
314  {
315  $user_ids[$row["owner"]] = $row["lastname"].", ".$row["firstname"];
316  if($row["title"])
317  {
318  $user_ids[$row["owner"]] .= ", ".$row["title"];
319  }
320  }
321 
322  return $user_ids;
323  }
324 
325  public function getSharedObjects($a_owner_id)
326  {
327  global $ilDB;
328 
329  $obj_ids = $this->getPossibleSharedTargets();
330 
331  $res = array();
332  $set = $ilDB->query("SELECT obj.obj_id".
333  " FROM object_data obj".
334  " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)".
335  " WHERE ".$ilDB->in("acl.object_id", $obj_ids, "", "integer").
336  " AND obj.owner = ".$ilDB->quote($a_owner_id, "integer"));
337  while ($row = $ilDB->fetchAssoc($set))
338  {
339  $res[$row["obj_id"]] = $row["obj_id"];
340  }
341 
342  return $res;
343  }
344 
345  public static function getSharedNodePassword($a_node_id)
346  {
347  global $ilDB;
348 
349  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
350 
351  $set = $ilDB->query("SELECT extended_data FROM usr_portf_acl".
352  " WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
353  " AND object_id = ".$ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, "integer"));
354  $res = $ilDB->fetchAssoc($set);
355  if($res)
356  {
357  return $res["extended_data"];
358  }
359  }
360 
361  public static function keepSharedSessionPassword($a_node_id, $a_password)
362  {
363  $_SESSION["ilshpw_".$a_node_id] = $a_password;
364  }
365 
366  public static function getSharedSessionPassword($a_node_id)
367  {
368  return $_SESSION["ilshpw_".$a_node_id];
369  }
370 
371  protected function syncProfile($a_node_id)
372  {
373  global $ilUser;
374 
375  // #12845
376  include_once "Services/Portfolio/classes/class.ilObjPortfolio.php";
377  if(ilObjPortfolio::getDefaultPortfolio($ilUser->getId()) == $a_node_id)
378  {
379  $has_registered = $this->hasRegisteredPermission($a_node_id);
380  $has_global = $this->hasGlobalPermission($a_node_id);
381 
382  // not published anymore - remove portfolio as profile
383  if(!$has_registered && !$has_global)
384  {
385  $ilUser->setPref("public_profile", "n");
386  $ilUser->writePrefs();
387  ilObjPortfolio::setUserDefault($ilUser->getId());
388  }
389  // adapt profile setting
390  else
391  {
392  $new_pref = "y";
393  if($has_global)
394  {
395  $new_pref = "g";
396  }
397  if($ilUser->getPref("public_profile") != $new_pref)
398  {
399  $ilUser->setPref("public_profile", $new_pref);
400  $ilUser->writePrefs();
401  }
402  }
403  }
404  }
405 }
406 
407 ?>