ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
24 include_once("./Services/Form/classes/class.ilCheckboxOption.php");
25 
34 {
35  protected $options = array();
36  protected $value;
37 
44  function __construct($a_title = "", $a_postvar = "")
45  {
46  parent::__construct($a_title, $a_postvar);
47  $this->setType("checkbox");
48  }
49 
55  function addOption($a_option)
56  {
57  $this->options[] = $a_option;
58  }
59 
65  function getOptions()
66  {
67  return $this->options;
68  }
69 
75  function setValue($a_value)
76  {
77  $this->value = $a_value;
78  }
79 
85  function getValue()
86  {
87  return $this->value;
88  }
89 
95  function setValueByArray($a_values)
96  {
97  $this->setValue($a_values[$this->getPostVar()]);
98  foreach($this->getOptions() as $option)
99  {
100  foreach($option->getSubItems() as $item)
101  {
102  $item->setValueByArray($a_values);
103  }
104  }
105  }
106 
112  function checkInput()
113  {
114  global $lng;
115 
116  if ($this->getRequired() && count($_POST[$this->getPostVar()]) == 0)
117  {
118  $this->setAlert($lng->txt("msg_input_is_required"));
119 
120  return false;
121  }
122 
123  $ok = true;
124  foreach($this->getOptions() as $option)
125  {
126  foreach($option->getSubItems() as $item)
127  {
128  $item_ok = $item->checkInput();
129  if (!$item_ok && in_array($option->getValue(), $_POST[$this->getPostVar()]))
130  {
131  $ok = false;
132  }
133  }
134  }
135  return $ok;
136 
137  }
138 
144  function insert(&$a_tpl)
145  {
146  $tpl = new ilTemplate("tpl.prop_checkbox_group.html", true, true, "Services/Form");
147 
148  foreach($this->getOptions() as $option)
149  {
150  // information text for option
151  if ($option->getInfo() != "")
152  {
153  $tpl->setCurrentBlock("checkbox_option_desc");
154  $tpl->setVariable("CHECKBOX_OPTION_DESC", $option->getInfo());
155  $tpl->parseCurrentBlock();
156  }
157 
158 
159  if (count($option->getSubItems()) > 0)
160  {
161  $tpl->setCurrentBlock("checkbox_option_subform");
162  $pf = new ilPropertyFormGUI();
163  $pf->setMode("subform");
164  $pf->setItems($option->getSubItems());
165  $tpl->setVariable("SUB_FORM", $pf->getContent());
166  $tpl->setVariable("SOP_ID", $this->getFieldId()."_".$option->getValue());
167  if ($pf->getMultipart())
168  {
169  $this->getParentForm()->setMultipart(true);
170  }
171  $tpl->parseCurrentBlock();
172  if ($pf->getMultipart())
173  {
174  $this->getParentForm()->setMultipart(true);
175  }
176  }
177 
178  $tpl->setCurrentBlock("prop_checkbox_option");
179  $tpl->setVariable("POST_VAR", $this->getPostVar() . '[]');
180  $tpl->setVariable("VAL_CHECKBOX_OPTION", $option->getValue());
181  $tpl->setVariable("OP_ID", $this->getFieldId()."_".$option->getValue());
182  $tpl->setVariable("FID", $this->getFieldId());
183  if($this->getDisabled() or $option->getDisabled())
184  {
185  $tpl->setVariable('DISABLED','disabled="disabled" ');
186  }
187  if (is_array($this->getValue()))
188  {
189  if (in_array($option->getValue(), $this->getValue()))
190  {
191  $tpl->setVariable("CHK_CHECKBOX_OPTION",
192  'checked="checked"');
193  }
194  }
195  $tpl->setVariable("TXT_CHECKBOX_OPTION", $option->getTitle());
196 
197 
198  $tpl->parseCurrentBlock();
199  }
200  $tpl->setVariable("ID", $this->getFieldId());
201 
202  $a_tpl->setCurrentBlock("prop_generic");
203  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
204  $a_tpl->parseCurrentBlock();
205 
206  }
207 
213  function getItemByPostVar($a_post_var)
214  {
215  if ($this->getPostVar() == $a_post_var)
216  {
217  return $this;
218  }
219 
220  foreach($this->getOptions() as $option)
221  {
222  foreach($option->getSubItems() as $item)
223  {
224  if ($item->getType() != "section_header")
225  {
226  $ret = $item->getItemByPostVar($a_post_var);
227  if (is_object($ret))
228  {
229  return $ret;
230  }
231  }
232  }
233  }
234 
235  return false;
236  }
237 
238 }