ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCheckboxGroupInputGUI.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24include_once("./Services/Form/classes/class.ilCheckboxOption.php");
25
34{
35 protected $options = array();
36 protected $value;
37 protected $use_values_as_keys = false;
38
39
46 function __construct($a_title = "", $a_postvar = "")
47 {
48 parent::__construct($a_title, $a_postvar);
49 $this->setType("checkboxgroup");
50 }
51
57 function setUseValuesAsKeys($a_val)
58 {
59 $this->use_values_as_keys = $a_val;
60 }
61
68 {
70 }
71
77 function addOption($a_option)
78 {
79 $this->options[] = $a_option;
80 }
81
87 function setOptions($a_options)
88 {
89 foreach($a_options as $key => $label) {
90 if (is_string($label)) {
91 $chb = new ilCheckboxInputGUI($label, $key);
92 $this->options[] = $chb;
93 }
94 else if ($label instanceof ilCheckboxInputGUI) {
95 $this->options[] = $label;
96 }
97 }
98 }
99
105 function getOptions()
106 {
107 return $this->options;
108 }
109
115 function setValue($a_value)
116 {
117 $this->value = $a_value;
118 }
119
125 function getValue()
126 {
127 return $this->value;
128 }
129
135 function setValueByArray($a_values)
136 {
137 $this->setValue($a_values[$this->getPostVar()]);
138 foreach($this->getOptions() as $option)
139 {
140 foreach($option->getSubItems() as $item)
141 {
142 $item->setValueByArray($a_values);
143 }
144 }
145 }
146
152 function checkInput()
153 {
154 global $lng;
155
156 if ($this->getRequired() && count($_POST[$this->getPostVar()]) == 0)
157 {
158 $this->setAlert($lng->txt("msg_input_is_required"));
159
160 return false;
161 }
162
163 $ok = true;
164 foreach($this->getOptions() as $option)
165 {
166 foreach($option->getSubItems() as $item)
167 {
168 $item_ok = $item->checkInput();
169 if (!$item_ok && in_array($option->getValue(), $_POST[$this->getPostVar()]))
170 {
171 $ok = false;
172 }
173 }
174 }
175 return $ok;
176
177 }
178
184 function insert(&$a_tpl)
185 {
186 $a_tpl->setCurrentBlock("prop_generic");
187 $a_tpl->setVariable("PROP_GENERIC", $this->render());
188 $a_tpl->parseCurrentBlock();
189 }
190
196 function getItemByPostVar($a_post_var)
197 {
198 if ($this->getPostVar() == $a_post_var)
199 {
200 return $this;
201 }
202
203 foreach($this->getOptions() as $option)
204 {
205 foreach($option->getSubItems() as $item)
206 {
207 if ($item->getType() != "section_header")
208 {
209 $ret = $item->getItemByPostVar($a_post_var);
210 if (is_object($ret))
211 {
212 return $ret;
213 }
214 }
215 }
216 }
217
218 return false;
219 }
220
221 public function getTableFilterHTML()
222 {
223 return $this->render();
224 }
225
226 public function getToolbarHTML()
227 {
228 return $this->render('toolbar');
229 }
230
231 protected function render($a_mode = '')
232 {
233 $tpl = new ilTemplate("tpl.prop_checkbox_group.html", true, true, "Services/Form");
234
235 foreach($this->getOptions() as $option)
236 {
237 // information text for option
238 if ($option->getInfo() != "")
239 {
240 $tpl->setCurrentBlock("checkbox_option_desc");
241 $tpl->setVariable("CHECKBOX_OPTION_DESC", $option->getInfo());
242 $tpl->parseCurrentBlock();
243 }
244
245
246 if (count($option->getSubItems()) > 0)
247 {
248 $tpl->setCurrentBlock("checkbox_option_subform");
249 $pf = new ilPropertyFormGUI();
250 $pf->setMode("subform");
251 $pf->setItems($option->getSubItems());
252 $tpl->setVariable("SUB_FORM", $pf->getContent());
253 $tpl->setVariable("SOP_ID", $this->getFieldId()."_".$option->getValue());
254 if ($pf->getMultipart())
255 {
256 $this->getParentForm()->setMultipart(true);
257 }
258 $tpl->parseCurrentBlock();
259 if ($pf->getMultipart())
260 {
261 $this->getParentForm()->setMultipart(true);
262 }
263 }
264
265 $tpl->setCurrentBlock("prop_checkbox_option");
266
267 if (!$this->getUseValuesAsKeys())
268 {
269 $tpl->setVariable("POST_VAR", $this->getPostVar() . '[]');
270 $tpl->setVariable("VAL_CHECKBOX_OPTION", $option->getValue());
271 }
272 else
273 {
274 $tpl->setVariable("POST_VAR", $this->getPostVar().'['.$option->getValue().']');
275 $tpl->setVariable("VAL_CHECKBOX_OPTION", "1");
276 }
277
278 $tpl->setVariable("OP_ID", $this->getFieldId()."_".$option->getValue());
279 $tpl->setVariable("FID", $this->getFieldId());
280
281 if($this->getDisabled() or $option->getDisabled())
282 {
283 $tpl->setVariable('DISABLED','disabled="disabled" ');
284 }
285
286 if (is_array($this->getValue()))
287 {
288 if (!$this->getUseValuesAsKeys())
289 {
290 if (in_array($option->getValue(), $this->getValue()))
291 {
292 $tpl->setVariable("CHK_CHECKBOX_OPTION",
293 'checked="checked"');
294 }
295 }
296 else
297 {
298 $cval = $this->getValue();
299 if ($cval[$option->getValue()] == 1)
300 {
301 $tpl->setVariable("CHK_CHECKBOX_OPTION",
302 'checked="checked"');
303 }
304 }
305 }
306 $tpl->setVariable("TXT_CHECKBOX_OPTION", $option->getTitle());
307
308
309 $tpl->parseCurrentBlock();
310 }
311 $tpl->setVariable("ID", $this->getFieldId());
312
313 return $tpl->get();
314 }
315
321 public function getSubInputItemsRecursive()
322 {
323 $subInputItems = parent::getSubInputItemsRecursive();
324 foreach($this->getOptions() as $option)
325 {
329 $subInputItems = array_merge( $subInputItems, $option->getSubInputItemsRecursive() );
330 }
331
332 return $subInputItems;
333 }
334}
global $tpl
Definition: ilias.php:8
This class represents a property in a property form.
getUseValuesAsKeys()
Get use values as keys.
getToolbarHTML()
Get input item HTML to be inserted into ilToolbarGUI.
setUseValuesAsKeys($a_val)
Set use values as keys.
insert(&$a_tpl)
Insert property html.
getItemByPostVar($a_post_var)
Get item by post var.
__construct($a_title="", $a_postvar="")
Constructor.
setValueByArray($a_values)
Set value by array.
checkInput()
Check input, strip slashes etc.
getTableFilterHTML()
Get input item HTML to be inserted into table filters.
This class represents a checkbox property in a property form.
setType($a_type)
Set Type.
getParentForm()
Get Parent Form.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
This class represents a property form user interface.
This class represents a property that may include a sub form.
getSubInputItemsRecursive()
returns a flat array of possibly existing subitems recursively
special template class to simplify handling of ITX/PEAR
$_POST['username']
Definition: cron.php:12
Interface for property form input GUI classes that can be used in table filters.
Interface for property form input GUI classes that can be used in ilToolbarGUI.
global $lng
Definition: privfeed.php:40