ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLPListOfSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
22use ILIAS\Tracking\View\Factory as ViewFactory;
24
32{
35 protected ProgressBlockSettings $progress_block_settings;
36
37 public function __construct(int $a_mode, int $a_ref_id)
38 {
39 parent::__construct($a_mode, $a_ref_id);
40
41 $this->obj_settings = new ilLPObjSettings($this->getObjId());
42 $this->obj_lp = ilObjectLP::getInstance($this->getObjId());
43 $this->progress_block_settings = (new ViewFactory())->progressBlock()->settings()->repository();
44 }
45
49 public function executeCommand(): void
50 {
51 switch ($this->ctrl->getNextClass()) {
52 default:
53 $cmd = $this->__getDefaultCommand();
54 $this->$cmd();
55 }
56 }
57
58 protected function initItemIdsFromPost(): array
59 {
60 if ($this->http->wrapper()->post()->has('item_ids')) {
61 return $this->http->wrapper()->post()->retrieve(
62 'item_ids',
63 $this->refinery->kindlyTo()->listOf(
64 $this->refinery->kindlyTo()->int()
65 )
66 );
67 }
68 return [];
69 }
70
74 protected function show(): void
75 {
76 $this->help->setSubScreenId("trac_settings");
77 $info = $this->obj_lp->getSettingsInfo();
78 if ($info) {
79 $this->tpl->setOnScreenMessage('info', $info);
80 }
81
82 $form = $this->initFormSettings();
83 $this->tpl->setContent(
84 $this->handleLPUsageInfo() .
85 $this->ui_renderer->render($form) .
86 $this->getTableByMode()
87 );
88 }
89
90 protected function initFormSettings(): StandardForm
91 {
92 $mode_groups = [];
93 if ($this->obj_lp->hasIndividualModeOptions()) {
94 $mode_groups = $this->obj_lp->initInvidualModeOptions();
95 } else {
96 foreach ($this->obj_lp->getValidModes() as $mode_key) {
97 $mode_config_inputs = [];
98
99 if ($mode_key == ilLPObjSettings::LP_MODE_VISITS) {
100 $mode_config_inputs['visits'] = $this->ui_factory->input()->field()->numeric(
101 $this->lng->txt('trac_visits'),
102 sprintf(
103 $this->lng->txt('trac_visits_info'),
105 )
106 )->withRequired(true)
107 ->withAdditionalTransformation(
108 $this->refinery->in()->series([
109 $this->refinery->int()->isGreaterThanOrEqual(1),
110 $this->refinery->int()->isLessThanOrEqual(99999)
111 ])
112 )->withValue($this->obj_settings->getVisits());
113 }
114
115 if ($mode_key == ilLPObjSettings::LP_MODE_COLLECTION) {
116 $mode_config_inputs['show_block'] = $this->ui_factory->input()->field()->checkbox(
117 $this->lng->txt('trac_show_progress_block'),
118 )->withValue(
119 $this->progress_block_settings->isBlockShownForObject($this->getObjId())
120 );
121 }
122
123 $mode_config_inputs = array_merge(
124 $mode_config_inputs,
125 $this->obj_lp->appendModeConfiguration($mode_key)
126 );
127
128 $mode_groups[$mode_key] = $this->ui_factory->input()->field()->group(
129 $mode_config_inputs,
130 $this->obj_lp->getModeText($mode_key),
131 $this->obj_lp->getModeInfoText($mode_key)
132 );
133 }
134 }
135
136 $mode = $this->ui_factory->input()->field()->switchableGroup(
137 $mode_groups,
138 $this->lng->txt('trac_mode')
139 )->withRequired(true)
140 ->withValue((string) $this->obj_lp->getCurrentMode());
141
142 $section = $this->ui_factory->input()->field()->section(
143 ['modus' => $mode],
144 $this->lng->txt('tracking_settings')
145 );
146
147 return $this->ui_factory->input()->container()->form()->standard(
148 $this->ctrl->getLinkTarget($this, 'saveSettings'),
149 ['main' => $section]
150 );
151 }
152
153 protected function saveSettings(): void
154 {
155 $form = $this->initFormSettings()
156 ->withRequest($this->http->request());
157 if ($data = $form->getData()) {
158 $selected_mode = (string) $data['main']['modus'][0];
159 $mode_data = $data['main']['modus'][1];
160
161 // mode
162 if ($this->obj_lp->shouldFetchIndividualModeFromFormSubmission()) {
163 $new_mode = $this->obj_lp->fetchIndividualModeFromFormSubmission(
164 $selected_mode,
165 $mode_data
166 );
167 } else {
168 $new_mode = (int) $selected_mode;
169 }
170 $old_mode = $this->obj_lp->getCurrentMode();
171 // anything changed?
172 $mode_changed = ($old_mode != $new_mode);
173
174 // visits
175 $new_visits = null;
176 $visits_changed = null;
177 if ($new_mode == ilLPObjSettings::LP_MODE_VISITS) {
178 $new_visits = (int) $mode_data['visits'];
179 $old_visits = $this->obj_settings->getVisits();
180 $visits_changed = ($old_visits != $new_visits);
181 }
182
183 // progress block
184 if ($new_mode == ilLPObjSettings::LP_MODE_COLLECTION) {
185 $this->progress_block_settings->setShowBlockForObject(
186 $this->getObjId(),
187 (bool) $mode_data['show_block']
188 );
189 }
190
191 $this->obj_lp->saveModeConfiguration(
192 $selected_mode,
193 $mode_data,
194 $mode_changed
195 );
196
197 if ($mode_changed) {
198 // delete existing collection
199 $collection = $this->obj_lp->getCollectionInstance();
200 if ($collection) {
201 $collection->delete();
202 }
203 }
204
205
206 // has to be done before LP refresh!
207 $this->obj_lp->resetCaches();
208
209 $this->obj_settings->setMode($new_mode);
210 $this->obj_settings->setVisits((int) $new_visits);
211 $this->obj_settings->update(true);
212
213 if ($mode_changed &&
214 $this->obj_lp->getCollectionInstance() &&
215 $new_mode != ilLPObjSettings::LP_MODE_MANUAL_BY_TUTOR) { // #14819
216 $this->tpl->setOnScreenMessage(
217 'info',
218 $this->lng->txt(
219 'trac_edit_collection'
220 ),
221 true
222 );
223 }
224 $this->tpl->setOnScreenMessage(
225 'success',
226 $this->lng->txt(
227 'trac_settings_saved'
228 ),
229 true
230 );
231 $this->ctrl->redirect($this, 'show');
232 }
233
234 $this->tpl->setContent(
235 $this->handleLPUsageInfo() .
236 $this->ui_renderer->render($form) .
237 $this->getTableByMode()
238 );
239 }
240
244 protected function getTableByMode(): string
245 {
246 $collection = $this->obj_lp->getCollectionInstance();
247 if ($collection && $collection->hasSelectableItems()) {
249 $this,
250 'show',
251 $this->getRefId(),
252 $this->obj_lp->getCurrentMode()
253 );
254 $table->parse($collection);
255 return $table->getHTML();
256 }
257 return '';
258 }
259
260 protected function assign(): void
261 {
262 if (!$this->initItemIdsFromPost()) {
263 $this->tpl->setOnScreenMessage(
264 'failure',
265 $this->lng->txt('select_one'),
266 true
267 );
268 $this->ctrl->redirect($this, 'show');
269 }
270 if (count($this->initItemIdsFromPost())) {
271 $collection = $this->obj_lp->getCollectionInstance();
272 if ($collection && $collection->hasSelectableItems()) {
273 $collection->activateEntries($this->initItemIdsFromPost());
274 }
275 // refresh learning progress
276 $this->obj_lp->resetCaches();
278 }
279 $this->tpl->setOnScreenMessage(
280 'success',
281 $this->lng->txt('trac_settings_saved'),
282 true
283 );
284 $this->ctrl->redirect($this, 'show');
285 }
286
287 protected function deassign(): void
288 {
289 if (!$this->initItemIdsFromPost()) {
290 $this->tpl->setOnScreenMessage(
291 'failure',
292 $this->lng->txt('select_one'),
293 true
294 );
295 $this->ctrl->redirect($this, 'show');
296 return;
297 }
298 if (count($this->initItemIdsFromPost())) {
299 $collection = $this->obj_lp->getCollectionInstance();
300 if ($collection && $collection->hasSelectableItems()) {
301 $collection->deactivateEntries($this->initItemIdsFromPost());
302 }
303
304 // #15045 - has to be done before LP refresh!
305 $this->obj_lp->resetCaches();
306
307 // refresh learning progress
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 groupMaterials(): 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 // Assign new grouping id
335 $collection->createNewGrouping($this->initItemIdsFromPost());
336
337 $this->obj_lp->resetCaches();
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 releaseMaterials(): void
355 {
356 if (!count((array) $this->initItemIdsFromPost())) {
357 $this->tpl->setOnScreenMessage(
358 'failure',
359 $this->lng->txt('select_one'),
360 true
361 );
362 $this->ctrl->redirect($this, 'show');
363 }
364
365 $collection = $this->obj_lp->getCollectionInstance();
366 if ($collection && $collection->hasSelectableItems()) {
367 $collection->releaseGrouping($this->initItemIdsFromPost());
368
369 $this->obj_lp->resetCaches();
370
371 // refresh learning progress
373 }
374
375 $this->tpl->setOnScreenMessage(
376 'success',
377 $this->lng->txt('trac_settings_saved'),
378 true
379 );
380 $this->ctrl->redirect($this, 'show');
381 }
382
386 protected function saveObligatoryMaterials(): void
387 {
388 $groups = [];
389 if ($this->http->wrapper()->post()->has('grp')) {
390 $groups = $this->http->wrapper()->post()->retrieve(
391 'grp',
392 $this->refinery->kindlyTo()->dictOf(
393 $this->refinery->kindlyTo()->int()
394 )
395 );
396 }
397 if (!count($groups)) {
398 $this->tpl->setOnScreenMessage(
399 'failure',
400 $this->lng->txt('select_one'),
401 true
402 );
403 $this->ctrl->redirect($this, 'show');
404 }
405
406 try {
407 $collection = $this->obj_lp->getCollectionInstance();
408 if ($collection && $collection->hasSelectableItems()) {
409 $collection->saveObligatoryMaterials($groups);
410
411 $this->obj_lp->resetCaches();
412
413 // refresh learning progress
415 }
416
417 $this->tpl->setOnScreenMessage(
418 'success',
419 $this->lng->txt('settings_saved'),
420 true
421 );
422 $this->ctrl->redirect($this, 'show');
423 } catch (UnexpectedValueException $e) {
424 $this->tpl->setOnScreenMessage(
425 'failure',
426 $this->lng->txt(
427 'trac_grouped_material_obligatory_err'
428 ),
429 true
430 );
431 $this->tpl->setOnScreenMessage(
432 'info',
433 $this->lng->txt('err_check_input'),
434 true
435 );
436 $this->ctrl->redirect($this, 'show');
437 }
438 }
439
443 protected function updateTLT(): void
444 {
445 $paths = $this->lom_services->paths();
446 $data_helper = $this->lom_services->dataHelper();
447
448 $tlt = (array) ($this->http->request()->getParsedBody()['tlt'] ?? []);
449 foreach ($tlt as $item_id => $item) {
450 $lom_duration = $data_helper->durationFromIntegers(
451 null,
452 (int) $item['mo'],
453 (int) $item['d'],
454 (int) $item['h'],
455 (int) $item['m'],
456 null
457 );
458 $this->lom_services->manipulate($this->getObjId(), $item_id, 'st')
459 ->prepareCreateOrUpdate(
460 $paths->firstTypicalLearningTime(),
461 $lom_duration
462 )->execute();
463 }
464
465 // refresh learning progress
466 $this->obj_lp->resetCaches();
468
469 $this->tpl->setOnScreenMessage(
470 'success',
471 $this->lng->txt('settings_saved'),
472 true
473 );
474 $this->ctrl->redirect($this, 'show');
475 }
476
477 protected function getLPPathInfo(int $a_ref_id, array &$a_res): bool
478 {
479 $has_lp_parents = false;
480
481 $path = $this->tree->getNodePath($a_ref_id);
482 array_shift($path); // root
483 foreach ($path as $node) {
484 $supports_lp = ilObjectLP::isSupportedObjectType($node["type"]);
485 if ($supports_lp || $has_lp_parents) {
486 $a_res[(int) $node["child"]]["node"] = array(
487 "type" => (string) $node["type"]
488 ,
489 "title" => (string) $node["title"]
490 ,
491 "obj_id" => (int) $node["obj_id"]
492 ,
493 "lp" => false
494 ,
495 "active" => false
496 );
497 }
498
499 if (
500 $supports_lp &&
501 $node["child"] != $a_ref_id) {
502 $a_res[(int) $node["child"]]["node"]["lp"] = true;
503 $has_lp_parents = true;
504
505 $parent_obj_id = (int) $node['obj_id'];
506 $parent_obj_lp = \ilObjectLP::getInstance($parent_obj_id);
507 $parent_collection = $parent_obj_lp->getCollectionInstance();
508 if (
509 $parent_collection &&
510 $parent_collection->hasSelectableItems() &&
511 $parent_collection->isAssignedEntry($a_ref_id)
512 ) {
513 $a_res[$node['child']]['node']['active'] = true;
514 }
515 }
516 }
517 return $has_lp_parents;
518 }
519
520 protected function handleLPUsageInfo(): string
521 {
522 $ref_id = 0;
523 if ($this->http->wrapper()->query()->has('ref_id')) {
524 $ref_id = $this->http->wrapper()->query()->retrieve(
525 'ref_id',
526 $this->refinery->kindlyTo()->int()
527 );
528 } elseif ($this->http->wrapper()->post()->has('ref_id')) {
529 $ref_id = $this->http->wrapper()->post()->retrieve(
530 'ref_id',
531 $this->refinery->kindlyTo()->int()
532 );
533 }
534 $coll = array();
535 if ($ref_id &&
536 $this->getLPPathInfo((int) $ref_id, $coll)) {
537 $tpl = new ilTemplate(
538 "tpl.lp_obj_settings_tree_info.html",
539 true,
540 true,
541 "components/ILIAS/Tracking"
542 );
543
544 $margin = 0;
545 $has_active = false;
546 foreach ($coll as $parent_ref_id => $parts) {
547 $node = $parts["node"];
548 $params = array();
549 if ($node["lp"]) {
550 if ($node["active"]) {
551 $tpl->touchBlock("parent_active_bl");
552 $has_active = true;
553 }
554
555 $params["gotolp"] = 1;
556 }
557
558 $tpl->setVariable("EXPAND_GLYPH", $this->ui_renderer->render(
559 $this->ui_factory->symbol()->glyph()->expand()->withUnavailableAction()
560 ));
561
562 if ($this->access->checkAccess("read", "", $parent_ref_id) &&
563 $parent_ref_id != $ref_id) { // #17170
564 $tpl->setCurrentBlock("parent_link_bl");
565 $tpl->setVariable("PARENT_LINK_TITLE", $node["title"]);
567 "PARENT_URL",
568 ilLink::_getLink(
569 $parent_ref_id,
570 $node["type"],
571 $params
572 )
573 );
575 } else {
576 $tpl->setCurrentBlock("parent_nolink_bl");
577 $tpl->setVariable("PARENT_NOLINK_TITLE", $node["title"]);
579 }
580
581 $tpl->setCurrentBlock("parent_usage_bl");
583 "PARENT_TYPE_URL",
585 $node["obj_id"],
586 "small",
587 $node["type"]
588 )
589 );
591 "PARENT_TYPE_ALT",
592 $this->lng->txt("obj_" . $node["type"])
593 );
594
596 "PARENT_STYLE",
597 $node["lp"]
598 ? ''
599 : ' class="ilLPParentInfoListLPUnsupported"'
600 );
601 $tpl->setVariable("MARGIN", $margin);
603
604 $margin += 25;
605 }
606
607 if ($has_active) {
609 "LEGEND",
610 sprintf(
611 $this->lng->txt("trac_lp_settings_info_parent_legend"),
613 )
614 );
615 }
616
617 $panel = $this->ui_factory->panel()->secondary()->legacy(
618 $this->lng->txt("trac_lp_settings_info_parent_container"),
619 $this->ui_factory->legacy()->content($tpl->get())
620 );
621
622 return $this->ui_renderer->render($panel);
623 }
624 return '';
625 }
626}
return true
Class ilLPListOfSettingsGUI.
saveObligatoryMaterials()
Save obligatory state per grouped materials.
getLPPathInfo(int $a_ref_id, array &$a_res)
__construct(int $a_mode, int $a_ref_id)
ProgressBlockSettings $progress_block_settings
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
Base class for object lp connectors.
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)
special template class to simplify handling of ITX/PEAR
$info
Definition: entry_point.php:21
setVariable(string $variable, $value='')
Sets the given variable to the given value.
touchBlock(string $block)
overwrites ITX::touchBlock.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This describes a standard form.
Definition: Standard.php:29
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
$path
Definition: ltiservices.php:30
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc