ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
19 static $online;
20 static $lo_access;
21
34 function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
35 {
36 global $ilUser, $lng, $rbacsystem, $ilAccess;
37
38 if ($a_user_id == "")
39 {
40 $a_user_id = $ilUser->getId();
41 }
42
43 switch ($a_cmd)
44 {
45 case "view":
46
48 && !$rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id))
49 {
50 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
51 return false;
52 }
53 break;
54
55 case "continue":
56 if(!$rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id))
57 {
59 {
60 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
61 return false;
62 }
63 }
64
65 // continue is now default and works all the time
66 // see ilLMPresentationGUI::resume()
67 /*
68 if ($ilUser->getId() == ANONYMOUS_USER_ID)
69 {
70 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("lm_no_continue_for_anonym"));
71 return false;
72 }
73 if (ilObjContentObjectAccess::_getLastAccessedPage($a_ref_id,$a_user_id) <= 0)
74 {
75 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("not_accessed_yet"));
76 return false;
77 }
78 */
79 break;
80
81 // for permission query feature
82 case "info":
84 {
85 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
86 }
87 else
88 {
89 $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("online"));
90 }
91 break;
92
93 }
94
95 switch ($a_permission)
96 {
97 case "read":
98 case "visible":
100 (!$rbacsystem->checkAccessOfUser($a_user_id,'write', $a_ref_id)))
101 {
102 $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
103 return false;
104 }
105 break;
106 }
107
108
109 return true;
110 }
111
112 //
113 // access relevant methods
114 //
115
121 function _lookupOnline($a_id)
122 {
123 global $ilDB;
124
125 if (isset(self::$online[$a_id]))
126 {
127 return self::$online[$a_id];
128 }
129
130 $q = "SELECT is_online FROM content_object WHERE id = ".$ilDB->quote($a_id, "integer");
131 $lm_set = $ilDB->query($q);
132 $lm_rec = $ilDB->fetchAssoc($lm_set);
133
134 self::$online[$a_id] = ilUtil::yn2tf($lm_rec["is_online"]);
135 return ilUtil::yn2tf($lm_rec["is_online"]);
136 }
137
144 function _getLastAccessedPage($a_ref_id, $a_user_id = "")
145 {
146 global $ilDB, $ilUser;
147
148 if ($a_user_id == "")
149 {
150 $a_user_id = $ilUser->getId();
151 }
152
153 if (isset(self::$lo_access[$a_ref_id]))
154 {
155 $acc_rec["obj_id"] = self::$lo_access[$a_ref_id];
156 }
157 else
158 {
159 $q = "SELECT * FROM lo_access WHERE ".
160 "usr_id = ".$ilDB->quote($a_user_id, "integer")." AND ".
161 "lm_id = ".$ilDB->quote($a_ref_id, "integer");
162
163 $acc_set = $ilDB->query($q);
164 $acc_rec = $ilDB->fetchAssoc($acc_set);
165 }
166
167 if ($acc_rec["obj_id"] > 0)
168 {
169 $lm_id = ilObject::_lookupObjId($a_ref_id);
170 $mtree = new ilTree($lm_id);
171 $mtree->setTableNames('lm_tree','lm_data');
172 $mtree->setTreeTablePK("lm_id");
173 if ($mtree->isInTree($acc_rec["obj_id"]))
174 {
175 return $acc_rec["obj_id"];
176 }
177 }
178
179 return 0;
180 }
181
185 function _checkGoto($a_target)
186 {
187 global $ilAccess;
188
189 $t_arr = explode("_", $a_target);
190
191 if (($t_arr[0] != "lm" && $t_arr[0] != "dbk" && $t_arr[0] != "st"
192 && $t_arr[0] != "pg")
193 || ((int) $t_arr[1]) <= 0)
194 {
195 return false;
196 }
197
198 if ($t_arr[0] == "lm" || $t_arr[0] == "dbk")
199 {
200 if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
201 $ilAccess->checkAccess("visible", "", $t_arr[1]))
202 {
203 return true;
204 }
205 }
206 else
207 {
208 if ($t_arr[2] > 0)
209 {
210 $ref_ids = array($t_arr[2]);
211 }
212 else
213 {
214 // determine learning object
215 include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
216 $lm_id = ilLMObject::_lookupContObjID($t_arr[1]);
217 $ref_ids = ilObject::_getAllReferences($lm_id);
218 }
219 // check read permissions
220 foreach ($ref_ids as $ref_id)
221 {
222 // Permission check
223 if ($ilAccess->checkAccess("read", "", $ref_id))
224 {
225 return true;
226 }
227 }
228
229 }
230 return false;
231 }
232
241 static function _isOffline($a_obj_id)
242 {
243 return !self::_lookupOnline($a_obj_id);
244 }
245
251 function _preloadData($a_obj_ids, $a_ref_ids)
252 {
253 global $ilDB, $ilUser;
254
255 $q = "SELECT id, is_online FROM content_object WHERE ".
256 $ilDB->in("id", $a_obj_ids, false, "integer");
257
258 $lm_set = $ilDB->query($q);
259 while ($rec = $ilDB->fetchAssoc($lm_set))
260 {
261 self::$online[$rec["id"]] = ilUtil::yn2tf($rec["is_online"]);
262 }
263
264 $q = "SELECT obj_id, lm_id FROM lo_access WHERE ".
265 "usr_id = ".$ilDB->quote($ilUser->getId(), "integer")." AND ".
266 $ilDB->in("lm_id", $a_ref_ids, false, "integer");;
267 $set = $ilDB->query($q);
268 foreach ($a_ref_ids as $r)
269 {
270 self::$lo_access[$r] = 0;
271 }
272 while ($rec = $ilDB->fetchAssoc($set))
273 {
274 self::$lo_access[$rec["lm_id"]] = $rec["obj_id"];
275 }
276
277 }
278
279}
280
281?>
const IL_NO_OBJECT_ACCESS
_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.
_lookupOnline($a_id)
check wether learning module is online
_preloadData($a_obj_ids, $a_ref_ids)
Preload data.
_checkGoto($a_target)
check whether goto script will succeed
_getLastAccessedPage($a_ref_id, $a_user_id="")
get last accessed page
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 $lng
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
global $ilDB
$lm_set
global $ilUser
Definition: imgupload.php:15