ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRadioGroupInputGUI.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.ilRadioOption.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("radio");
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  $_POST[$this->getPostVar()] =
118  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
119  {
120  $this->setAlert($lng->txt("msg_input_is_required"));
121 
122  return false;
123  }
124 
125  $ok = true;
126  foreach($this->getOptions() as $option)
127  {
128  foreach($option->getSubItems() as $item)
129  {
130  $item_ok = $item->checkInput();
131  if (!$item_ok && ($_POST[$this->getPostVar()] == $option->getValue()))
132  {
133  $ok = false;
134  }
135  }
136  }
137  return $ok;
138  }
139 
145  function insert(&$a_tpl)
146  {
147  $html = $this->render();
148 
149  $a_tpl->setCurrentBlock("prop_generic");
150  $a_tpl->setVariable("PROP_GENERIC", $html);
151  $a_tpl->parseCurrentBlock();
152  }
153 
157  function render()
158  {
159  $tpl = new ilTemplate("tpl.prop_radio.html", true, true, "Services/Form");
160 
161  foreach($this->getOptions() as $option)
162  {
163  // information text for option
164  if ($option->getInfo() != "")
165  {
166  $tpl->setCurrentBlock("radio_option_desc");
167  $tpl->setVariable("RADIO_OPTION_DESC", $option->getInfo());
168  $tpl->parseCurrentBlock();
169  }
170 
171 
172  if (count($option->getSubItems()) > 0)
173  {
174  if ($option->getValue() != $this->getValue())
175  {
176  $tpl->touchBlock("prop_radio_opt_hide");
177  $tpl->setVariable("HOP_ID", $this->getFieldId()."_".$option->getValue());
178  $tpl->parseCurrentBlock();
179  }
180  $tpl->setCurrentBlock("radio_option_subform");
181  $pf = new ilPropertyFormGUI();
182  $pf->setMode("subform");
183  $pf->setItems($option->getSubItems());
184  $tpl->setVariable("SUB_FORM", $pf->getContent());
185  $tpl->setVariable("SOP_ID", $this->getFieldId()."_".$option->getValue());
186  if ($pf->getMultipart())
187  {
188  $this->getParentForm()->setMultipart(true);
189  }
190  $tpl->parseCurrentBlock();
191  if ($pf->getMultipart())
192  {
193  $this->getParentForm()->setMultipart(true);
194  }
195  }
196 
197  $tpl->setCurrentBlock("prop_radio_option");
198  if (!$this->getDisabled())
199  {
200  $tpl->setVariable("POST_VAR", $this->getPostVar());
201  }
202  $tpl->setVariable("VAL_RADIO_OPTION", $option->getValue());
203  $tpl->setVariable("OP_ID", $this->getFieldId()."_".$option->getValue());
204  $tpl->setVariable("FID", $this->getFieldId());
205  if($this->getDisabled() or $option->getDisabled())
206  {
207  $tpl->setVariable('DISABLED','disabled="disabled" ');
208  }
209  if ($option->getValue() == $this->getValue())
210  {
211  $tpl->setVariable("CHK_RADIO_OPTION",
212  'checked="checked"');
213  }
214  $tpl->setVariable("TXT_RADIO_OPTION", $option->getTitle());
215 
216 
217  $tpl->parseCurrentBlock();
218  }
219  $tpl->setVariable("ID", $this->getFieldId());
220 
221  if ($this->getDisabled())
222  {
223  $tpl->setVariable("HIDDEN_INPUT",
224  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
225  }
226 
227  return $tpl->get();
228  }
229 
235  function getItemByPostVar($a_post_var)
236  {
237  if ($this->getPostVar() == $a_post_var)
238  {
239  return $this;
240  }
241 
242  foreach($this->getOptions() as $option)
243  {
244  foreach($option->getSubItems() as $item)
245  {
246  if ($item->getType() != "section_header")
247  {
248  $ret = $item->getItemByPostVar($a_post_var);
249  if (is_object($ret))
250  {
251  return $ret;
252  }
253  }
254  }
255  }
256 
257  return false;
258  }
259 
261  {
262  return $this->render();
263  }
264 }