ILIAS  Release_4_0_x_branch Revision 61816
 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  }
140 
146  function insert(&$a_tpl)
147  {
148  $tpl = new ilTemplate("tpl.prop_radio.html", true, true, "Services/Form");
149 
150  foreach($this->getOptions() as $option)
151  {
152  // information text for option
153  if ($option->getInfo() != "")
154  {
155  $tpl->setCurrentBlock("radio_option_desc");
156  $tpl->setVariable("RADIO_OPTION_DESC", $option->getInfo());
157  $tpl->parseCurrentBlock();
158  }
159 
160 
161  if (count($option->getSubItems()) > 0)
162  {
163  if ($option->getValue() != $this->getValue())
164  {
165  $tpl->touchBlock("prop_radio_opt_hide");
166  $tpl->setVariable("HOP_ID", $this->getFieldId()."_".$option->getValue());
167  $tpl->parseCurrentBlock();
168  }
169  $tpl->setCurrentBlock("radio_option_subform");
170  $pf = new ilPropertyFormGUI();
171  $pf->setMode("subform");
172  $pf->setItems($option->getSubItems());
173  $tpl->setVariable("SUB_FORM", $pf->getContent());
174  $tpl->setVariable("SOP_ID", $this->getFieldId()."_".$option->getValue());
175  if ($pf->getMultipart())
176  {
177  $this->getParentForm()->setMultipart(true);
178  }
179  $tpl->parseCurrentBlock();
180  if ($pf->getMultipart())
181  {
182  $this->getParentForm()->setMultipart(true);
183  }
184  }
185 
186  $tpl->setCurrentBlock("prop_radio_option");
187  if (!$this->getDisabled())
188  {
189  $tpl->setVariable("POST_VAR", $this->getPostVar());
190  }
191  $tpl->setVariable("VAL_RADIO_OPTION", $option->getValue());
192  $tpl->setVariable("OP_ID", $this->getFieldId()."_".$option->getValue());
193  $tpl->setVariable("FID", $this->getFieldId());
194  if($this->getDisabled() or $option->getDisabled())
195  {
196  $tpl->setVariable('DISABLED','disabled="disabled" ');
197  }
198  if ($option->getValue() == $this->getValue())
199  {
200  $tpl->setVariable("CHK_RADIO_OPTION",
201  'checked="checked"');
202  }
203  $tpl->setVariable("TXT_RADIO_OPTION", $option->getTitle());
204 
205 
206  $tpl->parseCurrentBlock();
207  }
208  $tpl->setVariable("ID", $this->getFieldId());
209 
210  if ($this->getDisabled())
211  {
212  $tpl->setVariable("HIDDEN_INPUT",
213  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
214  }
215 
216  $a_tpl->setCurrentBlock("prop_generic");
217  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
218  $a_tpl->parseCurrentBlock();
219 
220  }
221 
227  function getItemByPostVar($a_post_var)
228  {
229  if ($this->getPostVar() == $a_post_var)
230  {
231  return $this;
232  }
233 
234  foreach($this->getOptions() as $option)
235  {
236  foreach($option->getSubItems() as $item)
237  {
238  if ($item->getType() != "section_header")
239  {
240  $ret = $item->getItemByPostVar($a_post_var);
241  if (is_object($ret))
242  {
243  return $ret;
244  }
245  }
246  }
247  }
248 
249  return false;
250  }
251 
252 }