ILIAS  release_7 Revision v7.30-3-g800a261c036
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{
38 protected $lng;
39
40 protected $options = array();
41 protected $value;
42 protected $use_values_as_keys = false;
43
44
51 public function __construct($a_title = "", $a_postvar = "")
52 {
53 global $DIC;
54
55 $this->lng = $DIC->language();
56 parent::__construct($a_title, $a_postvar);
57 $this->setType("checkboxgroup");
58 }
59
65 public function setUseValuesAsKeys($a_val)
66 {
67 $this->use_values_as_keys = $a_val;
68 }
69
75 public function getUseValuesAsKeys()
76 {
78 }
79
85 public function addOption($a_option)
86 {
87 $this->options[] = $a_option;
88 }
89
95 public function setOptions($a_options)
96 {
97 foreach ($a_options as $key => $label) {
98 if (is_string($label)) {
99 $chb = new ilCheckboxInputGUI($label, $key);
100 $this->options[] = $chb;
101 } elseif ($label instanceof ilCheckboxInputGUI) {
102 $this->options[] = $label;
103 }
104 }
105 }
106
112 public function getOptions()
113 {
114 return $this->options;
115 }
116
122 public function setValue($a_value)
123 {
124 $this->value = $a_value;
125 }
126
132 public function getValue()
133 {
134 return $this->value;
135 }
136
142 public function setValueByArray($a_values)
143 {
144 $this->setValue($a_values[$this->getPostVar()]);
145 foreach ($this->getOptions() as $option) {
146 foreach ($option->getSubItems() as $item) {
147 $item->setValueByArray($a_values);
148 }
149 }
150 }
151
157 public function checkInput()
158 {
160
161 if ($this->getRequired() && (!is_array($_POST[$this->getPostVar()]) || count($_POST[$this->getPostVar()]) === 0)) {
162 $this->setAlert($lng->txt('msg_input_is_required'));
163 return false;
164 }
165
166 $ok = true;
167 foreach ($this->getOptions() as $option) {
168 foreach ($option->getSubItems() as $item) {
169 $item_ok = $item->checkInput();
170 if (!$item_ok && in_array($option->getValue(), $_POST[$this->getPostVar()])) {
171 $ok = false;
172 }
173 }
174 }
175 return $ok;
176 }
177
183 public function insert($a_tpl)
184 {
185 $a_tpl->setCurrentBlock("prop_generic");
186 $a_tpl->setVariable("PROP_GENERIC", $this->render());
187 $a_tpl->parseCurrentBlock();
188 }
189
195 public function getItemByPostVar($a_post_var)
196 {
197 if ($this->getPostVar() == $a_post_var) {
198 return $this;
199 }
200
201 foreach ($this->getOptions() as $option) {
202 foreach ($option->getSubItems() as $item) {
203 if ($item->getType() != "section_header") {
204 $ret = $item->getItemByPostVar($a_post_var);
205 if (is_object($ret)) {
206 return $ret;
207 }
208 }
209 }
210 }
211
212 return false;
213 }
214
215 public function getTableFilterHTML()
216 {
217 return $this->render();
218 }
219
220 public function getToolbarHTML()
221 {
222 return $this->render('toolbar');
223 }
224
225 protected function render($a_mode = '')
226 {
227 $tpl = new ilTemplate("tpl.prop_checkbox_group.html", true, true, "Services/Form");
228
229 foreach ($this->getOptions() as $option) {
230 // information text for option
231 if ($option->getInfo() != "") {
232 $tpl->setCurrentBlock("checkbox_option_desc");
233 $tpl->setVariable("CHECKBOX_OPTION_DESC", $option->getInfo());
234 $tpl->parseCurrentBlock();
235 }
236
237
238 if (count($option->getSubItems()) > 0) {
239 $tpl->setCurrentBlock("checkbox_option_subform");
240 $pf = new ilPropertyFormGUI();
241 $pf->setMode("subform");
242 $pf->setItems($option->getSubItems());
243 $tpl->setVariable("SUB_FORM", $pf->getContent());
244 $tpl->setVariable("SOP_ID", $this->getFieldId() . "_" . $option->getValue());
245 if ($pf->getMultipart()) {
246 $this->getParentForm()->setMultipart(true);
247 }
248 $tpl->parseCurrentBlock();
249 if ($pf->getMultipart()) {
250 $this->getParentForm()->setMultipart(true);
251 }
252 }
253
254 $tpl->setCurrentBlock("prop_checkbox_option");
255
256 if (!$this->getUseValuesAsKeys()) {
257 $tpl->setVariable("POST_VAR", $this->getPostVar() . '[]');
258 $tpl->setVariable("VAL_CHECKBOX_OPTION", $option->getValue());
259 } else {
260 $tpl->setVariable("POST_VAR", $this->getPostVar() . '[' . $option->getValue() . ']');
261 $tpl->setVariable("VAL_CHECKBOX_OPTION", "1");
262 }
263
264 $tpl->setVariable("OP_ID", $this->getFieldId() . "_" . $option->getValue());
265 $tpl->setVariable("FID", $this->getFieldId());
266
267 if ($this->getDisabled() or $option->getDisabled()) {
268 $tpl->setVariable('DISABLED', 'disabled="disabled" ');
269 }
270
271 if (is_array($this->getValue())) {
272 if (!$this->getUseValuesAsKeys()) {
273 if (in_array($option->getValue(), $this->getValue())) {
274 $tpl->setVariable(
275 "CHK_CHECKBOX_OPTION",
276 'checked="checked"'
277 );
278 }
279 } else {
280 $cval = $this->getValue();
281 if ($cval[$option->getValue()] == 1) {
282 $tpl->setVariable(
283 "CHK_CHECKBOX_OPTION",
284 'checked="checked"'
285 );
286 }
287 }
288 }
289 $tpl->setVariable("TXT_CHECKBOX_OPTION", $option->getTitle());
290
291
292 $tpl->parseCurrentBlock();
293 }
294 $tpl->setVariable("ID", $this->getFieldId());
295
296 return $tpl->get();
297 }
298
304 public function getSubInputItemsRecursive()
305 {
306 $subInputItems = parent::getSubInputItemsRecursive();
307 foreach ($this->getOptions() as $option) {
311 $subInputItems = array_merge($subInputItems, $option->getSubInputItemsRecursive());
312 }
313
314 return $subInputItems;
315 }
316}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
This class represents a property in a property form.
getUseValuesAsKeys()
Get use values as keys.
insert($a_tpl)
Insert property html.
getToolbarHTML()
Get input item HTML to be inserted into ilToolbarGUI.
setUseValuesAsKeys($a_val)
Set use values as keys.
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
global $DIC
Definition: goto.php:24
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.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6