ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTMultiEnumFormBridge.php
Go to the documentation of this file.
1 <?php
2 
3 require_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 
60  /*
61  * BT 32161: post value is null when no checkbox is selected,
62  * check whether the corresponding form input really exists, just
63  * to be sure.
64  */
65  if (is_object($this->getForm()->getItemByPostVar($this->getElementId()))) {
66  $this->getADT()->setSelections($this->getForm()->getInput($this->getElementId()) ?? []);
67  }
68 
69  $field = $this->getForm()->getItemByPostvar($this->getElementId());
70  $field->setValue($this->getADT()->getSelections());
71  }
72 
73  protected function isActiveForSubItems($a_parent_option = null)
74  {
75  $current = $this->getADT()->getSelections();
76  return (is_array($current) && in_array($a_parent_option, $current));
77  }
78 }
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
This class represents an option in a checkbox group.
ADT form bridge base class.
isActiveForSubItems($a_parent_option=null)
ADT base class.
Definition: class.ilADT.php:11
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
$lng
global $DIC
Definition: goto.php:24
This class represents a property in a property form.
getElementId()
Get element id.