ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  // #10930
177  $tpl->setCurrentBlock("prop_radio_opt_hide");
178  $tpl->setVariable("HOP_ID", $this->getFieldId()."_".$option->getValue());
179  $tpl->parseCurrentBlock();
180  }
181  $tpl->setCurrentBlock("radio_option_subform");
182  $pf = new ilPropertyFormGUI();
183  $pf->setMode("subform");
184  $pf->setItems($option->getSubItems());
185  $tpl->setVariable("SUB_FORM", $pf->getContent());
186  $tpl->setVariable("SOP_ID", $this->getFieldId()."_".$option->getValue());
187  if ($pf->getMultipart())
188  {
189  $this->getParentForm()->setMultipart(true);
190  }
191  $tpl->parseCurrentBlock();
192  if ($pf->getMultipart())
193  {
194  $this->getParentForm()->setMultipart(true);
195  }
196  }
197 
198  $tpl->setCurrentBlock("prop_radio_option");
199  if (!$this->getDisabled())
200  {
201  $tpl->setVariable("POST_VAR", $this->getPostVar());
202  }
203  $tpl->setVariable("VAL_RADIO_OPTION", $option->getValue());
204  $tpl->setVariable("OP_ID", $this->getFieldId()."_".$option->getValue());
205  $tpl->setVariable("FID", $this->getFieldId());
206  if($this->getDisabled() or $option->getDisabled())
207  {
208  $tpl->setVariable('DISABLED','disabled="disabled" ');
209  }
210  if ($option->getValue() == $this->getValue())
211  {
212  $tpl->setVariable("CHK_RADIO_OPTION",
213  'checked="checked"');
214  }
215  $tpl->setVariable("TXT_RADIO_OPTION", $option->getTitle());
216 
217 
218  $tpl->parseCurrentBlock();
219  }
220  $tpl->setVariable("ID", $this->getFieldId());
221 
222  if ($this->getDisabled())
223  {
224  $tpl->setVariable("HIDDEN_INPUT",
225  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
226  }
227 
228  return $tpl->get();
229  }
230 
236  function getItemByPostVar($a_post_var)
237  {
238  if ($this->getPostVar() == $a_post_var)
239  {
240  return $this;
241  }
242 
243  foreach($this->getOptions() as $option)
244  {
245  foreach($option->getSubItems() as $item)
246  {
247  if ($item->getType() != "section_header")
248  {
249  $ret = $item->getItemByPostVar($a_post_var);
250  if (is_object($ret))
251  {
252  return $ret;
253  }
254  }
255  }
256  }
257 
258  return false;
259  }
260 
262  {
263  return $this->render();
264  }
265 
271  public function getSubInputItemsRecursive()
272  {
273  $subInputItems = parent::getSubInputItemsRecursive();
274  foreach($this->getOptions() as $option)
275  {
279  $subInputItems = array_merge( $subInputItems, $option->getSubInputItemsRecursive() );
280  }
281 
282  return $subInputItems;
283  }
284 }
getHiddenTag($a_post_var, $a_value)
Get hidden tag (used for disabled properties)
Interface for property form input GUI classes that can be used in table filters.
This class represents a property form user interface.
getPostVar()
Get Post Variable.
getParentForm()
Get Parent Form.
getSubInputItemsRecursive()
returns a flat array of possibly existing subitems recursively
__construct($a_title="", $a_postvar="")
Constructor.
setAlert($a_alert)
Set Alert Text.
global $tpl
Definition: ilias.php:8
setType($a_type)
Set Type.
render()
Insert property html.
This class represents a property in a property form.
addOption($a_option)
Add Option.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
getTableFilterHTML()
Get input item HTML to be inserted into table filters.
Create styles array
The data for the language used.
checkInput()
Check input, strip slashes etc.
setValueByArray($a_values)
Set value by array.
This class represents a property that may include a sub form.
global $lng
Definition: privfeed.php:17
$ret
Definition: parser.php:6
insert($a_tpl)
Insert property html.
getItemByPostVar($a_post_var)
Get item by post var.
$_POST["username"]
$html
Definition: example_001.php:87