ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilObjUserTracking.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=0);
4 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
5 
14 {
15  private int $valid_time = 0;
16  protected int $extended_data = 0;
17  protected bool $learning_progress = false;
18  protected bool $tracking_user_related = false;
19  protected bool $object_statistics_enabled = false;
20  protected bool $lp_learner = false;
21  protected bool $session_statistics_enabled = false;
22  protected bool $lp_list_gui = false;
23 
27  private bool $is_change_event_tracking_enabled = false;
28 
29  public const EXTENDED_DATA_LAST_ACCESS = 1;
30  public const EXTENDED_DATA_READ_COUNT = 2;
31  public const EXTENDED_DATA_SPENT_SECONDS = 4;
32 
33  public const DEFAULT_TIME_SPAN = 300;
34 
35  protected ilSetting $settings;
36 
37  public function __construct(int $a_id = 0, bool $a_call_by_reference = true)
38  {
39  global $DIC;
40 
41  $this->settings = $DIC->settings();
42 
43  $this->type = "trac";
44  parent::__construct($a_id, $a_call_by_reference);
45  $this->__readSettings();
46  }
47 
48  public function enableLearningProgress(bool $a_enable): void
49  {
50  $this->learning_progress = $a_enable;
51  }
52 
53  public function enabledLearningProgress(): bool
54  {
56  }
57 
58  public static function _enabledLearningProgress(): bool
59  {
60  global $DIC;
61 
62  $ilSetting = $DIC->settings();
63 
64  return (bool) $ilSetting->get("enable_tracking", '0');
65  }
66 
67  public function enableUserRelatedData(bool $a_enable): void
68  {
69  $this->tracking_user_related = $a_enable;
70  }
71 
72  public function enabledUserRelatedData(): bool
73  {
75  }
76 
77  public static function _enabledUserRelatedData()
78  {
79  global $DIC;
80 
81  $ilSetting = $DIC->settings();
82  return (bool) $ilSetting->get('save_user_related_data', '0');
83  }
84 
85  public static function _enabledObjectStatistics(): bool
86  {
87  global $DIC;
88 
89  $ilSetting = $DIC->settings();
90  return (bool) $ilSetting->get('object_statistics', '0');
91  }
92 
93  public function enableObjectStatistics(bool $newValue): void
94  {
95  $this->object_statistics_enabled = $newValue;
96  }
97 
98  public function enabledObjectStatistics(): bool
99  {
101  }
102 
103  public function enableSessionStatistics(bool $newValue): void
104  {
105  $this->session_statistics_enabled = $newValue;
106  }
107 
108  public function enabledSessionStatistics(): bool
109  {
111  }
112 
113  public static function _enabledSessionStatistics(): bool
114  {
115  global $DIC;
116 
117  $ilSetting = $DIC->settings();
118  return (bool) $ilSetting->get('session_statistics', '1');
119  }
120 
121  public function setValidTimeSpan(int $a_time_span): void
122  {
123  $this->valid_time = $a_time_span;
124  }
125 
126  public function getValidTimeSpan(): int
127  {
128  return $this->valid_time;
129  }
130 
131  public static function _getValidTimeSpan(): int
132  {
133  global $DIC;
134 
135  $ilSetting = $DIC->settings();
136  return (int) $ilSetting->get(
137  "tracking_time_span",
138  (string) self::DEFAULT_TIME_SPAN
139  );
140  }
141 
142  public function enableChangeEventTracking(bool $newValue): void
143  {
144  $this->is_change_event_tracking_enabled = $newValue;
145  }
146 
147  public function enabledChangeEventTracking(): bool
148  {
150  }
151 
152  // END ChangeEvent
153 
154  public function setExtendedData(int $a_value): void
155  {
156  $this->extended_data = $a_value;
157  }
158 
159  public function hasExtendedData(int $a_code): bool
160  {
161  return (bool) ($this->extended_data & $a_code);
162  }
163 
164  public function updateSettings()
165  {
166  $this->settings->set(
167  "enable_tracking",
168  (string) $this->enabledLearningProgress()
169  );
170  $this->settings->set(
171  "save_user_related_data",
172  (string) $this->enabledUserRelatedData()
173  );
174  $this->settings->set(
175  "tracking_time_span",
176  (string) $this->getValidTimeSpan()
177  );
178  $this->settings->set("lp_extended_data", (string) $this->extended_data);
179  $this->settings->set(
180  "object_statistics",
181  (string) $this->enabledObjectStatistics()
182  );
183  // $this->settings->set("lp_desktop", (int)$this->hasLearningProgressDesktop());
184  $this->settings->set(
185  "lp_learner",
186  (string) $this->hasLearningProgressLearner()
187  );
188  $this->settings->set(
189  "session_statistics",
190  (string) $this->enabledSessionStatistics()
191  );
192  $this->settings->set(
193  "lp_list_gui",
194  (string) $this->hasLearningProgressListGUI()
195  );
196  }
197 
198  protected function __readSettings(): void
199  {
200  $this->enableLearningProgress(
201  (bool) $this->settings->get("enable_tracking", '0')
202  );
203  $this->enableUserRelatedData(
204  (bool) $this->settings->get("save_user_related_data", '0')
205  );
206  $this->enableObjectStatistics(
207  (bool) $this->settings->get("object_statistics", '0')
208  );
209  $this->setValidTimeSpan(
210  (int) $this->settings->get(
211  "tracking_time_span",
212  (string) self::DEFAULT_TIME_SPAN
213  )
214  );
216  (bool) $this->settings->get("lp_learner", '1')
217  );
219  (bool) $this->settings->get("session_statistics", '1')
220  );
222  (bool) $this->settings->get("lp_list_gui", '0')
223  );
224 
225  // BEGIN ChangeEvent
227  // END ChangeEvent
228 
229  $this->setExtendedData(
230  (int) $this->settings->get("lp_extended_data", '0')
231  );
232  }
233 
234  public static function _deleteUser(int $a_usr_id): void
235  {
236  global $DIC;
237 
238  $ilDB = $DIC['ilDB'];
239  $query = sprintf(
240  'DELETE FROM read_event WHERE usr_id = %s ',
241  $ilDB->quote($a_usr_id, 'integer')
242  );
243  $aff = $ilDB->manipulate($query);
244 
245  $query = sprintf(
246  'DELETE FROM write_event WHERE usr_id = %s ',
247  $ilDB->quote($a_usr_id, 'integer')
248  );
249  $aff = $ilDB->manipulate($query);
250 
251  $query = "DELETE FROM ut_lp_marks WHERE usr_id = " . $ilDB->quote(
252  $a_usr_id,
253  'integer'
254  ) . " ";
255  $res = $ilDB->manipulate($query);
256 
257  $ilDB->manipulate(
258  "DELETE FROM ut_online WHERE usr_id = " .
259  $ilDB->quote($a_usr_id, "integer")
260  );
261  }
262 
263  public static function _hasLearningProgressOtherUsers(): bool
264  {
265  global $DIC;
266 
267  $rbacsystem = $DIC['rbacsystem'];
268  $obj_ids = array_keys(ilObject::_getObjectsByType("trac"));
269  $obj_id = array_pop($obj_ids);
270  $ref_ids = ilObject::_getAllReferences($obj_id);
271  $ref_id = array_pop($ref_ids);
272  return $rbacsystem->checkAccess("lp_other_users", $ref_id);
273  }
274 
275  public function setLearningProgressLearner(bool $a_value): void
276  {
277  $this->lp_learner = $a_value;
278  }
279 
280  public function hasLearningProgressLearner(): bool
281  {
282  return $this->lp_learner;
283  }
284 
285  public static function _hasLearningProgressLearner(): bool
286  {
287  global $DIC;
288 
289  $ilSetting = $DIC->settings();
290  return (bool) $ilSetting->get("lp_learner", '1');
291  }
292 
293  public function setLearningProgressListGUI(bool $a_value): void
294  {
295  $this->lp_list_gui = $a_value;
296  }
297 
298  public function hasLearningProgressListGUI(): bool
299  {
300  return $this->lp_list_gui;
301  }
302 
303  public static function _hasLearningProgressListGUI(): bool
304  {
305  global $DIC;
306 
307  $ilSetting = $DIC->settings();
308  return (bool) $ilSetting->get("lp_list_gui", '0');
309  }
310 } // END class.ilObjUserTracking
enableSessionStatistics(bool $newValue)
$res
Definition: ltiservices.php:69
enableChangeEventTracking(bool $newValue)
static _deleteUser(int $a_usr_id)
static _getAllReferences(int $id)
get all reference ids for object ID
setLearningProgressLearner(bool $a_value)
enableObjectStatistics(bool $newValue)
__construct(int $a_id=0, bool $a_call_by_reference=true)
static _getObjectsByType(string $obj_type="", int $owner=null)
setValidTimeSpan(int $a_time_span)
bool $is_change_event_tracking_enabled
This variable holds the enabled state of the change event tracking.
global $DIC
Definition: feed.php:28
$query
enableLearningProgress(bool $a_enable)
global $ilSetting
Definition: privfeed.php:17
static _isActive()
Returns true, if change event tracking is active.
__construct(Container $dic, ilPlugin $plugin)
setLearningProgressListGUI(bool $a_value)
enableUserRelatedData(bool $a_enable)