ILIAS  Release_4_0_x_branch Revision 61816
 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  function __construct($a_title = "", $a_postvar = "")
46  {
47  parent::__construct($a_title, $a_postvar);
48  $this->setType("multi_select");
49  $this->setValue(array());
50  }
51 
57  function setOptions($a_options)
58  {
59  $this->options = $a_options;
60  }
61 
67  function getOptions()
68  {
69  return $this->options;
70  }
71 
77  function setValue($a_array)
78  {
79  $this->value = $a_array;
80  }
81 
87  function getValue()
88  {
89  return is_array($this->value) ? $this->value : array();
90  }
91 
97  function setValueByArray($a_values)
98  {
99  $this->setValue($a_values[$this->getPostVar()]);
100  }
101 
107  function checkInput()
108  {
109  global $lng;
110 
111  if (is_array($_POST[$this->getPostVar()]))
112  {
113  foreach ($_POST[$this->getPostVar()] as $k => $v)
114  {
115  $_POST[$this->getPostVar()][$k] =
117  }
118  }
119  else
120  {
121  $_POST[$this->getPostVar()] = array();
122  }
123  if ($this->getRequired() && count($_POST[$this->getPostVar()]) == 0)
124  {
125  $this->setAlert($lng->txt("msg_input_is_required"));
126 
127  return false;
128  }
129  return true;
130  }
131 
135  function render()
136  {
137  $tpl = new ilTemplate("tpl.prop_multi_select.html", true, true, "Services/Form");
138  $values = $this->getValue();
139 
140  foreach($this->getOptions() as $option_value => $option_text)
141  {
142  $tpl->setCurrentBlock("item");
143  if ($this->getDisabled())
144  {
145  $tpl->setVariable("DISABLED",
146  " disabled=\"disabled\"");
147  }
148  if (in_array($option_value, $values))
149  {
150  $tpl->setVariable("CHECKED",
151  " checked=\"checked\"");
152  }
153 
154  $tpl->setVariable("VAL", ilUtil::prepareFormOutput($option_value));
155  $tpl->setVariable("ID_VAL", ilUtil::prepareFormOutput($option_value));
156  $tpl->setVariable("IID", $this->getFieldId());
157  $tpl->setVariable("TXT_OPTION", $option_text);
158  $tpl->setVariable("POST_VAR", $this->getPostVar());
159  $tpl->parseCurrentBlock();
160  }
161  $tpl->setVariable("ID", $this->getFieldId());
162 
163  return $tpl->get();
164  }
165 
171  function insert(&$a_tpl)
172  {
173  $a_tpl->setCurrentBlock("prop_generic");
174  $a_tpl->setVariable("PROP_GENERIC", $this->render());
175  $a_tpl->parseCurrentBlock();
176  }
177 
182  {
183  $html = $this->render();
184  return $html;
185  }
186 
187 }