ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjUserTrackingGUI.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 
15 {
18 
19  public function __construct(
20  $a_data,
21  int $a_id,
22  bool $a_call_by_reference,
23  bool $prepare_output
24  ) {
25  global $DIC;
26 
27  $this->error = $DIC['ilErr'];
28  $this->objectDefinition = $DIC['objDefinition'];
29 
30  $this->type = "trac";
31  parent::__construct($a_data, $a_id, $a_call_by_reference, false);
32  $this->lng->loadLanguageModule('trac');
33  }
34 
35  public function executeCommand(): void
36  {
37  $next_class = $this->ctrl->getNextClass();
38  $this->ctrl->setReturn($this, "show");
39  $this->prepareOutput();
40 
41  switch ($next_class) {
42  case 'ilpermissiongui':
43  $perm_gui = new ilPermissionGUI($this);
44  $this->ctrl->forwardCommand($perm_gui);
45  break;
46 
47  case 'illpobjectstatisticsgui':
48  $this->tabs_gui->activateTab('statistics');
49  $os_gui = new ilLPObjectStatisticsGUI(
51  );
52  $this->ctrl->forwardCommand($os_gui);
53  break;
54 
55  case 'ilsessionstatisticsgui':
56  $this->tabs_gui->setTabActive('session_statistics');
57  $sess_gui = new ilSessionStatisticsGUI();
58  $this->ctrl->forwardCommand($sess_gui);
59  break;
60 
61  default:
62  $cmd = $this->ctrl->getCmd();
63  if ($cmd == "view" || $cmd == "") {
64  $cmd = "settings";
65  }
66  $cmd .= "Object";
67  $this->$cmd();
68  break;
69  }
70  }
71 
72  public function getAdminTabs(): void
73  {
74  $this->getTabs();
75  }
76 
77  protected function getTabs(): void
78  {
79  $this->ctrl->setParameter($this, "ref_id", $this->ref_id);
80 
81  $this->tabs_gui->addTarget(
82  "settings",
83  $this->ctrl->getLinkTarget($this, "settings"),
84  "settings",
85  get_class($this)
86  );
87 
88  if ($this->rbac_system->checkAccess("visible,read", $this->ref_id)) {
90  $this->tabs_gui->addTarget(
91  "statistics",
92  $this->ctrl->getLinkTargetByClass(
93  "illpobjectstatisticsgui",
94  "access"
95  ),
96  "",
97  "illpobjectstatisticsgui"
98  );
99  }
100 
101  // session statistics
103  $this->tabs_gui->addTarget(
104  "session_statistics",
105  $this->ctrl->getLinkTargetByClass(
106  "ilsessionstatisticsgui",
107  ""
108  ),
109  "",
110  "ilsessionstatisticsgui"
111  );
112  }
113  }
114 
115  if ($this->checkPermissionBool("edit_permission")) {
116  $this->tabs_gui->addTarget(
117  "perm_settings",
118  $this->ctrl->getLinkTargetByClass(
119  array(get_class($this), 'ilpermissiongui'),
120  "perm"
121  ),
122  array("perm", "info", "owner"),
123  'ilpermissiongui'
124  );
125  }
126  }
127 
128  public function settingsObject(?ilPropertyFormGUI $a_form = null): void
129  {
130  if (!$this->rbac_system->checkAccess(
131  "visible,read",
132  $this->object->getRefId()
133  )) {
134  $this->error->raiseError(
135  $this->lng->txt("no_permission"),
136  $this->error->WARNING
137  );
138  }
139 
140  $this->tabs_gui->addSubTab(
141  'lp_settings',
142  $this->lng->txt('settings'),
143  $this->ctrl->getLinkTarget($this, 'settings')
144  );
145 
147  $this->tabs_gui->addSubTab(
148  'lpdef',
149  $this->lng->txt('trac_defaults'),
150  $this->ctrl->getLinkTarget($this, 'editLPDefaults')
151  );
152  }
153 
154  $this->tabs_gui->setTabActive('settings');
155  $this->tabs_gui->setSubTabActive('lp_settings');
156 
157  if (!$a_form) {
158  $a_form = $this->initSettingsForm();
159  }
160 
161  $this->tpl->setContent($a_form->getHTML());
162  }
163 
164  protected function initSettingsForm(): ilPropertyFormGUI
165  {
166  $form = new ilPropertyFormGUI();
167  $form->setFormAction($this->ctrl->getFormAction($this));
168  $form->setTitle($this->lng->txt('tracking_settings'));
169 
170  $activate = new ilCheckboxGroupInputGUI(
171  $this->lng->txt('activate_tracking')
172  );
173  $form->addItem($activate);
174 
175  // learning progress
176  $lp = new ilCheckboxInputGUI(
177  $this->lng->txt('trac_learning_progress'),
178  'learning_progress_tracking'
179  );
180  if ($this->object->enabledLearningProgress()) {
181  $lp->setChecked(true);
182  }
183  $activate->addSubItem($lp);
184 
185  // lp settings
186 
187  $learner = new ilCheckboxInputGUI(
188  $this->lng->txt('trac_lp_learner_access'),
189  'lp_learner'
190  );
191  $learner->setInfo($this->lng->txt('trac_lp_learner_access_info'));
192  $learner->setChecked($this->object->hasLearningProgressLearner());
193  $lp->addSubItem($learner);
194 
195  // extended data
196 
197  $extdata = new ilCheckboxGroupInputGUI(
198  $this->lng->txt('trac_learning_progress_settings_info'),
199  'lp_extdata'
200  );
201  $extdata->addOption(
202  new ilCheckboxOption(
203  $this->lng->txt('trac_first_and_last_access'),
204  'lp_access'
205  )
206  );
207  $extdata->addOption(
208  new ilCheckboxOption($this->lng->txt('trac_read_count'), 'lp_count')
209  );
210  $extdata->addOption(
211  new ilCheckboxOption(
212  $this->lng->txt('trac_spent_seconds'),
213  'lp_spent'
214  )
215  );
216  $lp->addSubItem($extdata);
217 
218  $ext_value = array();
219  if ($this->object->hasExtendedData(
221  )) {
222  $ext_value[] = 'lp_access';
223  }
224  if ($this->object->hasExtendedData(
226  )) {
227  $ext_value[] = 'lp_count';
228  }
229  if ($this->object->hasExtendedData(
231  )) {
232  $ext_value[] = 'lp_spent';
233  }
234  $extdata->setValue($ext_value);
235 
236  $listgui = new ilCheckboxInputGUI(
237  $this->lng->txt('trac_lp_list_gui'),
238  'lp_list'
239  );
240  $listgui->setInfo($this->lng->txt('trac_lp_list_gui_info'));
241  $listgui->setChecked($this->object->hasLearningProgressListGUI());
242  $lp->addSubItem($listgui);
243 
244  // object statistics
245  $objstat = new ilCheckboxInputGUI(
246  $this->lng->txt('trac_object_statistics'),
247  'object_statistics'
248  );
249  if ($this->object->enabledObjectStatistics()) {
250  $objstat->setChecked(true);
251  }
252  $activate->addSubItem($objstat);
253 
254  // session statistics
255  $sessstat = new ilCheckboxInputGUI(
256  $this->lng->txt('session_statistics'),
257  'session_statistics'
258  );
259  if ($this->object->enabledSessionStatistics()) {
260  $sessstat->setChecked(true);
261  }
262  $activate->addSubItem($sessstat);
263 
264  // Anonymized
266  $this->lng->txt('trac_anonymized'),
267  'user_related'
268  );
269  $user->setInfo($this->lng->txt('trac_anonymized_info'));
270  $user->setChecked(!$this->object->enabledUserRelatedData());
271  $form->addItem($user);
272 
273  // Max time gap
274  $valid = new ilNumberInputGUI(
275  $this->lng->txt('trac_valid_request'),
276  'valid_request'
277  );
278  $valid->setMaxLength(4);
279  $valid->setSize(4);
280  $valid->setSuffix($this->lng->txt('seconds'));
281  $valid->setInfo($this->lng->txt('info_valid_request'));
282  $valid->setValue((string) $this->object->getValidTimeSpan());
283  $valid->setMinValue(1);
284  $valid->setMaxValue(9999);
285  $valid->setRequired(true);
286  $form->addItem($valid);
287 
290  $form,
291  $this
292  );
293 
294  // #12259
295  if ($this->checkPermissionBool("write")) {
296  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
297  } else {
298  $lp->setDisabled(true);
299  $learner->setDisabled(true);
300  $extdata->setDisabled(true);
301  $listgui->setDisabled(true);
302  $objstat->setDisabled(true);
303  $user->setDisabled(true);
304  $valid->setDisabled(true);
305  }
306 
307  return $form;
308  }
309 
310  public function saveSettingsObject(): void
311  {
312  $this->checkPermission('write');
313 
314  $form = $this->initSettingsForm();
315  if ($form->checkInput()) {
316  $lp_active = $form->getInput('learning_progress_tracking');
317 
318  $this->object->enableLearningProgress((bool) $lp_active);
319 
320  if ($lp_active) {
321  $ext_data = (array) $form->getInput("lp_extdata");
322  $code = 0;
323  if (in_array('lp_access', $ext_data)) {
325  }
326  if (in_array('lp_count', $ext_data)) {
328  }
329  if (in_array('lp_spent', $ext_data)) {
331  }
332  $this->object->setExtendedData($code);
333  }
334 
335  $this->object->enableChangeEventTracking(
336  (bool) $form->getInput('change_event_tracking')
337  );
338  $this->object->enableObjectStatistics(
339  (bool) $form->getInput('object_statistics')
340  );
341  $this->object->enableUserRelatedData(
342  !$form->getInput('user_related')
343  );
344  $this->object->setValidTimeSpan(
345  (int) $form->getInput('valid_request')
346  );
347  // $this->object->setLearningProgressDesktop($form->getInput('lp_desktop'));
348  $this->object->setLearningProgressLearner(
349  (bool) $form->getInput('lp_learner')
350  );
351  $this->object->enableSessionStatistics(
352  (bool) $form->getInput('session_statistics')
353  );
354  $this->object->setLearningProgressListGUI(
355  (bool) $form->getInput('lp_list')
356  );
357  $this->object->updateSettings();
358 
359  $this->tpl->setOnScreenMessage(
360  'success',
361  $this->lng->txt("msg_obj_modified"),
362  true
363  );
364  $this->ctrl->redirect($this, "settings");
365  }
366  $form->setValuesByPost();
367  $this->settingsObject($form);
368  }
369 
370  protected function editLPDefaultsObject(
371  ?ilPropertyFormGUI $a_form = null
372  ): void {
373  $this->checkPermission('read');
374 
375  $this->tabs_gui->addSubTab(
376  'lp_settings',
377  $this->lng->txt('settings'),
378  $this->ctrl->getLinkTarget($this, 'settings')
379  );
380 
381  $this->tabs_gui->addSubTab(
382  'lpdef',
383  $this->lng->txt('trac_defaults'),
384  $this->ctrl->getLinkTarget($this, 'editLPDefaults')
385  );
386 
387  $this->tabs_gui->setTabActive('settings');
388  $this->tabs_gui->setSubTabActive('lpdef');
389 
390  if (!$a_form) {
391  $a_form = $this->initLPDefaultsForm();
392  }
393 
394  $this->tpl->setContent($a_form->getHTML());
395  }
396 
397  protected function initLPDefaultsForm(): ilPropertyFormGUI
398  {
399  $form = new ilPropertyFormGUI();
400  $form->setFormAction($this->ctrl->getFormAction($this));
401  $form->setTitle($this->lng->txt('trac_defaults'));
402  $form->setDescription($this->lng->txt('trac_defaults_info'));
403 
404  $types = array();
405  foreach ($this->objectDefinition->getAllRepositoryTypes() as $type) {
407  $types[$type] = array(
408  "type" => $type,
409  "caption" => $this->lng->txt("obj_" . $type)
410  );
411  }
412  }
413  $types = ilArrayUtil::sortArray($types, "caption", "asc");
414  foreach ($types as $item) {
415  $class = ilObjectLP::getTypeClass($item["type"]);
416  $modes = $class::getDefaultModes(
418  );
419  if (sizeof($modes) > 1) {
420  $def_type = new ilSelectInputGUI(
421  $item["caption"],
422  "def_" . $item["type"]
423  );
424  $form->addItem($def_type);
425 
426  $def_type->setRequired(true);
427  $def_type->setValue(ilObjectLP::getTypeDefault($item["type"]));
428 
429  $options = array();
430  foreach ($modes as $mode) {
431  $caption = ($mode == ilLPObjSettings::LP_MODE_DEACTIVATED)
432  ? $this->lng->txt("trac_defaults_inactive")
434  $options[$mode] = $caption;
435  }
436  $def_type->setOptions($options);
437  }
438  }
439 
440  if ($this->checkPermissionBool("write")) {
441  $form->addCommandButton('saveLPDefaults', $this->lng->txt('save'));
442  } else {
443  foreach ($types as $item) {
444  $form->getItemByPostVar("def_" . $item["type"])->setDisabled(
445  true
446  );
447  }
448  }
449  return $form;
450  }
451 
452  protected function saveLPDefaultsObject(): void
453  {
454  $this->checkPermission('write');
455 
456  $form = $this->initLPDefaultsForm();
457  if ($form->checkInput()) {
458  $res = array();
459  foreach ($this->objectDefinition->getAllRepositoryTypes(
460  ) as $type) {
462  $mode = $form->getInput("def_" . $type);
463  $res[$type] = $mode
465  }
466  }
467 
469 
470  $this->tpl->setOnScreenMessage(
471  'success',
472  $this->lng->txt("msg_obj_modified"),
473  true
474  );
475  $this->ctrl->redirect($this, "editLPDefaults");
476  }
477 
478  $form->setValuesByPost();
479  $this->editLPDefaultsObject($form);
480  }
481 
482  public function addToExternalSettingsForm(int $a_form_id): array
483  {
484  switch ($a_form_id) {
486  $fields = array();
487  return array('obj_trac' => array('editLPDefaults', $fields));
488  }
489  return [];
490  }
491 }
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
static isSupportedObjectType(string $type)
prepareOutput(bool $show_sub_objects=true)
$valid
static getTypeDefault(string $type)
static saveTypeDefaults(array $data)
settingsObject(?ilPropertyFormGUI $a_form=null)
ilObjectDefinition $objectDefinition
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: shib_login.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
editLPDefaultsObject(?ilPropertyFormGUI $a_form=null)
__construct(Container $dic, ilPlugin $plugin)
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
static getTypeClass(string $type)
__construct( $a_data, int $a_id, bool $a_call_by_reference, bool $prepare_output)
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _mode2Text(int $a_mode)