1 | <?php |
||
39 | class SelectionList extends Field |
||
40 | { |
||
41 | /** |
||
42 | * An array of options to display with this selection list |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $options = array(); |
||
46 | |||
47 | /** |
||
48 | * When set true, this selection list would allow multiple selections |
||
49 | * @var boolean |
||
50 | */ |
||
51 | protected $multiple; |
||
52 | |||
53 | protected $default; |
||
54 | |||
55 | /** |
||
56 | * Constructs a new selection list. This constructor could be invoked through |
||
57 | * the form helper's $this->form->get_* method as $this->form->get_selection_list(). |
||
58 | * |
||
59 | * @param string $label The label for the selection list |
||
60 | * @param string $name The name of the selection list |
||
61 | * @param string $description A brief description for the selection list |
||
62 | */ |
||
63 | 1 | public function __construct($label="", $name="", $description="") |
|
68 | |||
69 | /** |
||
70 | * Sets whether multiple selections are allowed. This method automatically |
||
71 | * appends the array symbol '[]' to the name of the selection list object. |
||
72 | * @param boolean $multiple |
||
73 | * @return SelectionList |
||
74 | */ |
||
75 | 1 | public function setMultiple($multiple) |
|
81 | |||
82 | /** |
||
83 | * Add an option to the selection list. |
||
84 | * @param string $label |
||
85 | * @param string $value |
||
86 | * @return SelectionList |
||
87 | */ |
||
88 | 1 | public function addOption($label="", $value="") |
|
94 | |||
95 | /** |
||
96 | * An alias for SelectionList::addOption |
||
97 | * @param string $label |
||
98 | * @param string $value |
||
99 | * @return SelectionList |
||
100 | */ |
||
101 | 1 | public function option($label='', $value='') |
|
106 | |||
107 | 1 | public function initial($default) |
|
112 | |||
113 | 1 | public function render() |
|
114 | { |
||
115 | 1 | $keys = array_keys($this->options); |
|
116 | 1 | array_unshift($keys, ''); |
|
117 | 1 | array_unshift($this->options, $this->default); |
|
118 | 1 | $this->options = array_combine($keys, $this->options); |
|
119 | |||
120 | 1 | $this->setAttribute('name', $this->name); |
|
121 | |||
122 | 1 | if($this->multiple) |
|
123 | { |
||
124 | 1 | $this->setAttribute('multiple', 'multiple'); |
|
125 | } |
||
126 | 1 | $this->setAttribute('class', "select {$this->getCSSClasses()}"); |
|
127 | |||
128 | 1 | return \ntentan\honam\TemplateEngine::render( |
|
129 | 1 | 'select_element.tpl.php', |
|
130 | 1 | array('element' => $this) |
|
131 | ); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Set the options using a key value pair datastructure represented in the form of |
||
136 | * a structured array. |
||
137 | * |
||
138 | * @param array $options An array of options |
||
139 | * |
||
140 | * @return SelectionList |
||
141 | */ |
||
142 | 1 | public function setOptions($options = []) |
|
143 | { |
||
144 | 1 | if(is_a($options, "\\ntentan\\honam\\template_engines\\php\\Variable")) |
|
145 | { |
||
146 | $options = $options->unescape(); |
||
|
|||
147 | } |
||
148 | 1 | $this->options += $options; |
|
149 | 1 | return $this; |
|
150 | } |
||
151 | |||
152 | /** |
||
153 | * Return the array of options |
||
154 | * @return array |
||
155 | */ |
||
156 | 1 | public function getOptions() |
|
160 | } |
||
161 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.