ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCheckboxInputGUI.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/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php';
25 
34 {
35  protected $value = "1";
36  protected $checked;
37  protected $optiontitle = "";
38  protected $additional_attributes = '';
39 
46  function __construct($a_title = "", $a_postvar = "")
47  {
48  parent::__construct($a_title, $a_postvar);
49  $this->setType("checkbox");
50  }
51 
57  function setValue($a_value)
58  {
59  $this->value = $a_value;
60  }
61 
67  function getValue()
68  {
69  return $this->value;
70  }
71 
77  function setChecked($a_checked)
78  {
79  $this->checked = $a_checked;
80  }
81 
87  function getChecked()
88  {
89  return $this->checked;
90  }
91 
97  function setOptionTitle($a_optiontitle)
98  {
99  $this->optiontitle = $a_optiontitle;
100  }
101 
107  function getOptionTitle()
108  {
109  return $this->optiontitle;
110  }
111 
117  function setValueByArray($a_values)
118  {
119  $this->setChecked($a_values[$this->getPostVar()]);
120  foreach($this->getSubItems() as $item)
121  {
122  $item->setValueByArray($a_values);
123  }
124  }
125 
131  function setAdditionalAttributes($a_attrs)
132  {
133  $this->additional_attributes = $a_attrs;
134  }
135 
141  {
143  }
144 
150  function checkInput()
151  {
152  global $lng;
153 
154  $_POST[$this->getPostVar()] =
156 
157  $ok = $this->checkSubItemsInput();
158 
159  // only not ok, if checkbox not checked
160  if (!$ok && $_POST[$this->getPostVar()] == "")
161  {
162  $ok = true;
163  }
164 
165  return $ok;
166  }
167 
172  public function hideSubForm()
173  {
174  return !$this->getChecked();
175  }
176 
180  function render($a_mode = '')
181  {
182  $tpl = new ilTemplate("tpl.prop_checkbox.html", true, true, "Services/Form");
183 
184  $tpl->setVariable("POST_VAR", $this->getPostVar());
185  $tpl->setVariable("ID", $this->getFieldId());
186  $tpl->setVariable("PROPERTY_VALUE", $this->getValue());
187  $tpl->setVariable("OPTION_TITLE", $this->getOptionTitle());
188  if(strlen($this->getAdditionalAttributes()))
189  {
190  $tpl->setVariable('PROP_CHECK_ATTRS',$this->getAdditionalAttributes());
191  }
192  if ($this->getChecked())
193  {
194  $tpl->setVariable("PROPERTY_CHECKED",
195  'checked="checked"');
196  }
197  if ($this->getDisabled())
198  {
199  $tpl->setVariable("DISABLED",
200  'disabled="disabled"');
201  }
202 
203  if ($a_mode == "toolbar")
204  {
205  // block-inline hack, see: http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/
206  // -moz-inline-stack for FF2
207  // zoom 1; *display:inline for IE6 & 7
208  $tpl->setVariable("STYLE_PAR", 'display: -moz-inline-stack; display:inline-block; zoom: 1; *display:inline;');
209  }
210 
211  return $tpl->get();
212  }
213 
219  function insert(&$a_tpl)
220  {
221  $html = $this->render();
222 
223  $a_tpl->setCurrentBlock("prop_generic");
224  $a_tpl->setVariable("PROP_GENERIC", $html);
225  $a_tpl->parseCurrentBlock();
226  }
227 
232  {
233  $html = $this->render();
234  return $html;
235  }
236 
240  function serializeData()
241  {
242  return serialize($this->getChecked());
243  }
244 
248  function unserializeData($a_data)
249  {
250  $data = unserialize($a_data);
251 
252  if ($data)
253  {
254  $this->setValue($data);
255  $this->setChecked(true);
256  }
257  }
258 
262  function getToolbarHTML()
263  {
264  $html = $this->render('toolbar');
265  return $html;
266  }
267 }