ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public function __construct($a_title = "", $a_postvar = "")
45  {
46  global $DIC;
47 
48  $this->lng = $DIC->language();
49  parent::__construct($a_title, $a_postvar);
50  $this->setType("radio");
51  }
52 
58  public function addOption($a_option)
59  {
60  $this->options[] = $a_option;
61  }
62 
68  public function getOptions()
69  {
70  return $this->options;
71  }
72 
78  public function setValue($a_value)
79  {
80  $this->value = $a_value;
81  }
82 
88  public function getValue()
89  {
90  return $this->value;
91  }
92 
98  public function setValueByArray($a_values)
99  {
100  $this->setValue($a_values[$this->getPostVar()]);
101  foreach ($this->getOptions() as $option) {
102  foreach ($option->getSubItems() as $item) {
103  $item->setValueByArray($a_values);
104  }
105  }
106  }
107 
113  public function checkInput()
114  {
115  $lng = $this->lng;
116 
117  $_POST[$this->getPostVar()] =
119  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") {
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  foreach ($option->getSubItems() as $item) {
128  if ($_POST[$this->getPostVar()] == $option->getValue()) {
129  if (!$item->checkInput()) {
130  $ok = false;
131  }
132  }
133  }
134  }
135  return $ok;
136  }
137 
143  public function insert($a_tpl)
144  {
145  $html = $this->render();
146 
147  $a_tpl->setCurrentBlock("prop_generic");
148  $a_tpl->setVariable("PROP_GENERIC", $html);
149  $a_tpl->parseCurrentBlock();
150  }
151 
155  public function render()
156  {
157  $tpl = new ilTemplate("tpl.prop_radio.html", true, true, "Services/Form");
158 
159  foreach ($this->getOptions() as $option) {
160  // information text for option
161  if ($option->getInfo() != "") {
162  $tpl->setCurrentBlock("radio_option_desc");
163  $tpl->setVariable("RADIO_OPTION_DESC", $option->getInfo());
164  $tpl->parseCurrentBlock();
165  }
166 
167 
168  if (count($option->getSubItems()) > 0) {
169  if ($option->getValue() != $this->getValue()) {
170  // #10930
171  $tpl->setCurrentBlock("prop_radio_opt_hide");
172  $tpl->setVariable("HOP_ID", $this->getFieldId() . "_" . $option->getValue());
173  $tpl->parseCurrentBlock();
174  }
175  $tpl->setCurrentBlock("radio_option_subform");
176  $pf = new ilPropertyFormGUI();
177  $pf->setMode("subform");
178  $pf->setItems($option->getSubItems());
179  $tpl->setVariable("SUB_FORM", $pf->getContent());
180  $tpl->setVariable("SOP_ID", $this->getFieldId() . "_" . $option->getValue());
181  if ($pf->getMultipart()) {
182  $this->getParentForm()->setMultipart(true);
183  }
184  $tpl->parseCurrentBlock();
185  if ($pf->getMultipart()) {
186  $this->getParentForm()->setMultipart(true);
187  }
188  }
189 
190  $tpl->setCurrentBlock("prop_radio_option");
191  if (!$this->getDisabled()) {
192  $tpl->setVariable("POST_VAR", $this->getPostVar());
193  }
194  $tpl->setVariable("VAL_RADIO_OPTION", $option->getValue());
195  $tpl->setVariable("OP_ID", $this->getFieldId() . "_" . $option->getValue());
196  $tpl->setVariable("FID", $this->getFieldId());
197  if ($this->getDisabled() or $option->getDisabled()) {
198  $tpl->setVariable('DISABLED', 'disabled="disabled" ');
199  }
200  if ($option->getValue() == $this->getValue()) {
201  $tpl->setVariable(
202  "CHK_RADIO_OPTION",
203  'checked="checked"'
204  );
205  }
206  $tpl->setVariable("TXT_RADIO_OPTION", $option->getTitle());
207 
208 
209  $tpl->parseCurrentBlock();
210  }
211  $tpl->setVariable("ID", $this->getFieldId());
212 
213  if ($this->getDisabled()) {
214  $tpl->setVariable(
215  "HIDDEN_INPUT",
216  $this->getHiddenTag($this->getPostVar(), $this->getValue())
217  );
218  }
219 
220  return $tpl->get();
221  }
222 
228  public function getItemByPostVar($a_post_var)
229  {
230  if ($this->getPostVar() == $a_post_var) {
231  return $this;
232  }
233 
234  foreach ($this->getOptions() as $option) {
235  foreach ($option->getSubItems() as $item) {
236  if ($item->getType() != "section_header") {
237  $ret = $item->getItemByPostVar($a_post_var);
238  if (is_object($ret)) {
239  return $ret;
240  }
241  }
242  }
243  }
244 
245  return false;
246  }
247 
248  public function getTableFilterHTML()
249  {
250  return $this->render();
251  }
252 
258  public function getSubInputItemsRecursive()
259  {
260  $subInputItems = parent::getSubInputItemsRecursive();
261  foreach ($this->getOptions() as $option) {
265  $subInputItems = array_merge($subInputItems, $option->getSubInputItemsRecursive());
266  }
267 
268  return $subInputItems;
269  }
270 }
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.
global $DIC
Definition: saml.php:7
$tpl
Definition: ilias.php:10
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.
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.
$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