ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilADTEnumFormBridge.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 {
23  protected bool $force_radio = false;
24  protected array $option_infos = [];
25  protected bool $auto_sort = true;
26 
27  protected function isValidADT(ilADT $a_adt): bool
28  {
29  return ($a_adt instanceof ilADTEnum);
30  }
31 
32  public function setAutoSort($a_value)
33  {
34  $this->auto_sort = (bool) $a_value;
35  }
36 
37  public function forceRadio($a_value, ?array $a_info = null)
38  {
39  $this->force_radio = (bool) $a_value;
40  if ($this->force_radio) {
41  $this->option_infos = (array) $a_info;
42  }
43  }
44 
45  public function addToForm(): void
46  {
47  $def = $this->getADT()->getCopyOfDefinition();
48  $selection = $this->getADT()->getSelection();
49 
50  $options = $def->getOptions();
51 
52  if ($this->auto_sort) {
53  asort($options);
54  }
55 
56  if (!$this->isRequired()) {
57  $options = array("" => "-") + $options;
58  } elseif ($this->getADT()->isNull()) {
59  $options = array("" => $this->lng->txt("please_select")) + $options;
60  }
61 
62  if (!$this->force_radio) {
63  $select = new ilSelectInputGUI($this->getTitle(), $this->getElementId());
64 
65  $select->setOptions($options);
66  } else {
67  $select = new ilRadioGroupInputGUI($this->getTitle(), $this->getElementId());
68 
69  foreach ($options as $value => $caption) {
70  $option = new ilRadioOption($caption, $value);
71  if (is_array($this->option_infos) && array_key_exists($value, $this->option_infos)) {
72  $option->setInfo($this->option_infos[$value]);
73  }
74  $select->addOption($option);
75  }
76  }
77 
78  $this->addBasicFieldProperties($select, $def);
79 
80  $select->setValue($selection);
81 
82  $this->addToParentElement($select);
83  }
84 
85  public function importFromPost(): void
86  {
87  // ilPropertyFormGUI::checkInput() is pre-requisite
88  $this->getADT()->setSelection($this->getForm()->getInput($this->getElementId()));
89 
90  $field = $this->getForm()->getItemByPostVar($this->getElementId());
91  $field->setValue($this->getADT()->getSelection());
92  }
93 
94  protected function isActiveForSubItems($a_parent_option = null): bool
95  {
96  return ($this->getADT()->getSelection() == $a_parent_option);
97  }
98 }
This class represents an option in a radio group.
forceRadio($a_value, ?array $a_info=null)
addToParentElement(ilFormPropertyGUI $a_field)
isActiveForSubItems($a_parent_option=null)
This class represents a selection list property in a property form.
ADT form bridge base class.
ADT base class.
Definition: class.ilADT.php:25
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This class represents a property in a property form.