ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjContentObjectAccess.php
Go to the documentation of this file.
1 <?php
2 
23 {
24  protected ilObjUser $user;
25  protected ilLanguage $lng;
28 
29  public function __construct()
30  {
31  global $DIC;
32 
33  $this->user = $DIC->user();
34  $this->lng = $DIC->language();
35  $this->rbacsystem = $DIC->rbac()->system();
36  $this->access = $DIC->access();
37  }
38 
39  public static array $lo_access;
40 
41  public function _checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id = null): bool
42  {
44  $lng = $this->lng;
45  $ilAccess = $this->access;
46 
47  switch ($cmd) {
48  case "continue":
49 
50  // continue is now default and works all the time
51  // see ilLMPresentationGUI::resume()
52  /*
53  if ($ilUser->getId() == ANONYMOUS_USER_ID)
54  {
55  $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("lm_no_continue_for_anonym"));
56  return false;
57  }
58  if (ilObjContentObjectAccess::_getLastAccessedPage($ref_id,$user_id) <= 0)
59  {
60  $ilAccess->addInfoItem(ilAccessInfo::IL_NO_OBJECT_ACCESS, $lng->txt("not_accessed_yet"));
61  return false;
62  }
63  */
64  break;
65 
66  // for permission query feature
67  case "info":
68  if (!ilObject::lookupOfflineStatus($obj_id)) {
69  $ilAccess->addInfoItem(ilAccessInfo::IL_STATUS_MESSAGE, $lng->txt("online"));
70  }
71  break;
72 
73  }
74 
75  return true;
76  }
77 
78  //
79  // access relevant methods
80  //
81 
82  public static function _getLastAccessedPage(
83  int $a_ref_id,
84  int $a_user_id = 0
85  ): int {
86  global $DIC;
87 
88  $ilDB = $DIC->database();
89  $ilUser = $DIC->user();
90 
91  if ($a_user_id == 0) {
92  $a_user_id = $ilUser->getId();
93  }
94 
95  if (isset(self::$lo_access[$a_ref_id])) {
96  $acc_rec["obj_id"] = self::$lo_access[$a_ref_id];
97  } else {
98  $q = "SELECT * FROM lo_access WHERE " .
99  "usr_id = " . $ilDB->quote($a_user_id, "integer") . " AND " .
100  "lm_id = " . $ilDB->quote($a_ref_id, "integer");
101 
102  $acc_set = $ilDB->query($q);
103  $acc_rec = $ilDB->fetchAssoc($acc_set);
104  }
105 
106  if (($acc_rec["obj_id"] ?? 0) > 0) {
107  $lm_id = ilObject::_lookupObjId($a_ref_id);
108  $mtree = new ilTree($lm_id);
109  $mtree->setTableNames('lm_tree', 'lm_data');
110  $mtree->setTreeTablePK("lm_id");
111  if ($mtree->isInTree($acc_rec["obj_id"])) {
112  return $acc_rec["obj_id"];
113  }
114  }
115 
116  return 0;
117  }
118 
119  public static function _checkGoto(string $target): bool
120  {
121  global $DIC;
122 
123  $ilAccess = $DIC->access();
124 
125  $t_arr = explode("_", $target);
126 
127  if (($t_arr[0] != "lm" && $t_arr[0] != "st"
128  && $t_arr[0] != "pg")
129  || ((int) $t_arr[1]) <= 0) {
130  return false;
131  }
132 
133  if ($t_arr[0] == "lm") {
134  if ($ilAccess->checkAccess("read", "", $t_arr[1]) ||
135  $ilAccess->checkAccess("visible", "", $t_arr[1])) {
136  return true;
137  }
138  } else {
139  if (($t_arr[2] ?? 0) > 0) {
140  $ref_ids = array($t_arr[2]);
141  } else {
142  // determine learning object
143  $lm_id = ilLMObject::_lookupContObjID($t_arr[1]);
144  $ref_ids = ilObject::_getAllReferences($lm_id);
145  }
146  // check read permissions
147  foreach ($ref_ids as $ref_id) {
148  // Permission check
149  if ($ilAccess->checkAccess("read", "", $ref_id)) {
150  return true;
151  }
152  }
153  }
154  return false;
155  }
156 
157  public static function _preloadData(array $obj_ids, array $ref_ids): void
158  {
159  global $DIC;
160 
161  $reading_time_manager = new \ILIAS\LearningModule\ReadingTime\ReadingTimeManager();
162  $reading_time_manager->loadData($obj_ids);
163 
164  $ilDB = $DIC->database();
165  $ilUser = $DIC->user();
166 
167  $q = "SELECT obj_id, lm_id FROM lo_access WHERE " .
168  "usr_id = " . $ilDB->quote($ilUser->getId(), "integer") . " AND " .
169  $ilDB->in("lm_id", $ref_ids, false, "integer");
170  $set = $ilDB->query($q);
171  foreach ($ref_ids as $r) {
172  self::$lo_access[$r] = 0;
173  }
174  while ($rec = $ilDB->fetchAssoc($set)) {
175  self::$lo_access[$rec["lm_id"]] = $rec["obj_id"];
176  }
177  }
178 
179  public static function isInfoEnabled(int $obj_id): bool
180  {
182  $obj_id,
184  true
185  );
186  }
187 }
addInfoItem(string $a_type, string $a_text, string $a_data="")
add an info item to current info object
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
_checkAccess(string $cmd, string $permission, int $ref_id, int $obj_id, ?int $user_id=null)
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupContainerSetting(int $a_id, string $a_keyword, string $a_default_value=null)
static _lookupObjId(int $ref_id)
static lookupOfflineStatus(int $obj_id)
Lookup offline status using objectDataCache.
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
static _getLastAccessedPage(int $a_ref_id, int $a_user_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ilUser
Definition: imgupload.php:34
static _lookupContObjID(int $a_id)
get learning module id for lm object
static _preloadData(array $obj_ids, array $ref_ids)