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