ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilADTEnumFormBridge.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 $force_radio; // [bool]
8  protected $option_infos = []; // [array]
9  protected $auto_sort = true; // [bool]
10 
11  protected function isValidADT(ilADT $a_adt)
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 = $a_info;
26  }
27  }
28 
29  public function addToForm()
30  {
31  global $DIC;
32 
33  $lng = $DIC['lng'];
34 
35  $def = $this->getADT()->getCopyOfDefinition();
36  $selection = $this->getADT()->getSelection();
37 
38  $options = $def->getOptions();
39 
40  if ((bool) $this->auto_sort) {
41  asort($options);
42  }
43 
44  if (!$this->isRequired()) {
45  $options = array("" => "-") + $options;
46  } elseif ($this->getADT()->isNull()) {
47  $options = array("" => $lng->txt("please_select")) + $options;
48  }
49 
50  if (!(bool) $this->force_radio) {
51  $select = new ilSelectInputGUI($this->getTitle(), $this->getElementId());
52 
53  $select->setOptions($options);
54  } else {
55  $select = new ilRadioGroupInputGUI($this->getTitle(), $this->getElementId());
56 
57  foreach ($options as $value => $caption) {
58  $option = new ilRadioOption($caption, $value);
59  if (is_array($this->option_infos) && array_key_exists($value, $this->option_infos)) {
60  $option->setInfo($this->option_infos[$value]);
61  }
62  $select->addOption($option);
63  }
64  }
65 
66  $this->addBasicFieldProperties($select, $def);
67 
68  $select->setValue($selection);
69 
70  $this->addToParentElement($select);
71  }
72 
73  public function importFromPost()
74  {
75  // ilPropertyFormGUI::checkInput() is pre-requisite
76  $this->getADT()->setSelection($this->getForm()->getInput($this->getElementId()));
77 
78  $field = $this->getForm()->getItemByPostvar($this->getElementId());
79  $field->setValue($this->getADT()->getSelection());
80  }
81 
82  protected function isActiveForSubItems($a_parent_option = null)
83  {
84  return ($this->getADT()->getSelection() == $a_parent_option);
85  }
86 }
This class represents an option in a radio group.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
isActiveForSubItems($a_parent_option=null)
This class represents a selection list property in a property form.
global $DIC
Definition: saml.php:7
ADT form bridge base class.
isRequired()
Get required.
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)
$lng
getElementId()
Get element id.
$def
Definition: croninfo.php:21