ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilADTMultiEnumFormBridge.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected ?array $option_infos = [];
24 protected bool $auto_sort = true;
25
26 protected function isValidADT(ilADT $a_adt): bool
27 {
28 return ($a_adt instanceof ilADTMultiEnum);
29 }
30
31 public function setOptionInfos(?array $a_info = null): void
32 {
33 $this->option_infos = $a_info;
34 }
35
36 public function setAutoSort(bool $a_value): void
37 {
38 $this->auto_sort = $a_value;
39 }
40
41 public function addToForm(): void
42 {
43 $def = $this->getADT()->getCopyOfDefinition();
44 $options = $def->getOptions();
45
46 if ($this->auto_sort) {
47 asort($options);
48 }
49
50 $cbox = new ilCheckboxGroupInputGUI($this->getTitle(), $this->getElementId());
51
52 foreach ($options as $value => $caption) {
53 $option = new ilCheckboxOption($caption, (string) $value);
54 if (is_array($this->option_infos) && array_key_exists($value, $this->option_infos)) {
55 $option->setInfo($this->option_infos[$value]);
56 }
57 $cbox->addOption($option);
58 }
59
60 $this->addBasicFieldProperties($cbox, $def);
61
62 $cbox->setValue($this->getADT()->getSelections());
63
64 $this->addToParentElement($cbox);
65 }
66
67 public function importFromPost(): void
68 {
69 // ilPropertyFormGUI::checkInput() is pre-requisite
70
71 /*
72 * BT 32161: post value is null when no checkbox is selected,
73 * check whether the corresponding form input really exists, just
74 * to be sure.
75 */
76 if (is_object($this->getForm()->getItemByPostVar($this->getElementId()))) {
77 $this->getADT()->setSelections($this->getForm()->getInput($this->getElementId()) ?? []);
78 }
79
80 $field = $this->getForm()->getItemByPostVar($this->getElementId());
81 $field->setValue($this->getADT()->getSelections());
82 }
83
84 protected function isActiveForSubItems($a_parent_option = null): bool
85 {
86 $current = $this->getADT()->getSelections();
87 return (is_array($current) && in_array($a_parent_option, $current));
88 }
89}
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:26
This class represents a property in a property form.
This class represents an option in a checkbox group.