ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
24 include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
25 include_once("./Services/Form/classes/class.ilFormPropertyGUI.php");
26 
35 {
36  protected $options;
37  protected $value;
38 
45  private $width = 160;
46 
53  private $height = 100;
54 
61  function __construct($a_title = "", $a_postvar = "")
62  {
63  parent::__construct($a_title, $a_postvar);
64  $this->setType("multi_select");
65  $this->setValue(array());
66  }
67 
74  public function setWidth($a_width)
75  {
76  $this->width = (int)$a_width;
77  }
78 
85  public function getWidth()
86  {
87  return $this->width;
88  }
89 
96  public function setHeight($a_height)
97  {
98  $this->height = (int)$a_height;
99  }
100 
107  public function getHeight()
108  {
109  return $this->height;
110  }
111 
117  function setOptions($a_options)
118  {
119  $this->options = $a_options;
120  }
121 
127  function getOptions()
128  {
129  return $this->options;
130  }
131 
137  function setValue($a_array)
138  {
139  $this->value = $a_array;
140  }
141 
147  function getValue()
148  {
149  return is_array($this->value) ? $this->value : array();
150  }
151 
157  function setValueByArray($a_values)
158  {
159  $this->setValue($a_values[$this->getPostVar()]);
160  }
161 
167  function checkInput()
168  {
169  global $lng;
170 
171  if (is_array($_POST[$this->getPostVar()]))
172  {
173  foreach ($_POST[$this->getPostVar()] as $k => $v)
174  {
175  $_POST[$this->getPostVar()][$k] =
177  }
178  }
179  else
180  {
181  $_POST[$this->getPostVar()] = array();
182  }
183  if ($this->getRequired() && count($_POST[$this->getPostVar()]) == 0)
184  {
185  $this->setAlert($lng->txt("msg_input_is_required"));
186 
187  return false;
188  }
189  return true;
190  }
191 
195  function render()
196  {
197  $tpl = new ilTemplate("tpl.prop_multi_select.html", true, true, "Services/Form");
198  $values = $this->getValue();
199 
200  $options = $this->getOptions();
201  if($options)
202  {
203  foreach($options as $option_value => $option_text)
204  {
205  $tpl->setCurrentBlock("item");
206  if ($this->getDisabled())
207  {
208  $tpl->setVariable("DISABLED",
209  " disabled=\"disabled\"");
210  }
211  if (in_array($option_value, $values))
212  {
213  $tpl->setVariable("CHECKED",
214  " checked=\"checked\"");
215  }
216 
217  $tpl->setVariable("VAL", ilUtil::prepareFormOutput($option_value));
218  $tpl->setVariable("ID_VAL", ilUtil::prepareFormOutput($option_value));
219  $tpl->setVariable("IID", $this->getFieldId());
220  $tpl->setVariable("TXT_OPTION", $option_text);
221  $tpl->setVariable("POST_VAR", $this->getPostVar());
222  $tpl->parseCurrentBlock();
223  }
224  }
225 
226  $tpl->setVariable("ID", $this->getFieldId());
227 
228  $tpl->setVariable("WIDTH", $this->getWidth());
229  $tpl->setVariable("HEIGHT", $this->getHeight());
230 
231  return $tpl->get();
232  }
233 
239  function insert(&$a_tpl)
240  {
241  $a_tpl->setCurrentBlock("prop_generic");
242  $a_tpl->setVariable("PROP_GENERIC", $this->render());
243  $a_tpl->parseCurrentBlock();
244  }
245 
250  {
251  $html = $this->render();
252  return $html;
253  }
254 
255 }