ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilErrorTextWizardInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
13 protected $values = array();
14 protected $key_size = 20;
15 protected $value_size = 20;
16 protected $key_maxlength = 255;
17 protected $value_maxlength = 255;
18 protected $key_name = "";
19 protected $value_name = "";
20
27 public function __construct($a_title = "", $a_postvar = "")
28 {
29 parent::__construct($a_title, $a_postvar);
30 }
31
37 public function setValue($a_value)
38 {
39 $this->values = array();
40 if (is_array($a_value)) {
41 include_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
42 if (is_array($a_value['key'])) {
43 foreach ($a_value['key'] as $idx => $key) {
44 array_push($this->values, new assAnswerErrorText($key, $a_value['value'][$idx], str_replace(",", ".", $a_value['points'][$idx])));
45 }
46 }
47 }
48 }
49
55 public function setKeySize($a_size)
56 {
57 $this->key_size = $a_size;
58 }
59
65 public function getKeySize()
66 {
67 return $this->key_size;
68 }
69
75 public function setValueSize($a_size)
76 {
77 $this->value_size = $a_size;
78 }
79
85 public function getValueSize()
86 {
87 return $this->value_size;
88 }
89
95 public function setKeyMaxlength($a_maxlength)
96 {
97 $this->key_maxlength = $a_maxlength;
98 }
99
105 public function getKeyMaxlength()
106 {
108 }
109
115 public function setValueMaxlength($a_maxlength)
116 {
117 $this->value_maxlength = $a_maxlength;
118 }
119
125 public function getValueMaxlength()
126 {
128 }
129
135 public function setValueName($a_name)
136 {
137 $this->value_name = $a_name;
138 }
139
145 public function getValueName()
146 {
147 return $this->value_name;
148 }
149
155 public function setKeyName($a_name)
156 {
157 $this->key_name = $a_name;
158 }
159
165 public function getKeyName()
166 {
167 return $this->key_name;
168 }
169
175 public function setValues($a_values)
176 {
177 $this->values = $a_values;
178 }
179
185 public function getValues()
186 {
187 return $this->values;
188 }
189
195 public function checkInput()
196 {
197 global $lng;
198
199 if (is_array($_POST[$this->getPostVar()])) {
201 }
202 $foundvalues = $_POST[$this->getPostVar()];
203 $max_points = 0;
204
205 if (is_array($foundvalues)) {
206 // check answers
207 if (is_array($foundvalues['key']) && is_array($foundvalues['value'])) {
208 foreach ($foundvalues['key'] as $val) {
209 if ($this->getRequired() && (strlen($val)) == 0) {
210 $this->setAlert($lng->txt("msg_input_is_required"));
211 return false;
212 }
213 }
214 foreach ($foundvalues['value'] as $val) {
215 if ($this->getRequired() && (strlen($val)) == 0) {
216 $this->setAlert($lng->txt("msg_input_is_required"));
217 return false;
218 }
219 }
220 foreach ($foundvalues['points'] as $val) {
221 if ($this->getRequired() && (strlen($val)) == 0) {
222 $this->setAlert($lng->txt("msg_input_is_required"));
223 return false;
224 }
225 if (!is_numeric(str_replace(",", ".", $val))) {
226 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
227 return false;
228 }
229 if ((float) $val <= 0) {
230 $this->setAlert($lng->txt("positive_numbers_required"));
231 return false;
232 }
233 }
234 } else {
235 if ($this->getRequired()) {
236 $this->setAlert($lng->txt("msg_input_is_required"));
237 return false;
238 }
239 }
240 } else {
241 if ($this->getRequired()) {
242 $this->setAlert($lng->txt("msg_input_is_required"));
243 return false;
244 }
245 }
246
247 return $this->checkSubItemsInput();
248 }
249
255 public function insert($a_tpl)
256 {
257 global $lng;
258
259 $tpl = new ilTemplate("tpl.prop_errortextwizardinput.html", true, true, "Modules/TestQuestionPool");
260 $i = 0;
261 foreach ($this->values as $value) {
262 if (is_object($value)) {
263 if (strlen($value->text_wrong)) {
264 $tpl->setCurrentBlock("prop_key_propval");
265 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_wrong));
266 $tpl->parseCurrentBlock();
267 }
268 if (strlen($value->text_correct)) {
269 $tpl->setCurrentBlock("prop_value_propval");
270 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_correct));
271 $tpl->parseCurrentBlock();
272 }
273 if (strlen($value->points)) {
274 $tpl->setCurrentBlock("prop_points_propval");
275 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->points));
276 $tpl->parseCurrentBlock();
277 }
278 }
279
280 $tpl->setCurrentBlock("row");
281 $class = ($i % 2 == 0) ? "even" : "odd";
282 if ($i == 0) {
283 $class .= " first";
284 }
285 if ($i == count($this->values)-1) {
286 $class .= " last";
287 }
288 $tpl->setVariable("ROW_CLASS", $class);
289 $tpl->setVariable("ROW_NUMBER", $i);
290
291 $tpl->setVariable("KEY_SIZE", $this->getKeySize());
292 $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
293 $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
294
295 $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
296 $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
297 $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
298
299 $tpl->setVariable("POST_VAR", $this->getPostVar());
300
301 $tpl->parseCurrentBlock();
302
303 $i++;
304 }
305 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
306 $tpl->setVariable("KEY_TEXT", $this->getKeyName());
307 $tpl->setVariable("VALUE_TEXT", $this->getValueName());
308 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
309
310 $a_tpl->setCurrentBlock("prop_generic");
311 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
312 $a_tpl->parseCurrentBlock();
313 }
314}
$tpl
Definition: ilias.php:10
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Class for error text answers.
This class represents a key value pair wizard property in a property form.
checkInput()
Check input, strip slashes etc.
setValueMaxlength($a_maxlength)
Set value maxlength.
setKeyMaxlength($a_maxlength)
Set key maxlength.
__construct($a_title="", $a_postvar="")
Constructor.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$key
Definition: croninfo.php:18
$i
Definition: disco.tpl.php:19