ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilADTEnumFormBridge.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTFormBridge.php";
4
6{
7 protected $force_radio; // [bool]
8 protected $option_infos; // [array]
9
10 protected function isValidADT(ilADT $a_adt)
11 {
12 return ($a_adt instanceof ilADTEnum);
13 }
14
15 public function forceRadio($a_value, array $a_info = null)
16 {
17 $this->force_radio = (bool)$a_value;
18 if($this->force_radio)
19 {
20 $this->option_infos = $a_info;
21 }
22 }
23
24 public function addToForm()
25 {
26 global $lng;
27
28 $def = $this->getADT()->getCopyOfDefinition();
29 $selection = $this->getADT()->getSelection();
30
31 $options = $def->getOptions();
32 asort($options); // ?
33
34 if(!$this->isRequired())
35 {
36 $options = array("" => "-") + $options;
37 }
38 else if($this->getADT()->isNull())
39 {
40 $options = array("" => $lng->txt("please_select")) + $options;
41 }
42
43 if(!(bool)$this->force_radio)
44 {
45 $select = new ilSelectInputGUI($this->getTitle(), $this->getElementId());
46
47 $select->setOptions($options);
48 }
49 else
50 {
51 $select = new ilRadioGroupInputGUI($this->getTitle(), $this->getElementId());
52
53 foreach($options as $value => $caption)
54 {
55 $option = new ilRadioOption($caption, $value);
56 if(is_array($this->option_infos) && array_key_exists($value, $this->option_infos))
57 {
58 $option->setInfo($this->option_infos[$value]);
59 }
60 $select->addOption($option);
61 }
62 }
63
64 $this->addBasicFieldProperties($select, $def);
65
66 $select->setValue($selection);
67
68 $this->addToParentElement($select);
69 }
70
71 public function importFromPost()
72 {
73 // ilPropertyFormGUI::checkInput() is pre-requisite
74 $this->getADT()->setSelection($this->getForm()->getInput($this->getElementId()));
75
76 $field = $this->getForm()->getItemByPostvar($this->getElementId());
77 $field->setValue($this->getADT()->getSelection());
78 }
79
80 protected function isActiveForSubItems($a_parent_option = null)
81 {
82 return ($this->getADT()->getSelection() == $a_parent_option);
83 }
84}
85
86?>
isActiveForSubItems($a_parent_option=null)
Check if element is currently active for subitem(s)
importFromPost()
Import values from form request POST data.
addToForm()
Add ADT-specific fields to form.
isValidADT(ilADT $a_adt)
Check if given ADT is valid.
forceRadio($a_value, array $a_info=null)
ADT form bridge base class.
addBasicFieldProperties(ilFormPropertyGUI $a_field, ilADTDefinition $a_def)
Helper method to handle generic properties like setRequired(), setInfo()
getElementId()
Get element id.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
isRequired()
Get required.
ADT base class.
Definition: class.ilADT.php:12
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
global $lng
Definition: privfeed.php:40
if(!is_array($argv)) $options