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