ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilADTMultiEnumFormBridge.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTFormBridge.php";
4
6{
7 protected $option_infos = []; // [array]
8 protected $auto_sort = true; // [bool]
9
10 protected function isValidADT(ilADT $a_adt)
11 {
12 return ($a_adt instanceof ilADTMultiEnum);
13 }
14
15 public function setOptionInfos(array $a_info = null)
16 {
17 $this->option_infos = $a_info;
18 }
19
20 public function setAutoSort($a_value)
21 {
22 $this->auto_sort = (bool) $a_value;
23 }
24
25 public function addToForm()
26 {
27 global $DIC;
28
29 $lng = $DIC['lng'];
30
31 $def = $this->getADT()->getCopyOfDefinition();
32
33 $options = $def->getOptions();
34
35 if ((bool) $this->auto_sort) {
36 asort($options);
37 }
38
39 $cbox = new ilCheckboxGroupInputGUI($this->getTitle(), $this->getElementId());
40
41 foreach ($options as $value => $caption) {
42 $option = new ilCheckboxOption($caption, $value);
43 if (is_array($this->option_infos) && array_key_exists($value, $this->option_infos)) {
44 $option->setInfo($this->option_infos[$value]);
45 }
46 $cbox->addOption($option);
47 }
48
49 $this->addBasicFieldProperties($cbox, $def);
50
51 $cbox->setValue($this->getADT()->getSelections());
52
53 $this->addToParentElement($cbox);
54 }
55
56 public function importFromPost()
57 {
58 // ilPropertyFormGUI::checkInput() is pre-requisite
59 $this->getADT()->setSelections($this->getForm()->getInput($this->getElementId()));
60
61 $field = $this->getForm()->getItemByPostvar($this->getElementId());
62 $field->setValue($this->getADT()->getSelections());
63 }
64
65 protected function isActiveForSubItems($a_parent_option = null)
66 {
67 $current = $this->getADT()->getSelections();
68 return (is_array($current) && in_array($a_parent_option, $current));
69 }
70}
An exception for terminatinating execution or to throw for unit testing.
ADT form bridge base class.
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
getElementId()
Get element id.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
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 class represents a property in a property form.
This class represents an option in a checkbox group.
$lng
$DIC
Definition: xapitoken.php:46