ILIAS  Release_3_10_x_branch Revision 61812
 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()] =
117  ilUtil::stripSlashes($_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  foreach($this->getOptions() as $option)
149  {
150  // information text for option
151  if ($option->getInfo() != "")
152  {
153  $a_tpl->setCurrentBlock("radio_option_desc");
154  $a_tpl->setVariable("RADIO_OPTION_DESC", $option->getInfo());
155  $a_tpl->parseCurrentBlock();
156  }
157 
158  $a_tpl->setCurrentBlock("prop_radio_option");
159  $a_tpl->setVariable("POST_VAR", $this->getPostVar());
160  $a_tpl->setVariable("VAL_RADIO_OPTION", $option->getValue());
161  $a_tpl->setVariable("OP_ID", $this->getFieldId()."_".$option->getValue());
162  if($this->getDisabled())
163  {
164  $a_tpl->setVariable('DISABLED','disabled="disabled" ');
165  }
166  if ($option->getValue() == $this->getValue())
167  {
168  $a_tpl->setVariable("CHK_RADIO_OPTION",
169  'checked="checked"');
170  }
171  $a_tpl->setVariable("TXT_RADIO_OPTION", $option->getTitle());
172 
173  if (count($option->getSubItems()) > 0)
174  {
175  $pf = new ilPropertyFormGUI();
176  $pf->setMode("subform");
177  $pf->setItems($option->getSubItems());
178  $a_tpl->setVariable("SUB_FORM", $pf->getContent());
179  }
180 
181  $a_tpl->parseCurrentBlock();
182  }
183  $a_tpl->setCurrentBlock("prop_radio");
184  $a_tpl->parseCurrentBlock();
185 
186  }
187 
188 }