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