ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
26  $this->option_infos = $a_info;
27  }
28  }
29 
30  public function addToForm()
31  {
32  global $lng;
33 
34  $def = $this->getADT()->getCopyOfDefinition();
35  $selection = $this->getADT()->getSelection();
36 
37  $options = $def->getOptions();
38 
39  if((bool)$this->auto_sort)
40  {
41  asort($options);
42  }
43 
44  if(!$this->isRequired())
45  {
46  $options = array("" => "-") + $options;
47  }
48  else if($this->getADT()->isNull())
49  {
50  $options = array("" => $lng->txt("please_select")) + $options;
51  }
52 
53  if(!(bool)$this->force_radio)
54  {
55  $select = new ilSelectInputGUI($this->getTitle(), $this->getElementId());
56 
57  $select->setOptions($options);
58  }
59  else
60  {
61  $select = new ilRadioGroupInputGUI($this->getTitle(), $this->getElementId());
62 
63  foreach($options as $value => $caption)
64  {
65  $option = new ilRadioOption($caption, $value);
66  if(is_array($this->option_infos) && array_key_exists($value, $this->option_infos))
67  {
68  $option->setInfo($this->option_infos[$value]);
69  }
70  $select->addOption($option);
71  }
72  }
73 
74  $this->addBasicFieldProperties($select, $def);
75 
76  $select->setValue($selection);
77 
78  $this->addToParentElement($select);
79  }
80 
81  public function importFromPost()
82  {
83  // ilPropertyFormGUI::checkInput() is pre-requisite
84  $this->getADT()->setSelection($this->getForm()->getInput($this->getElementId()));
85 
86  $field = $this->getForm()->getItemByPostvar($this->getElementId());
87  $field->setValue($this->getADT()->getSelection());
88  }
89 
90  protected function isActiveForSubItems($a_parent_option = null)
91  {
92  return ($this->getADT()->getSelection() == $a_parent_option);
93  }
94 }
95 
96 ?>
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.
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.
if(!is_array($argv)) $options
forceRadio($a_value, array $a_info=null)
Create styles array
The data for the language used.
getElementId()
Get element id.
global $lng
Definition: privfeed.php:17