Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once("./Services/Form/classes/class.ilRadioOption.php");
00025
00033 class ilRadioGroupInputGUI extends ilFormPropertyGUI
00034 {
00035 protected $options = array();
00036 protected $value;
00037
00044 function __construct($a_title = "", $a_postvar = "")
00045 {
00046 parent::__construct($a_title, $a_postvar);
00047 $this->setType("radio");
00048 }
00049
00055 function addOption($a_option)
00056 {
00057 $this->options[] = $a_option;
00058 }
00059
00065 function getOptions()
00066 {
00067 return $this->options;
00068 }
00069
00075 function setValue($a_value)
00076 {
00077 $this->value = $a_value;
00078 }
00079
00085 function getValue()
00086 {
00087 return $this->value;
00088 }
00089
00095 function setValueByArray($a_values)
00096 {
00097 $this->setValue($a_values[$this->getPostVar()]);
00098 }
00099
00105 function checkInput()
00106 {
00107 global $lng;
00108
00109 $_POST[$this->getPostVar()] =
00110 ilUtil::stripSlashes($_POST[$this->getPostVar()]);
00111 if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
00112 {
00113 $this->setAlert($lng->txt("msg_input_is_required"));
00114
00115 return false;
00116 }
00117
00118 $ok = true;
00119 foreach($this->getOptions() as $option)
00120 {
00121 foreach($option->getSubItems() as $item)
00122 {
00123 $item_ok = $item->checkInput();
00124 if (!$item_ok && ($_POST[$this->getPostVar()] == $option->getValue()))
00125 {
00126 $ok = false;
00127 }
00128 }
00129 }
00130 return $ok;
00131
00132 }
00133
00139 function insert(&$a_tpl)
00140 {
00141 foreach($this->getOptions() as $option)
00142 {
00143
00144 if ($option->getInfo() != "")
00145 {
00146 $a_tpl->setCurrentBlock("radio_option_desc");
00147 $a_tpl->setVariable("RADIO_OPTION_DESC", $option->getInfo());
00148 $a_tpl->parseCurrentBlock();
00149 }
00150
00151 $a_tpl->setCurrentBlock("prop_radio_option");
00152 $a_tpl->setVariable("POST_VAR", $this->getPostVar());
00153 $a_tpl->setVariable("VAL_RADIO_OPTION", $option->getValue());
00154 $a_tpl->setVariable("OP_ID", $this->getFieldId()."_".$option->getValue());
00155 if($this->getDisabled())
00156 {
00157 $a_tpl->setVariable('DISABLED','disabled="disabled" ');
00158 }
00159 if ($option->getValue() == $this->getValue())
00160 {
00161 $a_tpl->setVariable("CHK_RADIO_OPTION",
00162 'checked="checked"');
00163 }
00164 $a_tpl->setVariable("TXT_RADIO_OPTION", $option->getTitle());
00165
00166 if (count($option->getSubItems()) > 0)
00167 {
00168 $pf = new ilPropertyFormGUI();
00169 $pf->setMode("subform");
00170 $pf->setItems($option->getSubItems());
00171 $a_tpl->setVariable("SUB_FORM", $pf->getContent());
00172 }
00173
00174 $a_tpl->parseCurrentBlock();
00175 }
00176 $a_tpl->setCurrentBlock("prop_radio");
00177 $a_tpl->parseCurrentBlock();
00178
00179 }
00180
00181 }