ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilADTEnumFormBridge.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 {
7  protected bool $force_radio = false;
8  protected array $option_infos = [];
9  protected bool $auto_sort = true;
10 
11  protected function isValidADT(ilADT $a_adt): bool
12  {
13  return ($a_adt instanceof ilADTEnum);
14  }
15 
16  public function setAutoSort($a_value)
17  {
18  $this->auto_sort = (bool) $a_value;
19  }
20 
21  public function forceRadio($a_value, array $a_info = null)
22  {
23  $this->force_radio = (bool) $a_value;
24  if ($this->force_radio) {
25  $this->option_infos = (array) $a_info;
26  }
27  }
28 
29  public function addToForm(): void
30  {
31  $def = $this->getADT()->getCopyOfDefinition();
32  $selection = $this->getADT()->getSelection();
33 
34  $options = $def->getOptions();
35 
36  if ($this->auto_sort) {
37  asort($options);
38  }
39 
40  if (!$this->isRequired()) {
41  $options = array("" => "-") + $options;
42  } elseif ($this->getADT()->isNull()) {
43  $options = array("" => $this->lng->txt("please_select")) + $options;
44  }
45 
46  if (!$this->force_radio) {
47  $select = new ilSelectInputGUI($this->getTitle(), $this->getElementId());
48 
49  $select->setOptions($options);
50  } else {
51  $select = new ilRadioGroupInputGUI($this->getTitle(), $this->getElementId());
52 
53  foreach ($options as $value => $caption) {
54  $option = new ilRadioOption($caption, $value);
55  if (is_array($this->option_infos) && array_key_exists($value, $this->option_infos)) {
56  $option->setInfo($this->option_infos[$value]);
57  }
58  $select->addOption($option);
59  }
60  }
61 
62  $this->addBasicFieldProperties($select, $def);
63 
64  $select->setValue($selection);
65 
66  $this->addToParentElement($select);
67  }
68 
69  public function importFromPost(): void
70  {
71  // ilPropertyFormGUI::checkInput() is pre-requisite
72  $this->getADT()->setSelection($this->getForm()->getInput($this->getElementId()));
73 
74  $field = $this->getForm()->getItemByPostVar($this->getElementId());
75  $field->setValue($this->getADT()->getSelection());
76  }
77 
78  protected function isActiveForSubItems($a_parent_option = null): bool
79  {
80  return ($this->getADT()->getSelection() == $a_parent_option);
81  }
82 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addToParentElement(ilFormPropertyGUI $a_field)
isActiveForSubItems($a_parent_option=null)
ADT form bridge base class.
ADT base class.
Definition: class.ilADT.php:11
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
This class represents a property in a property form.
forceRadio($a_value, array $a_info=null)