ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $DIC;
198 $lng = $DIC['lng'];
199
200 if (is_array($_POST[$this->getPostVar()])) {
202 }
203 $foundvalues = $_POST[$this->getPostVar()];
204 $max_points = 0;
205
206 if (is_array($foundvalues)) {
207 // check answers
208 if (is_array($foundvalues['key']) && is_array($foundvalues['value'])) {
209 foreach ($foundvalues['key'] as $val) {
210 if ($this->getRequired() && (strlen($val)) == 0) {
211 $this->setAlert($lng->txt("msg_input_is_required"));
212 return false;
213 }
214 }
215 foreach ($foundvalues['value'] as $val) {
216 if ($this->getRequired() && (strlen($val)) == 0) {
217 $this->setAlert($lng->txt("msg_input_is_required"));
218 return false;
219 }
220 }
221 foreach ($foundvalues['points'] as $val) {
222 if ($this->getRequired() && (strlen($val)) == 0) {
223 $this->setAlert($lng->txt("msg_input_is_required"));
224 return false;
225 }
226 if (!is_numeric(str_replace(",", ".", $val))) {
227 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
228 return false;
229 }
230 if ((float) $val <= 0) {
231 $this->setAlert($lng->txt("positive_numbers_required"));
232 return false;
233 }
234 }
235 } else {
236 if ($this->getRequired()) {
237 $this->setAlert($lng->txt("msg_input_is_required"));
238 return false;
239 }
240 }
241 } else {
242 if ($this->getRequired()) {
243 $this->setAlert($lng->txt("msg_input_is_required"));
244 return false;
245 }
246 }
247
248 return $this->checkSubItemsInput();
249 }
250
256 public function insert($a_tpl)
257 {
258 global $DIC;
259 $lng = $DIC['lng'];
260
261 $tpl = new ilTemplate("tpl.prop_errortextwizardinput.html", true, true, "Modules/TestQuestionPool");
262 $i = 0;
263 foreach ($this->values as $value) {
264 if (is_object($value)) {
265 if (strlen($value->text_wrong)) {
266 $tpl->setCurrentBlock("prop_key_propval");
267 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_wrong));
268 $tpl->parseCurrentBlock();
269 }
270 if (strlen($value->text_correct)) {
271 $tpl->setCurrentBlock("prop_value_propval");
272 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_correct));
273 $tpl->parseCurrentBlock();
274 }
275 if (strlen($value->points)) {
276 $tpl->setCurrentBlock("prop_points_propval");
277 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->points));
278 $tpl->parseCurrentBlock();
279 }
280 }
281
282 $tpl->setCurrentBlock("row");
283 $class = ($i % 2 == 0) ? "even" : "odd";
284 if ($i == 0) {
285 $class .= " first";
286 }
287 if ($i == count($this->values) - 1) {
288 $class .= " last";
289 }
290 $tpl->setVariable("ROW_CLASS", $class);
291 $tpl->setVariable("ROW_NUMBER", $i);
292
293 $tpl->setVariable("KEY_SIZE", $this->getKeySize());
294 $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
295 $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
296
297 $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
298 $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
299 $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
300
301 $tpl->setVariable("POST_VAR", $this->getPostVar());
302
303 $tpl->parseCurrentBlock();
304
305 $i++;
306 }
307 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
308 $tpl->setVariable("KEY_TEXT", $this->getKeyName());
309 $tpl->setVariable("VALUE_TEXT", $this->getValueName());
310 $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
311
312 $a_tpl->setCurrentBlock("prop_generic");
313 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
314 $a_tpl->parseCurrentBlock();
315 }
316}
$_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
$i
Definition: metadata.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$DIC
Definition: xapitoken.php:46