ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilLPListOfSettingsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=0);
20 
28 {
30  protected ilObjectLP $obj_lp;
31 
32  public function __construct(int $a_mode, int $a_ref_id)
33  {
34  parent::__construct($a_mode, $a_ref_id);
35 
36  $this->obj_settings = new ilLPObjSettings($this->getObjId());
37  $this->obj_lp = ilObjectLP::getInstance($this->getObjId());
38  }
39 
43  public function executeCommand(): void
44  {
45  switch ($this->ctrl->getNextClass()) {
46  default:
47  $cmd = $this->__getDefaultCommand();
48  $this->$cmd();
49  }
50  }
51 
52  protected function initItemIdsFromPost(): array
53  {
54  if ($this->http->wrapper()->post()->has('item_ids')) {
55  return $this->http->wrapper()->post()->retrieve(
56  'item_ids',
57  $this->refinery->kindlyTo()->listOf(
58  $this->refinery->kindlyTo()->int()
59  )
60  );
61  }
62  return [];
63  }
64 
68  protected function show(): void
69  {
70  $this->help->setSubScreenId("trac_settings");
71  $info = $this->obj_lp->getSettingsInfo();
72  if ($info) {
73  $this->tpl->setOnScreenMessage('info', $info);
74  }
75 
76  $form = $this->initFormSettings();
77  $this->tpl->setContent(
78  $this->handleLPUsageInfo() .
79  $form->getHTML() .
80  $this->getTableByMode()
81  );
82  }
83 
84  protected function initFormSettings(): ilPropertyFormGUI
85  {
86  $form = new ilPropertyFormGUI();
87  $form->setTitle($this->lng->txt('tracking_settings'));
88  $form->setFormAction($this->ctrl->getFormAction($this));
89 
90  // Mode
91  $mod = new ilRadioGroupInputGUI($this->lng->txt('trac_mode'), 'modus');
92  $mod->setRequired(true);
93  $mod->setValue((string) $this->obj_lp->getCurrentMode());
94  $form->addItem($mod);
95 
96  if ($this->obj_lp->hasIndividualModeOptions()) {
97  $this->obj_lp->initInvidualModeOptions($mod);
98  } else {
99  foreach ($this->obj_lp->getValidModes() as $mode_key) {
100  $opt = new ilRadioOption(
101  $this->obj_lp->getModeText($mode_key),
102  (string) $mode_key,
103  $this->obj_lp->getModeInfoText($mode_key)
104  );
105  $opt->setValue((string) $mode_key);
106  $mod->addOption($opt);
107 
108  // :TODO: Subitem for visits ?!
109  if ($mode_key == ilLPObjSettings::LP_MODE_VISITS) {
110  $vis = new ilNumberInputGUI(
111  $this->lng->txt('trac_visits'),
112  'visits'
113  );
114  $vis->setSize(3);
115  $vis->setMaxLength(4);
116  $vis->setInfo(
117  sprintf(
118  $this->lng->txt('trac_visits_info'),
120  )
121  );
122  $vis->setRequired(true);
123  $vis->setValue((string) $this->obj_settings->getVisits());
124  $opt->addSubItem($vis);
125  }
126  $this->obj_lp->appendModeConfiguration((int) $mode_key, $opt);
127  }
128  }
129  $form->addCommandButton('saveSettings', $this->lng->txt('save'));
130  return $form;
131  }
132 
133  protected function saveSettings(): void
134  {
135  $form = $this->initFormSettings();
136  if ($form->checkInput()) {
137  // anything changed?
138 
139  // mode
140  if ($this->obj_lp->shouldFetchIndividualModeFromFormSubmission()) {
141  $new_mode = $this->obj_lp->fetchIndividualModeFromFormSubmission(
142  $form
143  );
144  } else {
145  $new_mode = (int) $form->getInput('modus');
146  }
147  $old_mode = $this->obj_lp->getCurrentMode();
148  $mode_changed = ($old_mode != $new_mode);
149 
150  // visits
151  $new_visits = null;
152  $visits_changed = null;
153  if ($new_mode == ilLPObjSettings::LP_MODE_VISITS) {
154  $new_visits = (int) $form->getInput('visits');
155  $old_visits = $this->obj_settings->getVisits();
156  $visits_changed = ($old_visits != $new_visits);
157  }
158 
159  $this->obj_lp->saveModeConfiguration($form, $mode_changed);
160 
161  if ($mode_changed) {
162  // delete existing collection
163  $collection = $this->obj_lp->getCollectionInstance();
164  if ($collection) {
165  $collection->delete();
166  }
167  }
168 
169 
170  // has to be done before LP refresh!
171  $this->obj_lp->resetCaches();
172 
173  $this->obj_settings->setMode($new_mode);
174  $this->obj_settings->setVisits((int) $new_visits);
175  $this->obj_settings->update(true);
176 
177  if ($mode_changed &&
178  $this->obj_lp->getCollectionInstance() &&
179  $new_mode != ilLPObjSettings::LP_MODE_MANUAL_BY_TUTOR) { // #14819
180  $this->tpl->setOnScreenMessage(
181  'info',
182  $this->lng->txt(
183  'trac_edit_collection'
184  ),
185  true
186  );
187  }
188  $this->tpl->setOnScreenMessage(
189  'success',
190  $this->lng->txt(
191  'trac_settings_saved'
192  ),
193  true
194  );
195  $this->ctrl->redirect($this, 'show');
196  }
197 
198  $form->setValuesByPost();
199 
200  $this->tpl->setContent(
201  $this->handleLPUsageInfo() .
202  $form->getHTML() .
203  $this->getTableByMode()
204  );
205  }
206 
210  protected function getTableByMode(): string
211  {
212  $collection = $this->obj_lp->getCollectionInstance();
213  if ($collection && $collection->hasSelectableItems()) {
214  $table = new ilLPCollectionSettingsTableGUI(
215  $this,
216  'show',
217  $this->getRefId(),
218  $this->obj_lp->getCurrentMode()
219  );
220  $table->parse($collection);
221  return $table->getHTML();
222  }
223  return '';
224  }
225 
226  protected function assign(): void
227  {
228  if (!$this->initItemIdsFromPost()) {
229  $this->tpl->setOnScreenMessage(
230  'failure',
231  $this->lng->txt('select_one'),
232  true
233  );
234  $this->ctrl->redirect($this, 'show');
235  }
236  if (count($this->initItemIdsFromPost())) {
237  $collection = $this->obj_lp->getCollectionInstance();
238  if ($collection && $collection->hasSelectableItems()) {
239  $collection->activateEntries($this->initItemIdsFromPost());
240  }
241  // refresh learning progress
242  $this->obj_lp->resetCaches();
244  }
245  $this->tpl->setOnScreenMessage(
246  'success',
247  $this->lng->txt('trac_settings_saved'),
248  true
249  );
250  $this->ctrl->redirect($this, 'show');
251  }
252 
253  protected function deassign(): void
254  {
255  if (!$this->initItemIdsFromPost()) {
256  $this->tpl->setOnScreenMessage(
257  'failure',
258  $this->lng->txt('select_one'),
259  true
260  );
261  $this->ctrl->redirect($this, 'show');
262  return;
263  }
264  if (count($this->initItemIdsFromPost())) {
265  $collection = $this->obj_lp->getCollectionInstance();
266  if ($collection && $collection->hasSelectableItems()) {
267  $collection->deactivateEntries($this->initItemIdsFromPost());
268  }
269 
270  // #15045 - has to be done before LP refresh!
271  $this->obj_lp->resetCaches();
272 
273  // refresh learning progress
275  }
276  $this->tpl->setOnScreenMessage(
277  'success',
278  $this->lng->txt('trac_settings_saved'),
279  true
280  );
281  $this->ctrl->redirect($this, 'show');
282  }
283 
287  protected function groupMaterials(): void
288  {
289  if (!count((array) $this->initItemIdsFromPost())) {
290  $this->tpl->setOnScreenMessage(
291  'failure',
292  $this->lng->txt('select_one'),
293  true
294  );
295  $this->ctrl->redirect($this, 'show');
296  }
297 
298  $collection = $this->obj_lp->getCollectionInstance();
299  if ($collection && $collection->hasSelectableItems()) {
300  // Assign new grouping id
301  $collection->createNewGrouping($this->initItemIdsFromPost());
302 
303  $this->obj_lp->resetCaches();
304 
305  // refresh learning progress
307  }
308 
309  $this->tpl->setOnScreenMessage(
310  'success',
311  $this->lng->txt('trac_settings_saved'),
312  true
313  );
314  $this->ctrl->redirect($this, 'show');
315  }
316 
320  protected function releaseMaterials(): void
321  {
322  if (!count((array) $this->initItemIdsFromPost())) {
323  $this->tpl->setOnScreenMessage(
324  'failure',
325  $this->lng->txt('select_one'),
326  true
327  );
328  $this->ctrl->redirect($this, 'show');
329  }
330 
331  $collection = $this->obj_lp->getCollectionInstance();
332  if ($collection && $collection->hasSelectableItems()) {
333  $collection->releaseGrouping($this->initItemIdsFromPost());
334 
335  $this->obj_lp->resetCaches();
336 
337  // refresh learning progress
339  }
340 
341  $this->tpl->setOnScreenMessage(
342  'success',
343  $this->lng->txt('trac_settings_saved'),
344  true
345  );
346  $this->ctrl->redirect($this, 'show');
347  }
348 
352  protected function saveObligatoryMaterials(): void
353  {
354  $groups = [];
355  if ($this->http->wrapper()->post()->has('grp')) {
356  $groups = $this->http->wrapper()->post()->retrieve(
357  'grp',
358  $this->refinery->kindlyTo()->dictOf(
359  $this->refinery->kindlyTo()->int()
360  )
361  );
362  }
363  if (!count($groups)) {
364  $this->tpl->setOnScreenMessage(
365  'failure',
366  $this->lng->txt('select_one'),
367  true
368  );
369  $this->ctrl->redirect($this, 'show');
370  }
371 
372  try {
373  $collection = $this->obj_lp->getCollectionInstance();
374  if ($collection && $collection->hasSelectableItems()) {
375  $collection->saveObligatoryMaterials($groups);
376 
377  $this->obj_lp->resetCaches();
378 
379  // refresh learning progress
381  }
382 
383  $this->tpl->setOnScreenMessage(
384  'success',
385  $this->lng->txt('settings_saved'),
386  true
387  );
388  $this->ctrl->redirect($this, 'show');
389  } catch (UnexpectedValueException $e) {
390  $this->tpl->setOnScreenMessage(
391  'failure',
392  $this->lng->txt(
393  'trac_grouped_material_obligatory_err'
394  ),
395  true
396  );
397  $this->tpl->setOnScreenMessage(
398  'info',
399  $this->lng->txt('err_check_input'),
400  true
401  );
402  $this->ctrl->redirect($this, 'show');
403  }
404  }
405 
409  protected function updateTLT(): void
410  {
411  $paths = $this->lom_services->paths();
412  $data_helper = $this->lom_services->dataHelper();
413 
414  $tlt = (array) ($this->http->request()->getParsedBody()['tlt'] ?? []);
415  foreach ($tlt as $item_id => $item) {
416  $lom_duration = $data_helper->durationFromIntegers(
417  null,
418  (int) $item['mo'],
419  (int) $item['d'],
420  (int) $item['h'],
421  (int) $item['m'],
422  null
423  );
424  $this->lom_services->manipulate($this->getObjId(), $item_id, 'st')
425  ->prepareCreateOrUpdate(
426  $paths->firstTypicalLearningTime(),
427  $lom_duration
428  )->execute();
429  }
430 
431  // refresh learning progress
432  $this->obj_lp->resetCaches();
434 
435  $this->tpl->setOnScreenMessage(
436  'success',
437  $this->lng->txt('settings_saved'),
438  true
439  );
440  $this->ctrl->redirect($this, 'show');
441  }
442 
443  protected function getLPPathInfo(int $a_ref_id, array &$a_res): bool
444  {
445  $has_lp_parents = false;
446 
447  $path = $this->tree->getNodePath($a_ref_id);
448  array_shift($path); // root
449  foreach ($path as $node) {
450  $supports_lp = ilObjectLP::isSupportedObjectType($node["type"]);
451  if ($supports_lp || $has_lp_parents) {
452  $a_res[(int) $node["child"]]["node"] = array(
453  "type" => (string) $node["type"]
454  ,
455  "title" => (string) $node["title"]
456  ,
457  "obj_id" => (int) $node["obj_id"]
458  ,
459  "lp" => false
460  ,
461  "active" => false
462  );
463  }
464 
465  if (
466  $supports_lp &&
467  $node["child"] != $a_ref_id) {
468  $a_res[(int) $node["child"]]["node"]["lp"] = true;
469  $has_lp_parents = true;
470 
471  $parent_obj_id = (int) $node['obj_id'];
472  $parent_obj_lp = \ilObjectLP::getInstance($parent_obj_id);
473  $parent_collection = $parent_obj_lp->getCollectionInstance();
474  if (
475  $parent_collection &&
476  $parent_collection->hasSelectableItems() &&
477  $parent_collection->isAssignedEntry($a_ref_id)
478  ) {
479  $a_res[$node['child']]['node']['active'] = true;
480  }
481  }
482  }
483  return $has_lp_parents;
484  }
485 
486  protected function handleLPUsageInfo(): string
487  {
488  $ref_id = 0;
489  if ($this->http->wrapper()->query()->has('ref_id')) {
490  $ref_id = $this->http->wrapper()->query()->retrieve(
491  'ref_id',
492  $this->refinery->kindlyTo()->int()
493  );
494  } elseif ($this->http->wrapper()->post()->has('ref_id')) {
495  $ref_id = $this->http->wrapper()->post()->retrieve(
496  'ref_id',
497  $this->refinery->kindlyTo()->int()
498  );
499  }
500  $coll = array();
501  if ($ref_id &&
502  $this->getLPPathInfo((int) $ref_id, $coll)) {
503  $tpl = new ilTemplate(
504  "tpl.lp_obj_settings_tree_info.html",
505  true,
506  true,
507  "components/ILIAS/Tracking"
508  );
509 
510  $margin = 0;
511  $has_active = false;
512  foreach ($coll as $parent_ref_id => $parts) {
513  $node = $parts["node"];
514  $params = array();
515  if ($node["lp"]) {
516  if ($node["active"]) {
517  $tpl->touchBlock("parent_active_bl");
518  $has_active = true;
519  }
520 
521  $params["gotolp"] = 1;
522  }
523 
524  if ($this->access->checkAccess("read", "", $parent_ref_id) &&
525  $parent_ref_id != $ref_id) { // #17170
526  $tpl->setCurrentBlock("parent_link_bl");
527  $tpl->setVariable("PARENT_LINK_TITLE", $node["title"]);
528  $tpl->setVariable(
529  "PARENT_URL",
530  ilLink::_getLink(
531  $parent_ref_id,
532  $node["type"],
533  $params
534  )
535  );
537  } else {
538  $tpl->setCurrentBlock("parent_nolink_bl");
539  $tpl->setVariable("PARENT_NOLINK_TITLE", $node["title"]);
541  }
542 
543  $tpl->setCurrentBlock("parent_usage_bl");
544  $tpl->setVariable(
545  "PARENT_TYPE_URL",
547  $node["obj_id"],
548  "small",
549  $node["type"]
550  )
551  );
552  $tpl->setVariable(
553  "PARENT_TYPE_ALT",
554  $this->lng->txt("obj_" . $node["type"])
555  );
556 
557  $tpl->setVariable(
558  "PARENT_STYLE",
559  $node["lp"]
560  ? ''
561  : ' class="ilLPParentInfoListLPUnsupported"'
562  );
563  $tpl->setVariable("MARGIN", $margin);
565 
566  $margin += 25;
567  }
568 
569  if ($has_active) {
570  $tpl->setVariable(
571  "LEGEND",
572  sprintf(
573  $this->lng->txt("trac_lp_settings_info_parent_legend"),
575  )
576  );
577  }
578 
579  $panel = $this->ui_factory->panel()->secondary()->legacy(
580  $this->lng->txt("trac_lp_settings_info_parent_container"),
581  $this->ui_factory->legacy($tpl->get())
582  );
583 
584  return $this->ui_renderer->render($panel);
585  }
586  return '';
587  }
588 }
__construct(int $a_mode, int $a_ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static isSupportedObjectType(string $type)
show()
Show settings tables.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
touchBlock(string $block)
overwrites ITX::touchBlock.
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
Class ilLPListOfSettingsGUI.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parse(ilLPCollection $a_collection)
Read and parse items.
$path
Definition: ltiservices.php:30
static _lookupObjId(int $ref_id)
static http()
Fetches the global http state from ILIAS.
This class represents a property in a property form.
static _lookupTitle(int $obj_id)
setValue(string $a_value)
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
getLPPathInfo(int $a_ref_id, array &$a_res)
setRequired(bool $a_required)
saveObligatoryMaterials()
Save obligatory state per grouped materials.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
getTableByMode()
Get tables by mode.
__construct(Container $dic, ilPlugin $plugin)
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
static getInstance(int $obj_id)