ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMultiSelectInputGUI.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/Table/interfaces/interface.ilTableFilterItem.php");
25include_once("./Services/Form/classes/class.ilFormPropertyGUI.php");
26
35{
36 protected $options;
37 protected $value;
38 protected $select_all; // [bool]
39 protected $selected_first; // [bool]
40
47 private $width = 160;
48
55 private $height = 100;
56
60 protected $widthUnit = 'px';
61
65 protected $heightUnit = 'px';
66
70 protected $custom_attributes = array();
71
78 function __construct($a_title = "", $a_postvar = "")
79 {
80 parent::__construct($a_title, $a_postvar);
81 $this->setType("multi_select");
82 $this->setValue(array());
83 }
84
91 public function setWidth($a_width)
92 {
93 $this->width = (int)$a_width;
94 }
95
102 public function getWidth()
103 {
104 return $this->width;
105 }
106
113 public function setHeight($a_height)
114 {
115 $this->height = (int)$a_height;
116 }
117
124 public function getHeight()
125 {
126 return $this->height;
127 }
128
134 function setOptions($a_options)
135 {
136 $this->options = $a_options;
137 }
138
144 function getOptions()
145 {
146 return $this->options;
147 }
148
154 function setValue($a_array)
155 {
156 $this->value = $a_array;
157 }
158
164 function getValue()
165 {
166 return is_array($this->value) ? $this->value : array();
167 }
168
174 function setValueByArray($a_values)
175 {
176 $this->setValue($a_values[$this->getPostVar()]);
177 }
178
179
180 function enableSelectAll($a_value)
181 {
182 $this->select_all = (bool)$a_value;
183 }
184
185 function enableSelectedFirst($a_value)
186 {
187 $this->selected_first = (bool)$a_value;
188 }
189
190
196 function checkInput()
197 {
198 global $lng;
199
200 if (is_array($_POST[$this->getPostVar()]))
201 {
202 foreach ($_POST[$this->getPostVar()] as $k => $v)
203 {
204 $_POST[$this->getPostVar()][$k] =
206 }
207 }
208 else
209 {
210 $_POST[$this->getPostVar()] = array();
211 }
212 if ($this->getRequired() && count($_POST[$this->getPostVar()]) == 0)
213 {
214 $this->setAlert($lng->txt("msg_input_is_required"));
215
216 return false;
217 }
218 return true;
219 }
220
224 function render()
225 {
226 global $lng;
227
228 $tpl = new ilTemplate("tpl.prop_multi_select.html", true, true, "Services/Form");
229 $values = $this->getValue();
230
231 $options = $this->getOptions();
232 if($options)
233 {
234 if($this->select_all)
235 {
236 // enable select all toggle
237 $tpl->setCurrentBlock("item");
238 $tpl->setVariable("VAL", "");
239 $tpl->setVariable("ID_VAL", ilUtil::prepareFormOutput("all__toggle"));
240 $tpl->setVariable("IID", $this->getFieldId());
241 $tpl->setVariable("TXT_OPTION" ,"<em>".$lng->txt("select_all")."</em>");
242 $tpl->setVariable("POST_VAR", $this->getPostVar());
243 $tpl->parseCurrentBlock();
244
245 $tpl->setVariable("TOGGLE_FIELD_ID", $this->getFieldId());
246 $tpl->setVariable("TOGGLE_ALL_ID", $this->getFieldId()."_all__toggle");
247 $tpl->setVariable("TOGGLE_ALL_CBOX_ID", $this->getFieldId()."_");
248 }
249
250 if($this->selected_first)
251 {
252 // move selected values to top
253 $tmp_checked = $tmp_unchecked = array();
254 foreach($options as $option_value => $option_text)
255 {
256 if (in_array($option_value, $values))
257 {
258 $tmp_checked[$option_value] = $option_text;
259 }
260 else
261 {
262 $tmp_unchecked[$option_value] = $option_text;
263 }
264 }
265 $options = $tmp_checked + $tmp_unchecked;
266 unset($tmp_checked);
267 unset($tmp_unchecked);
268 }
269
270 foreach($options as $option_value => $option_text)
271 {
272 $tpl->setCurrentBlock("item");
273 if ($this->getDisabled())
274 {
275 $tpl->setVariable("DISABLED",
276 " disabled=\"disabled\"");
277 }
278 if (in_array($option_value, $values))
279 {
280 $tpl->setVariable("CHECKED",
281 " checked=\"checked\"");
282 }
283
284 $tpl->setVariable("VAL", ilUtil::prepareFormOutput($option_value));
285 $tpl->setVariable("ID_VAL", ilUtil::prepareFormOutput($option_value));
286 $tpl->setVariable("IID", $this->getFieldId());
287 $tpl->setVariable("TXT_OPTION", $option_text);
288 $tpl->setVariable("POST_VAR", $this->getPostVar());
289 $tpl->parseCurrentBlock();
290 }
291 }
292
293 $tpl->setVariable("ID", $this->getFieldId());
294 $tpl->setVariable("CUSTOM_ATTRIBUTES", implode(' ', $this->getCustomAttributes()));
295
296 if($this->getWidth())
297 {
298 $tpl->setVariable("WIDTH", $this->getWidth().($this->getWidthUnit()?$this->getWidthUnit():''));
299 }
300 if($this->getHeight())
301 {
302 $tpl->setVariable("HEIGHT", $this->getHeight().($this->getHeightUnit()?$this->getHeightUnit():''));
303 }
304
305 return $tpl->get();
306 }
307
313 function insert(&$a_tpl)
314 {
315 $a_tpl->setCurrentBlock("prop_generic");
316 $a_tpl->setVariable("PROP_GENERIC", $this->render());
317 $a_tpl->parseCurrentBlock();
318 }
319
324 {
325 $html = $this->render();
326 return $html;
327 }
328
329
333 public function getCustomAttributes() {
335 }
336
337
342 $this->custom_attributes = $custom_attributes;
343 }
344
345
349 public function addCustomAttribute($custom_attribute) {
350 $this->custom_attributes[] = $custom_attribute;
351 }
352
356 public function getWidthUnit() {
357 return $this->widthUnit;
358 }
359
363 public function setWidthUnit($widthUnit) {
364 $this->widthUnit = $widthUnit;
365 }
366
370 public function getHeightUnit() {
371 return $this->heightUnit;
372 }
373
377 public function setHeightUnit($heightUnit) {
378 $this->heightUnit = $heightUnit;
379 }
380}
global $tpl
Definition: ilias.php:8
This class represents a property in a property form.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
This class represents a multi selection list property in a property form.
getTableFilterHTML()
Get HTML for table filter.
setCustomAttributes($custom_attributes)
insert(&$a_tpl)
Insert property html.
setOptions($a_options)
Set Options.
setHeight($a_height)
Sets the height of this field.
__construct($a_title="", $a_postvar="")
Constructor.
checkInput()
Check input, strip slashes etc.
getWidth()
Returns the width currently set for this field.
setValueByArray($a_values)
Set value by array.
setWidth($a_width)
Sets the width of this field.
getHeight()
Returns the height currently set for this field.
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$_POST['username']
Definition: cron.php:12
$html
Definition: example_001.php:87
Interface for property form input GUI classes that can be used in table filters.
global $lng
Definition: privfeed.php:40