ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
6 include_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 $lo_access;
54 
67  public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
68  {
70  $lng = $this->lng;
72  $ilAccess = $this->access;
73 
74  if ($a_user_id == "") {
75  $a_user_id = $ilUser->getId();
76  }
77 
78  switch ($a_cmd) {
79  case "continue":
80 
81  // continue is now default and works all the time
82  // see ilLMPresentationGUI::resume()
83  /*
84  if ($ilUser->getId() == ANONYMOUS_USER_ID)
85  {
86  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("lm_no_continue_for_anonym"));
87  return false;
88  }
89  if (ilObjContentObjectAccess::_getLastAccessedPage($a_ref_id,$a_user_id) <= 0)
90  {
91  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("not_accessed_yet"));
92  return false;
93  }
94  */
95  break;
96 
97  // for permission query feature
98  case "info":
99  if (!ilObject::lookupOfflineStatus($a_obj_id)) {
100  $ilAccess->addInfoItem(IL_STATUS_MESSAGE, $lng->txt("online"));
101  }
102  break;
103 
104  }
105 
106  return true;
107  }
108 
109  //
110  // access relevant methods
111  //
112 
113 
120  public static function _getLastAccessedPage($a_ref_id, $a_user_id = "")
121  {
122  global $DIC;
123 
124  $ilDB = $DIC->database();
125  $ilUser = $DIC->user();
126 
127  if ($a_user_id == "") {
128  $a_user_id = $ilUser->getId();
129  }
130 
131  if (isset(self::$lo_access[$a_ref_id])) {
132  $acc_rec["obj_id"] = self::$lo_access[$a_ref_id];
133  } else {
134  $q = "SELECT * FROM lo_access WHERE " .
135  "usr_id = " . $ilDB->quote($a_user_id, "integer") . " AND " .
136  "lm_id = " . $ilDB->quote($a_ref_id, "integer");
137 
138  $acc_set = $ilDB->query($q);
139  $acc_rec = $ilDB->fetchAssoc($acc_set);
140  }
141 
142  if ($acc_rec["obj_id"] > 0) {
143  $lm_id = ilObject::_lookupObjId($a_ref_id);
144  $mtree = new ilTree($lm_id);
145  $mtree->setTableNames('lm_tree', 'lm_data');
146  $mtree->setTreeTablePK("lm_id");
147  if ($mtree->isInTree($acc_rec["obj_id"])) {
148  return $acc_rec["obj_id"];
149  }
150  }
151 
152  return 0;
153  }
154 
158  public static function _checkGoto($a_target)
159  {
160  global $DIC;
161 
162  $ilAccess = $DIC->access();
163 
164  $t_arr = explode("_", $a_target);
165 
166  if (($t_arr[0] != "lm" && $t_arr[0] != "st"
167  && $t_arr[0] != "pg")
168  || ((int) $t_arr[1]) <= 0) {
169  return false;
170  }
171 
172  if ($t_arr[0] == "lm") {
173  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
174  $ilAccess->checkAccess("visible", "", $t_arr[1])) {
175  return true;
176  }
177  } else {
178  if ($t_arr[2] > 0) {
179  $ref_ids = array($t_arr[2]);
180  } else {
181  // determine learning object
182  include_once("./Modules/LearningModule/classes/class.ilLMObject.php");
183  $lm_id = ilLMObject::_lookupContObjID($t_arr[1]);
184  $ref_ids = ilObject::_getAllReferences($lm_id);
185  }
186  // check read permissions
187  foreach ($ref_ids as $ref_id) {
188  // Permission check
189  if ($ilAccess->checkAccess("read", "", $ref_id)) {
190  return true;
191  }
192  }
193  }
194  return false;
195  }
196 
202  public static function _preloadData($a_obj_ids, $a_ref_ids)
203  {
204  global $DIC;
205 
206  $ilDB = $DIC->database();
207  $ilUser = $DIC->user();
208 
209  $q = "SELECT obj_id, lm_id FROM lo_access WHERE " .
210  "usr_id = " . $ilDB->quote($ilUser->getId(), "integer") . " AND " .
211  $ilDB->in("lm_id", $a_ref_ids, false, "integer");
212  ;
213  $set = $ilDB->query($q);
214  foreach ($a_ref_ids as $r) {
215  self::$lo_access[$r] = 0;
216  }
217  while ($rec = $ilDB->fetchAssoc($set)) {
218  self::$lo_access[$rec["lm_id"]] = $rec["obj_id"];
219  }
220  }
221 }
static _preloadData($a_obj_ids, $a_ref_ids)
Preload data.
global $DIC
Definition: saml.php:7
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
$r
Definition: example_031.php:79
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.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Class ilObjectAccess.
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...
static _getLastAccessedPage($a_ref_id, $a_user_id="")
get last accessed page