ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObjContentObjectAccess.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
6include_once("./Services/Object/classes/class.ilObjectAccess.php");
7
18{
22 protected $user;
23
27 protected $lng;
28
32 protected $rbacsystem;
33
37 protected $access;
38
39
43 public function __construct()
44 {
45 global $DIC;
46
47 $this->user = $DIC->user();
48 $this->lng = $DIC->language();
49 $this->rbacsystem = $DIC->rbac()->system();
50 $this->access = $DIC->access();
51 }
52
53 public static $online;
54 public static $lo_access;
55
68 public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
69 {
73 $ilAccess = $this->access;
74
75 if ($a_user_id == "") {
76 $a_user_id = $ilUser->getId();
77 }
78
79 switch ($a_cmd) {
80 case "view":
81
83 && !$rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id)) {
84 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
85 return false;
86 }
87 break;
88
89 case "continue":
90 if (!$rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id)) {
92 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
93 return false;
94 }
95 }
96
97 // continue is now default and works all the time
98 // see ilLMPresentationGUI::resume()
99 /*
100 if ($ilUser->getId() == ANONYMOUS_USER_ID)
101 {
102 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("lm_no_continue_for_anonym"));
103 return false;
104 }
105 if (ilObjContentObjectAccess::_getLastAccessedPage($a_ref_id,$a_user_id) <= 0)
106 {
107 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("not_accessed_yet"));
108 return false;
109 }
110 */
111 break;
112
113 // for permission query feature
114 case "info":
116 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
117 } else {
118 $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("online"));
119 }
120 break;
121
122 }
123
124 switch ($a_permission) {
125 case "read":
126 case "visible":
128 (!$rbacsystem->checkAccessOfUser($a_user_id, 'write', $a_ref_id))) {
129 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
130 return false;
131 }
132 break;
133 }
134
135
136 return true;
137 }
138
139 //
140 // access relevant methods
141 //
142
148 public static function _lookupOnline($a_id)
149 {
150 global $DIC;
151
152 $ilDB = $DIC->database();
153
154 if (isset(self::$online[$a_id])) {
155 return self::$online[$a_id];
156 }
157
158 $q = "SELECT is_online FROM content_object WHERE id = " . $ilDB->quote($a_id, "integer");
159 $lm_set = $ilDB->query($q);
160 $lm_rec = $ilDB->fetchAssoc($lm_set);
161
162 self::$online[$a_id] = ilUtil::yn2tf($lm_rec["is_online"]);
163 return ilUtil::yn2tf($lm_rec["is_online"]);
164 }
165
172 public static function _getLastAccessedPage($a_ref_id, $a_user_id = "")
173 {
174 global $DIC;
175
176 $ilDB = $DIC->database();
177 $ilUser = $DIC->user();
178
179 if ($a_user_id == "") {
180 $a_user_id = $ilUser->getId();
181 }
182
183 if (isset(self::$lo_access[$a_ref_id])) {
184 $acc_rec["obj_id"] = self::$lo_access[$a_ref_id];
185 } else {
186 $q = "SELECT * FROM lo_access WHERE " .
187 "usr_id = " . $ilDB->quote($a_user_id, "integer") . " AND " .
188 "lm_id = " . $ilDB->quote($a_ref_id, "integer");
189
190 $acc_set = $ilDB->query($q);
191 $acc_rec = $ilDB->fetchAssoc($acc_set);
192 }
193
194 if ($acc_rec["obj_id"] > 0) {
195 $lm_id = ilObject::_lookupObjId($a_ref_id);
196 $mtree = new ilTree($lm_id);
197 $mtree->setTableNames('lm_tree', 'lm_data');
198 $mtree->setTreeTablePK("lm_id");
199 if ($mtree->isInTree($acc_rec["obj_id"])) {
200 return $acc_rec["obj_id"];
201 }
202 }
203
204 return 0;
205 }
206
210 public static function _checkGoto($a_target)
211 {
212 global $DIC;
213
214 $ilAccess = $DIC->access();
215
216 $t_arr = explode("_", $a_target);
217
218 if (($t_arr[0] != "lm" && $t_arr[0] != "st"
219 && $t_arr[0] != "pg")
220 || ((int) $t_arr[1]) <= 0) {
221 return false;
222 }
223
224 if ($t_arr[0] == "lm") {
225 if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
226 $ilAccess->checkAccess("visible", "", $t_arr[1])) {
227 return true;
228 }
229 } else {
230 if ($t_arr[2] > 0) {
231 $ref_ids = array($t_arr[2]);
232 } else {
233 // determine learning object
234 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
235 $lm_id = ilLMObject::_lookupContObjID($t_arr[1]);
236 $ref_ids = ilObject::_getAllReferences($lm_id);
237 }
238 // check read permissions
239 foreach ($ref_ids as $ref_id) {
240 // Permission check
241 if ($ilAccess->checkAccess("read", "", $ref_id)) {
242 return true;
243 }
244 }
245 }
246 return false;
247 }
248
257 public static function _isOffline($a_obj_id)
258 {
259 return !self::_lookupOnline($a_obj_id);
260 }
261
267 public static function _preloadData($a_obj_ids, $a_ref_ids)
268 {
269 global $DIC;
270
271 $ilDB = $DIC->database();
272 $ilUser = $DIC->user();
273
274 $q = "SELECT id, is_online FROM content_object WHERE " .
275 $ilDB->in("id", $a_obj_ids, false, "integer");
276
277 $lm_set = $ilDB->query($q);
278 while ($rec = $ilDB->fetchAssoc($lm_set)) {
279 self::$online[$rec["id"]] = ilUtil::yn2tf($rec["is_online"]);
280 }
281
282 $q = "SELECT obj_id, lm_id FROM lo_access WHERE " .
283 "usr_id = " . $ilDB->quote($ilUser->getId(), "integer") . " AND " .
284 $ilDB->in("lm_id", $a_ref_ids, false, "integer");
285 ;
286 $set = $ilDB->query($q);
287 foreach ($a_ref_ids as $r) {
288 self::$lo_access[$r] = 0;
289 }
290 while ($rec = $ilDB->fetchAssoc($set)) {
291 self::$lo_access[$rec["lm_id"]] = $rec["obj_id"];
292 }
293 }
294}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
const IL_STATUS_MESSAGE
const IL_NO_OBJECT_ACCESS
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
Class ilObjContentObjectAccess.
_checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id="")
checks wether a user may invoke a command or not (this method is called by ilAccessHandler::checkAcce...
static _isOffline($a_obj_id)
Type-specific implementation of general status.
static _lookupOnline($a_id)
check wether learning module is online
static _preloadData($a_obj_ids, $a_ref_ids)
Preload data.
static _getLastAccessedPage($a_ref_id, $a_user_id="")
get last accessed page
static _checkGoto($a_target)
check whether goto script will succeed
Class ilObjectAccess.
static _lookupObjId($a_id)
static _getAllReferences($a_id)
get all reference ids of object
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static yn2tf($a_yn)
convert "y"/"n" to true/false
$r
Definition: example_031.php:79
global $DIC
Definition: saml.php:7
global $ilDB
$lm_set
$ilUser
Definition: imgupload.php:18