ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilSelectInputGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
6include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
7include_once 'Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php';
8include_once 'Services/Form/interfaces/interface.ilMultiValuesItem.php';
9
18{
19 protected $cust_attr = array();
20 protected $options = array();
21 protected $value;
22
29 public function __construct($a_title = "", $a_postvar = "")
30 {
31 global $DIC;
32
33 $this->lng = $DIC->language();
34 parent::__construct($a_title, $a_postvar);
35 $this->setType("select");
36 }
37
43 public function setOptions($a_options)
44 {
45 $this->options = $a_options;
46 }
47
53 public function getOptions()
54 {
55 return $this->options ? $this->options : array();
56 }
57
63 public function setValue($a_value)
64 {
65 if ($this->getMulti() && is_array($a_value)) {
66 $this->setMultiValues($a_value);
67 $a_value = array_shift($a_value);
68 }
69 $this->value = $a_value;
70 }
71
77 public function getValue()
78 {
79 return $this->value;
80 }
81
82
88 public function setValueByArray($a_values)
89 {
90 $this->setValue($a_values[$this->getPostVar()]);
91 foreach ($this->getSubItems() as $item) {
92 $item->setValueByArray($a_values);
93 }
94 }
95
101 public function checkInput()
102 {
104
105 $valid = true;
106 if (!$this->getMulti()) {
108 if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") {
109 $valid = false;
110 } elseif (!array_key_exists($_POST[$this->getPostVar()], (array) $this->getOptions())) {
111 $this->setAlert($lng->txt('msg_invalid_post_input'));
112 return false;
113 }
114 } else {
115 foreach ($_POST[$this->getPostVar()] as $idx => $value) {
116 $_POST[$this->getPostVar()][$idx] = ilUtil::stripSlashes($value);
117 if (!array_key_exists($value, (array) $this->getOptions())) {
118 $this->setAlert($lng->txt('msg_invalid_post_input'));
119 return false;
120 }
121 }
122 $_POST[$this->getPostVar()] = array_unique($_POST[$this->getPostVar()]);
123
124 if ($this->getRequired() && !trim(implode("", $_POST[$this->getPostVar()]))) {
125 $valid = false;
126 }
127 }
128 if (!$valid) {
129 $this->setAlert($lng->txt("msg_input_is_required"));
130 return false;
131 }
132 return $this->checkSubItemsInput();
133 }
134
135 public function addCustomAttribute($a_attr)
136 {
137 $this->cust_attr[] = $a_attr;
138 }
139
140 public function getCustomAttributes()
141 {
142 return (array) $this->cust_attr;
143 }
144
148 public function render($a_mode = "")
149 {
150 $tpl = new ilTemplate("tpl.prop_select.html", true, true, "Services/Form");
151
152 foreach ($this->getCustomAttributes() as $attr) {
153 $tpl->setCurrentBlock('cust_attr');
154 $tpl->setVariable('CUSTOM_ATTR', $attr);
155 $tpl->parseCurrentBlock();
156 }
157
158 // determin value to select. Due to accessibility reasons we
159 // should always select a value (per default the first one)
160 $first = true;
161 foreach ($this->getOptions() as $option_value => $option_text) {
162 if ($first) {
163 $sel_value = $option_value;
164 }
165 $first = false;
166 if ((string) $option_value == (string) $this->getValue()) {
167 $sel_value = $option_value;
168 }
169 }
170 foreach ($this->getOptions() as $option_value => $option_text) {
171 $tpl->setCurrentBlock("prop_select_option");
172 $tpl->setVariable("VAL_SELECT_OPTION", ilUtil::prepareFormOutput($option_value));
173 if ((string) $sel_value == (string) $option_value) {
174 $tpl->setVariable(
175 "CHK_SEL_OPTION",
176 'selected="selected"'
177 );
178 }
179 $tpl->setVariable("TXT_SELECT_OPTION", $option_text);
180 $tpl->parseCurrentBlock();
181 }
182 $tpl->setVariable("ID", $this->getFieldId());
183
184 $postvar = $this->getPostVar();
185 if ($this->getMulti() && substr($postvar, -2) != "[]") {
186 $postvar .= "[]";
187 }
188
189 $tpl->setVariable("POST_VAR", $postvar);
190 if ($this->getDisabled()) {
191 if ($this->getMulti()) {
192 $value = $this->getMultiValues();
193 $hidden = "";
194 if (is_array($value)) {
195 foreach ($value as $item) {
196 $hidden .= $this->getHiddenTag($postvar, $item);
197 }
198 }
199 } else {
200 $hidden = $this->getHiddenTag($postvar, $this->getValue());
201 }
202 if ($hidden) {
203 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
204 $tpl->setVariable("HIDDEN_INPUT", $hidden);
205 }
206 }
207
208 // multi icons
209 if ($this->getMulti() && !$a_mode && !$this->getDisabled()) {
210 $tpl->touchBlock("inline_in_bl");
211 $tpl->setVariable("MULTI_ICONS", $this->getMultiIconsHTML());
212 }
213
214 $tpl->setVariable("ARIA_LABEL", ilUtil::prepareFormOutput($this->getTitle()));
215
216 return $tpl->get();
217 }
218
224 public function insert($a_tpl)
225 {
226 $a_tpl->setCurrentBlock("prop_generic");
227 $a_tpl->setVariable("PROP_GENERIC", $this->render());
228 $a_tpl->parseCurrentBlock();
229 }
230
234 public function getTableFilterHTML()
235 {
236 $html = $this->render();
237 return $html;
238 }
239
243 public function getToolbarHTML()
244 {
245 $html = $this->render("toolbar");
246 return $html;
247 }
248
256 public function setHideSubForm($a_value, $a_condition = null)
257 {
258 $this->hide_sub = (bool) $a_value;
259
260 if ($a_condition) {
261 $this->addCustomAttribute('onchange="if(this.value ' . $a_condition . ')' .
262 ' { il.Form.showSubForm(\'subform_' . $this->getFieldId() . '\', \'il_prop_cont_' . $this->getFieldId() . '\'); }' .
263 ' else { il.Form.hideSubForm(\'subform_' . $this->getFieldId() . '\'); };"');
264 }
265 }
266
267 public function hideSubForm()
268 {
269 return (bool) $this->hide_sub;
270 }
271}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
getMultiIconsHTML()
Get HTML for multiple value icons.
setType($a_type)
Set Type.
getPostVar()
Get Post Variable.
getHiddenTag($a_post_var, $a_value)
Get hidden tag (used for disabled properties)
setAlert($a_alert)
Set Alert Text.
getMultiValues()
Get multi values.
setMultiValues(array $a_values)
Set multi values.
getFieldId()
Get Post Variable.
This class represents a selection list property in a property form.
__construct($a_title="", $a_postvar="")
Constructor.
setValue($a_value)
Set Value.
setOptions($a_options)
Set Options.
getTableFilterHTML()
Get HTML for table filter.
checkInput()
Check input, strip slashes etc.
render($a_mode="")
Render item.
setValueByArray($a_values)
Set value by array.
insert($a_tpl)
Insert property html.
setHideSubForm($a_value, $a_condition=null)
Set initial sub form visibility, optionally add dynamic value-based condition.
getToolbarHTML()
Get HTML for toolbar.
This class represents a property that may include a sub form.
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
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$valid
global $DIC
Definition: goto.php:24
Interface for multi values support.
Interface for property form input GUI classes that can be used in table filters.
Interface for property form input GUI classes that can be used in ilToolbarGUI.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc