ILIAS  release_8 Revision v8.24
class.ilADTMultiEnumFormBridge.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6{
7 protected ?array $option_infos = [];
8 protected bool $auto_sort = true;
9
10 protected function isValidADT(ilADT $a_adt): bool
11 {
12 return ($a_adt instanceof ilADTMultiEnum);
13 }
14
15 public function setOptionInfos(array $a_info = null): void
16 {
17 $this->option_infos = $a_info;
18 }
19
20 public function setAutoSort(bool $a_value): void
21 {
22 $this->auto_sort = $a_value;
23 }
24
25 public function addToForm(): void
26 {
27 $def = $this->getADT()->getCopyOfDefinition();
28 $options = $def->getOptions();
29
30 if ($this->auto_sort) {
31 asort($options);
32 }
33
34 $cbox = new ilCheckboxGroupInputGUI($this->getTitle(), $this->getElementId());
35
36 foreach ($options as $value => $caption) {
37 $option = new ilCheckboxOption($caption, (string) $value);
38 if (is_array($this->option_infos) && array_key_exists($value, $this->option_infos)) {
39 $option->setInfo($this->option_infos[$value]);
40 }
41 $cbox->addOption($option);
42 }
43
44 $this->addBasicFieldProperties($cbox, $def);
45
46 $cbox->setValue($this->getADT()->getSelections());
47
48 $this->addToParentElement($cbox);
49 }
50
51 public function importFromPost(): void
52 {
53 // ilPropertyFormGUI::checkInput() is pre-requisite
54
55 /*
56 * BT 32161: post value is null when no checkbox is selected,
57 * check whether the corresponding form input really exists, just
58 * to be sure.
59 */
60 if (is_object($this->getForm()->getItemByPostVar($this->getElementId()))) {
61 $this->getADT()->setSelections($this->getForm()->getInput($this->getElementId()) ?? []);
62 }
63
64 $field = $this->getForm()->getItemByPostVar($this->getElementId());
65 $field->setValue($this->getADT()->getSelections());
66 }
67
68 protected function isActiveForSubItems($a_parent_option = null): bool
69 {
70 $current = $this->getADT()->getSelections();
71 return (is_array($current) && in_array($a_parent_option, $current));
72 }
73}
ADT form bridge base class.
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
addToParentElement(ilFormPropertyGUI $a_field)
importFromPost()
Import values from form request POST data.
isActiveForSubItems($a_parent_option=null)
Check if element is currently active for subitem(s)
addToForm()
Add ADT-specific fields to form.
ADT base class.
Definition: class.ilADT.php:12
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...