ILIAS  Release_4_0_x_branch Revision 61816
 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 
32 {
33  protected $value = "1";
34  protected $checked;
35  protected $optiontitle = "";
36  protected $additional_attributes = '';
37 
44  function __construct($a_title = "", $a_postvar = "")
45  {
46  parent::__construct($a_title, $a_postvar);
47  $this->setType("checkbox");
48  }
49 
55  function setValue($a_value)
56  {
57  $this->value = $a_value;
58  }
59 
65  function getValue()
66  {
67  return $this->value;
68  }
69 
75  function setChecked($a_checked)
76  {
77  $this->checked = $a_checked;
78  }
79 
85  function getChecked()
86  {
87  return $this->checked;
88  }
89 
95  function setOptionTitle($a_optiontitle)
96  {
97  $this->optiontitle = $a_optiontitle;
98  }
99 
105  function getOptionTitle()
106  {
107  return $this->optiontitle;
108  }
109 
115  function setValueByArray($a_values)
116  {
117  $this->setChecked($a_values[$this->getPostVar()]);
118  foreach($this->getSubItems() as $item)
119  {
120  $item->setValueByArray($a_values);
121  }
122  }
123 
129  function setAdditionalAttributes($a_attrs)
130  {
131  $this->additional_attributes = $a_attrs;
132  }
133 
139  {
141  }
142 
148  function checkInput()
149  {
150  global $lng;
151 
152  $_POST[$this->getPostVar()] =
154 
155  $ok = $this->checkSubItemsInput();
156  return $ok;
157  }
158 
163  public function hideSubForm()
164  {
165  return !$this->getChecked();
166  }
167 
171  function render()
172  {
173  $tpl = new ilTemplate("tpl.prop_checkbox.html", true, true, "Services/Form");
174 
175  $tpl->setVariable("POST_VAR", $this->getPostVar());
176  $tpl->setVariable("ID", $this->getFieldId());
177  $tpl->setVariable("PROPERTY_VALUE", $this->getValue());
178  $tpl->setVariable("OPTION_TITLE", $this->getOptionTitle());
179  if(strlen($this->getAdditionalAttributes()))
180  {
181  $tpl->setVariable('PROP_CHECK_ATTRS',$this->getAdditionalAttributes());
182  }
183  if ($this->getChecked())
184  {
185  $tpl->setVariable("PROPERTY_CHECKED",
186  'checked="checked"');
187  }
188  if ($this->getDisabled())
189  {
190  $tpl->setVariable("DISABLED",
191  'disabled="disabled"');
192  }
193  return $tpl->get();
194  }
195 
201  function insert(&$a_tpl)
202  {
203  $html = $this->render();
204 
205  $a_tpl->setCurrentBlock("prop_generic");
206  $a_tpl->setVariable("PROP_GENERIC", $html);
207  $a_tpl->parseCurrentBlock();
208  }
209 
214  {
215  $html = $this->render();
216  return $html;
217  }
218 
222  function serializeData()
223  {
224  return serialize($this->getChecked());
225  }
226 
230  function unserializeData($a_data)
231  {
232  $data = unserialize($a_data);
233 
234  if ($data)
235  {
236  $this->setValue($data);
237  $this->setChecked(true);
238  }
239  }
240 
241 }