ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
16 {
20  protected $user;
21 
25  protected $lng;
26 
30  protected $rbacsystem;
31 
35  protected $access;
36 
37 
41  public function __construct()
42  {
43  global $DIC;
44 
45  $this->user = $DIC->user();
46  $this->lng = $DIC->language();
47  $this->rbacsystem = $DIC->rbac()->system();
48  $this->access = $DIC->access();
49  }
50 
51  public static $lo_access;
52 
65  public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
66  {
68  $lng = $this->lng;
70  $ilAccess = $this->access;
71 
72  if ($a_user_id == "") {
73  $a_user_id = $ilUser->getId();
74  }
75 
76  switch ($a_cmd) {
77  case "continue":
78 
79  // continue is now default and works all the time
80  // see ilLMPresentationGUI::resume()
81  /*
82  if ($ilUser->getId() == ANONYMOUS_USER_ID)
83  {
84  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("lm_no_continue_for_anonym"));
85  return false;
86  }
87  if (ilObjContentObjectAccess::_getLastAccessedPage($a_ref_id,$a_user_id) <= 0)
88  {
89  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("not_accessed_yet"));
90  return false;
91  }
92  */
93  break;
94 
95  // for permission query feature
96  case "info":
97  if (!ilObject::lookupOfflineStatus($a_obj_id)) {
98  $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("online"));
99  }
100  break;
101 
102  }
103 
104  return true;
105  }
106 
107  //
108  // access relevant methods
109  //
110 
111 
118  public static function _getLastAccessedPage($a_ref_id, $a_user_id = "")
119  {
120  global $DIC;
121 
122  $ilDB = $DIC->database();
123  $ilUser = $DIC->user();
124 
125  if ($a_user_id == "") {
126  $a_user_id = $ilUser->getId();
127  }
128 
129  if (isset(self::$lo_access[$a_ref_id])) {
130  $acc_rec["obj_id"] = self::$lo_access[$a_ref_id];
131  } else {
132  $q = "SELECT * FROM lo_access WHERE " .
133  "usr_id = " . $ilDB->quote($a_user_id, "integer") . " AND " .
134  "lm_id = " . $ilDB->quote($a_ref_id, "integer");
135 
136  $acc_set = $ilDB->query($q);
137  $acc_rec = $ilDB->fetchAssoc($acc_set);
138  }
139 
140  if ($acc_rec["obj_id"] > 0) {
141  $lm_id = ilObject::_lookupObjId($a_ref_id);
142  $mtree = new ilTree($lm_id);
143  $mtree->setTableNames('lm_tree', 'lm_data');
144  $mtree->setTreeTablePK("lm_id");
145  if ($mtree->isInTree($acc_rec["obj_id"])) {
146  return $acc_rec["obj_id"];
147  }
148  }
149 
150  return 0;
151  }
152 
156  public static function _checkGoto($a_target)
157  {
158  global $DIC;
159 
160  $ilAccess = $DIC->access();
161 
162  $t_arr = explode("_", $a_target);
163 
164  if (($t_arr[0] != "lm" && $t_arr[0] != "st"
165  && $t_arr[0] != "pg")
166  || ((int) $t_arr[1]) <= 0) {
167  return false;
168  }
169 
170  if ($t_arr[0] == "lm") {
171  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
172  $ilAccess->checkAccess("visible", "", $t_arr[1])) {
173  return true;
174  }
175  } else {
176  if ($t_arr[2] > 0) {
177  $ref_ids = array($t_arr[2]);
178  } else {
179  // determine learning object
180  $lm_id = ilLMObject::_lookupContObjID($t_arr[1]);
181  $ref_ids = ilObject::_getAllReferences($lm_id);
182  }
183  // check read permissions
184  foreach ($ref_ids as $ref_id) {
185  // Permission check
186  if ($ilAccess->checkAccess("read", "", $ref_id)) {
187  return true;
188  }
189  }
190  }
191  return false;
192  }
193 
199  public static function _preloadData($a_obj_ids, $a_ref_ids)
200  {
201  global $DIC;
202 
203  $ilDB = $DIC->database();
204  $ilUser = $DIC->user();
205 
206  $q = "SELECT obj_id, lm_id FROM lo_access WHERE " .
207  "usr_id = " . $ilDB->quote($ilUser->getId(), "integer") . " AND " .
208  $ilDB->in("lm_id", $a_ref_ids, false, "integer");
209  ;
210  $set = $ilDB->query($q);
211  foreach ($a_ref_ids as $r) {
212  self::$lo_access[$r] = 0;
213  }
214  while ($rec = $ilDB->fetchAssoc($set)) {
215  self::$lo_access[$rec["lm_id"]] = $rec["obj_id"];
216  }
217  }
218 }
static _preloadData($a_obj_ids, $a_ref_ids)
Preload data.
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
user()
Definition: user.php:4
static _getAllReferences($a_id)
get all reference ids of object
const IL_STATUS_MESSAGE
static _checkGoto($a_target)
check whether goto script will succeed
static lookupOfflineStatus($a_obj_id)
Lookup offline status using objectDataCache.
static _lookupObjId($a_id)
$ilUser
Definition: imgupload.php:18
Class ilObjContentObjectAccess.
global $ilDB
_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...
$DIC
Definition: xapitoken.php:46
static _getLastAccessedPage($a_ref_id, $a_user_id="")
get last accessed page