ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
5include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
6include_once "Modules/Group/classes/class.ilGroupParticipants.php";
7include_once "Modules/Course/classes/class.ilCourseParticipants.php";
8include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
9require_once('./Services/WebAccessChecker/interfaces/interface.ilWACCheckingClass.php');
10
20{
21 public function __construct()
22 {
23 global $lng;
24 $lng->loadLanguageModule("wsp");
25 }
26
36 public function checkAccess($a_permission, $a_cmd, $a_node_id, $a_type = "")
37 {
38 global $ilUser;
39
40 return $this->checkAccessOfUser($ilUser->getId(),$a_permission, $a_cmd, $a_node_id, $a_type);
41 }
42
53 public function checkAccessOfUser($a_user_id, $a_permission, $a_cmd, $a_node_id, $a_type = "")
54 {
55 global $rbacreview, $ilUser, $ilSetting;
56
57 // #20310
58 if(!$ilSetting->get("enable_global_profiles") && $ilUser->getId() == ANONYMOUS_USER_ID)
59 {
60 return false;
61 }
62
63 // #12059
64 if (!$ilSetting->get('user_portfolios'))
65 {
66 return false;
67 }
68
69 // :TODO: create permission for parent node with type ?!
70
71 $pf = new ilObjPortfolio($a_node_id, false);
72 if(!$pf->getId())
73 {
74 return false;
75 }
76
77 // portfolio owner has all rights
78 if($pf->getOwner() == $a_user_id)
79 {
80 return true;
81 }
82
83 // #11921
84 if(!$pf->isOnline())
85 {
86 return false;
87 }
88
89 // other users can only read
90 if($a_permission == "read" || $a_permission == "visible")
91 {
92 // get all objects with explicit permission
93 $objects = self::_getPermissions($a_node_id);
94 if($objects)
95 {
96 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
97
98 // check if given user is member of object or has role
99 foreach($objects as $obj_id)
100 {
101 switch($obj_id)
102 {
104 return true;
105
107 // check against input kept in session
108 if(self::getSharedNodePassword($a_node_id) == self::getSharedSessionPassword($a_node_id) ||
109 $a_permission == "visible")
110 {
111 return true;
112 }
113 break;
114
116 if($ilUser->getId() != ANONYMOUS_USER_ID)
117 {
118 return true;
119 }
120 break;
121
122 default:
123 switch(ilObject::_lookupType($obj_id))
124 {
125 case "grp":
126 // member of group?
127 if(ilGroupParticipants::_getInstanceByObjId($obj_id)->isAssigned($a_user_id))
128 {
129 return true;
130 }
131 break;
132
133 case "crs":
134 // member of course?
135 if(ilCourseParticipants::_getInstanceByObjId($obj_id)->isAssigned($a_user_id))
136 {
137 return true;
138 }
139 break;
140
141 case "role":
142 // has role?
143 if($rbacreview->isAssigned($a_user_id, $obj_id))
144 {
145 return true;
146 }
147 break;
148
149 case "usr":
150 // direct assignment
151 if($a_user_id == $obj_id)
152 {
153 return true;
154 }
155 break;
156 }
157 break;
158 }
159 }
160 }
161 }
162
163 return false;
164 }
165
172 public function setPermissions($a_parent_node_id, $a_node_id)
173 {
174 // nothing to do as owner has irrefutable rights to any portfolio object
175 }
176
184 public function addPermission($a_node_id, $a_object_id, $a_extended_data = null)
185 {
186 global $ilDB, $ilUser;
187
188 // current owner must not be added
189 if($a_object_id == $ilUser->getId())
190 {
191 return;
192 }
193
194 $ilDB->manipulate("INSERT INTO usr_portf_acl (node_id, object_id, extended_data, tstamp)".
195 " VALUES (".$ilDB->quote($a_node_id, "integer").", ".
196 $ilDB->quote($a_object_id, "integer").",".
197 $ilDB->quote($a_extended_data, "text").",".
198 $ilDB->quote(time(), "integer").")");
199
200 // portfolio as profile
201 $this->syncProfile($a_node_id);
202 }
203
210 public function removePermission($a_node_id, $a_object_id = null)
211 {
212 global $ilDB;
213
214 $query = "DELETE FROM usr_portf_acl".
215 " WHERE node_id = ".$ilDB->quote($a_node_id, "integer");
216
217 if($a_object_id)
218 {
219 $query .= " AND object_id = ".$ilDB->quote($a_object_id, "integer");
220 }
221
222 $ilDB->manipulate($query);
223
224 // portfolio as profile
225 $this->syncProfile($a_node_id);
226 }
227
234 public function getPermissions($a_node_id)
235 {
236 return self::_getPermissions($a_node_id);
237 }
238
245 public static function _getPermissions($a_node_id)
246 {
247 global $ilDB;
248
249 $set = $ilDB->query("SELECT object_id FROM usr_portf_acl".
250 " WHERE node_id = ".$ilDB->quote($a_node_id, "integer"));
251 $res = array();
252 while($row = $ilDB->fetchAssoc($set))
253 {
254 $res[] = $row["object_id"];
255 }
256 return $res;
257 }
258
259 public function hasRegisteredPermission($a_node_id)
260 {
261 global $ilDB;
262
263 $set = $ilDB->query("SELECT object_id FROM usr_portf_acl".
264 " WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
265 " AND object_id = ".$ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_REGISTERED, "integer"));
266 return (bool)$ilDB->numRows($set);
267 }
268
269 public function hasGlobalPermission($a_node_id)
270 {
271 global $ilDB;
272
273 $set = $ilDB->query("SELECT object_id FROM usr_portf_acl".
274 " WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
275 " AND object_id = ".$ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_ALL, "integer"));
276 return (bool)$ilDB->numRows($set);
277 }
278
279 public function hasGlobalPasswordPermission($a_node_id)
280 {
281 global $ilDB;
282
283 $set = $ilDB->query("SELECT object_id FROM usr_portf_acl".
284 " WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
285 " AND object_id = ".$ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, "integer"));
286 return (bool)$ilDB->numRows($set);
287 }
288
289 public function getObjectsIShare($a_online_only = true)
290 {
291 global $ilDB, $ilUser;
292
293 $res = array();
294
295 $sql = "SELECT obj.obj_id".
296 " FROM object_data obj".
297 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)".
298 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)".
299 " WHERE obj.owner = ".$ilDB->quote($ilUser->getId(), "integer");
300
301 if($a_online_only)
302 {
303 $sql .= " AND prtf.is_online = ".$ilDB->quote(1, "integer");
304 }
305
306 $set = $ilDB->query($sql);
307 while ($row = $ilDB->fetchAssoc($set))
308 {
309 $res[] = $row["obj_id"];
310 }
311
312 return $res;
313 }
314
315 public static function getPossibleSharedTargets()
316 {
317 global $ilUser;
318
319 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
320 include_once "Services/Membership/classes/class.ilParticipants.php";
321 $grp_ids = ilParticipants::_getMembershipByType($ilUser->getId(), "grp");
322 $crs_ids = ilParticipants::_getMembershipByType($ilUser->getId(), "crs");
323
324 $obj_ids = array_merge($grp_ids, $crs_ids);
325 $obj_ids[] = $ilUser->getId();
329
330 return $obj_ids;
331 }
332
333 public function getSharedOwners()
334 {
335 global $ilUser, $ilDB;
336
337 $obj_ids = $this->getPossibleSharedTargets();
338
339 $user_ids = array();
340 $set = $ilDB->query("SELECT DISTINCT(obj.owner), u.lastname, u.firstname, u.title".
341 " FROM object_data obj".
342 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)".
343 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)".
344 " JOIN usr_data u on (u.usr_id = obj.owner)".
345 " WHERE ".$ilDB->in("acl.object_id", $obj_ids, "", "integer").
346 " AND obj.owner <> ".$ilDB->quote($ilUser->getId(), "integer").
347 " AND prtf.is_online = ".$ilDB->quote(1, "integer").
348 " ORDER BY u.lastname, u.firstname, u.title");
349 while ($row = $ilDB->fetchAssoc($set))
350 {
351 $user_ids[$row["owner"]] = $row["lastname"].", ".$row["firstname"];
352 if($row["title"])
353 {
354 $user_ids[$row["owner"]] .= ", ".$row["title"];
355 }
356 }
357
358 return $user_ids;
359 }
360
361 public function getSharedObjects($a_owner_id)
362 {
363 global $ilDB;
364
365 $obj_ids = $this->getPossibleSharedTargets();
366
367 $res = array();
368 $set = $ilDB->query("SELECT obj.obj_id, obj.owner".
369 " FROM object_data obj".
370 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)".
371 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)".
372 " WHERE ".$ilDB->in("acl.object_id", $obj_ids, "", "integer").
373 " AND obj.owner = ".$ilDB->quote($a_owner_id, "integer").
374 " AND prtf.is_online = ".$ilDB->quote(1, "integer"));
375 while ($row = $ilDB->fetchAssoc($set))
376 {
377 $res[$row["obj_id"]] = $row["obj_id"];
378 }
379
380 return $res;
381 }
382
383 public function getShardObjectsDataForUserIds(array $a_owner_ids)
384 {
385 global $ilDB;
386
387 $obj_ids = $this->getPossibleSharedTargets();
388
389 $res = array();
390
391 $set = $ilDB->query("SELECT obj.obj_id, obj.owner, obj.title".
392 " FROM object_data obj".
393 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)".
394 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)".
395 " WHERE ".$ilDB->in("acl.object_id", $obj_ids, "", "integer").
396 " AND ".$ilDB->in("obj.owner", $a_owner_ids, "", "integer").
397 " AND prtf.is_online = ".$ilDB->quote(1, "integer"));
398 while ($row = $ilDB->fetchAssoc($set))
399 {
400 $res[$row["owner"]][$row["obj_id"]] = $row["title"];
401 }
402
403 return $res;
404 }
405
406 public function findSharedObjects(array $a_filter = null, array $a_crs_ids = null, array $a_grp_ids = null)
407 {
408 global $ilDB, $ilUser;
409 if(!$a_filter["acl_type"])
410 {
411 $obj_ids = $this->getPossibleSharedTargets();
412 }
413 else
414 {
415 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
416
417 switch($a_filter["acl_type"])
418 {
419 case "all":
420 $obj_ids = array(ilWorkspaceAccessGUI::PERMISSION_ALL);
421 break;
422
423 case "password":
425 break;
426
427 case "registered":
429 break;
430
431 case "course":
432 $obj_ids = $a_crs_ids;
433 break;
434
435 case "group":
436 $obj_ids = $a_grp_ids;
437 break;
438
439 case "user":
440 $obj_ids = array($ilUser->getId());
441 break;
442 }
443 }
444
445 $res = array();
446
447 $sql = "SELECT obj.obj_id,obj.title,obj.owner".
448 ",acl.object_id acl_type, acl.tstamp acl_date".
449 " FROM object_data obj".
450 " JOIN usr_portfolio prtf ON (prtf.id = obj.obj_id)".
451 " JOIN usr_portf_acl acl ON (acl.node_id = obj.obj_id)".
452 " WHERE ".$ilDB->in("acl.object_id", $obj_ids, "", "integer").
453 " AND obj.owner <> ".$ilDB->quote($ilUser->getId(), "integer").
454 " AND obj.type = ".$ilDB->quote("prtf", "text").
455 " AND prtf.is_online = ".$ilDB->quote(1, "integer");
456
457 if($a_filter["title"] && strlen($a_filter["title"]) >= 3)
458 {
459 $sql .= " AND ".$ilDB->like("obj.title", "text", "%".$a_filter["title"]."%");
460 }
461 if($a_filter["user"] && strlen($a_filter["user"]) >= 3)
462 {
463 $usr_ids = array();
464 $set = $ilDB->query("SELECT usr_id FROM usr_data".
465 " WHERE (".$ilDB->like("login", "text", "%".$a_filter["user"]."%")." ".
466 "OR ".$ilDB->like("firstname", "text", "%".$a_filter["user"]."%")." ".
467 "OR ".$ilDB->like("lastname", "text", "%".$a_filter["user"]."%")." ".
468 "OR ".$ilDB->like("email", "text", "%".$a_filter["user"]."%").")");
469 while($row = $ilDB->fetchAssoc($set))
470 {
471 $usr_ids[] = $row["usr_id"];
472 }
473 if(!sizeof($usr_ids))
474 {
475 return;
476 }
477 $sql .= " AND ".$ilDB->in("obj.owner", $usr_ids, "", "integer");
478 }
479
480 if($a_filter["acl_date"])
481 {
482 $dt = $a_filter["acl_date"]->get(IL_CAL_DATE);
483 $dt = new ilDateTime($dt." 00:00:00", IL_CAL_DATETIME);
484 $sql .= " AND acl.tstamp > ".$ilDB->quote($dt->get(IL_CAL_UNIX), "integer");
485 }
486
487 if($a_filter["crsgrp"])
488 {
489 include_once "Services/Membership/classes/class.ilParticipants.php";
490 $part = ilParticipants::getInstanceByObjId($a_filter['crsgrp']);
491 $part = $part->getParticipants();
492 if(!sizeof($part))
493 {
494 return;
495 }
496 $sql .= " AND ".$ilDB->in("obj.owner", $part, "", "integer");
497 }
498
499 // we use the oldest share date
500 $sql .= " ORDER BY acl.tstamp";
501
502 $set = $ilDB->query($sql);
503 while ($row = $ilDB->fetchAssoc($set))
504 {
505 if(!isset($res[$row["obj_id"]]))
506 {
507 $row["acl_type"] = array($row["acl_type"]);
508 $res[$row["obj_id"]] = $row;
509 }
510 else
511 {
512 $res[$row["obj_id"]]["acl_type"][] = $row["acl_type"];
513 }
514 }
515
516 return $res;
517 }
518
519 public static function getSharedNodePassword($a_node_id)
520 {
521 global $ilDB;
522
523 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php";
524
525 $set = $ilDB->query("SELECT extended_data FROM usr_portf_acl".
526 " WHERE node_id = ".$ilDB->quote($a_node_id, "integer").
527 " AND object_id = ".$ilDB->quote(ilWorkspaceAccessGUI::PERMISSION_ALL_PASSWORD, "integer"));
528 $res = $ilDB->fetchAssoc($set);
529 if($res)
530 {
531 return $res["extended_data"];
532 }
533 }
534
535 public static function keepSharedSessionPassword($a_node_id, $a_password)
536 {
537 $_SESSION["ilshpw_".$a_node_id] = $a_password;
538 }
539
540 public static function getSharedSessionPassword($a_node_id)
541 {
542 return $_SESSION["ilshpw_".$a_node_id];
543 }
544
545 protected function syncProfile($a_node_id)
546 {
547 global $ilUser;
548
549 // #12845
550 include_once "Modules/Portfolio/classes/class.ilObjPortfolio.php";
551 if(ilObjPortfolio::getDefaultPortfolio($ilUser->getId()) == $a_node_id)
552 {
553 $has_registered = $this->hasRegisteredPermission($a_node_id);
554 $has_global = $this->hasGlobalPermission($a_node_id);
555
556 // not published anymore - remove portfolio as profile
557 if(!$has_registered && !$has_global)
558 {
559 $ilUser->setPref("public_profile", "n");
560 $ilUser->writePrefs();
562 }
563 // adapt profile setting
564 else
565 {
566 $new_pref = "y";
567 if($has_global)
568 {
569 $new_pref = "g";
570 }
571 if($ilUser->getPref("public_profile") != $new_pref)
572 {
573 $ilUser->setPref("public_profile", $new_pref);
574 $ilUser->writePrefs();
575 }
576 }
577 }
578 }
579
580
586 public function canBeDelivered(ilWACPath $ilWACPath) {
587 global $ilUser, $ilAccess;
588
589 if (preg_match("/\\/prtf_([\\d]*)\\//uism", $ilWACPath->getPath(), $results))
590 {
591 // portfolio (custom)
592 $obj_id = $results[1];
593 if(ilObject::_lookupType($obj_id) == "prtf")
594 {
595 if ($this->checkAccessOfUser($ilUser->getId(), "read", "view", $obj_id, "prtf")) {
596 return true;
597 }
598 }
599 // portfolio template (RBAC)
600 else
601 {
602 $ref_ids = ilObject::_getAllReferences($obj_id);
603 foreach($ref_ids as $ref_id)
604 {
605 if ($ilAccess->checkAccessOfUser($ilUser->getId(), "read", "view", $ref_id, "prtt", $obj_id))
606 {
607 return true;
608 }
609 }
610 }
611 }
612
613 return false;
614 }
615}
616
617?>
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
@classDescription Date and time handling
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
static setUserDefault($a_user_id, $a_portfolio_id=null)
Set the user default portfolio.
static getDefaultPortfolio($a_user_id)
Get default portfolio of user.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstanceByObjId($a_obj_id)
Get instance by obj type.
static _getMembershipByType($a_usr_id, $a_type, $a_only_member_role=false)
get membership by type Get course or group membership
Access handler for portfolio.
addPermission($a_node_id, $a_object_id, $a_extended_data=null)
Add permission to node for object.
findSharedObjects(array $a_filter=null, array $a_crs_ids=null, array $a_grp_ids=null)
checkAccessOfUser($a_user_id, $a_permission, $a_cmd, $a_node_id, $a_type="")
check access for an object
setPermissions($a_parent_node_id, $a_node_id)
Set permissions after creating node/object.
checkAccess($a_permission, $a_cmd, $a_node_id, $a_type="")
check access for an object
static _getPermissions($a_node_id)
Get all permissions to node.
removePermission($a_node_id, $a_object_id=null)
Remove permission[s] (for object) to node.
static keepSharedSessionPassword($a_node_id, $a_password)
getPermissions($a_node_id)
Get all permissions to node.
Class ilWACPath.
Class ilWACCheckingClass.
global $lng
Definition: privfeed.php:17
global $ilSetting
Definition: privfeed.php:17
$ref_id
Definition: sahs_server.php:39
$results
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:93