ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAnswerWizardInputGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
5
14{
15 protected $values = array();
16 protected $allowMove = false;
17 protected $allowAddRemove = true;
18 protected $singleline = true;
19 protected $qstObject = null;
20 protected $minvalue = false;
21 protected $minvalueShouldBeGreater = false;
22
29 function __construct($a_title = "", $a_postvar = "")
30 {
31 parent::__construct($a_title, $a_postvar);
32 $this->setSize('25');
33 $this->validationRegexp = "";
34 }
35
41 function setValue($a_value)
42 {
43 $this->values = array();
44 if (is_array($a_value))
45 {
46 if (is_array($a_value['answer']))
47 {
48 foreach ($a_value['answer'] as $index => $value)
49 {
50 include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
51 $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, $a_value['imagename'][$index]);
52 array_push($this->values, $answer);
53 }
54 }
55 }
56 }
57
63 function setValues($a_values)
64 {
65 $this->values = $a_values;
66 }
67
73 function getValues()
74 {
75 return $this->values;
76 }
77
83 function setSingleline($a_value)
84 {
85 $this->singleline = $a_value;
86 }
87
93 function getSingleline()
94 {
95 return $this->singleline;
96 }
97
103 function setQuestionObject($a_value)
104 {
105 $this->qstObject =& $a_value;
106 }
107
114 {
115 return $this->qstObject;
116 }
117
123 function setAllowMove($a_allow_move)
124 {
125 $this->allowMove = $a_allow_move;
126 }
127
133 function getAllowMove()
134 {
135 return $this->allowMove;
136 }
137
141 public function isAddRemoveAllowed()
142 {
144 }
145
150 {
151 $this->allowAddRemove = $allowAddRemove;
152 }
153
160 {
161 $this->minvalueShouldBeGreater = $a_bool;
162 }
163
170 {
172 }
178 function setMinValue($a_minvalue)
179 {
180 $this->minvalue = $a_minvalue;
181 }
182
188 function getMinValue()
189 {
190 return $this->minvalue;
191 }
197 function checkInput()
198 {
199 global $lng;
201 $foundvalues = $_POST[$this->getPostVar()];
202 if (is_array($foundvalues))
203 {
204 // check answers
205 if (is_array($foundvalues['answer']))
206 {
207 foreach ($foundvalues['answer'] as $aidx => $answervalue)
208 {
209 if ((strlen($answervalue)) == 0)
210 {
211 $this->setAlert($lng->txt("msg_input_is_required"));
212 return FALSE;
213 }
214 }
215 }
216 // check points
217 $max = 0;
218 if (is_array($foundvalues['points']))
219 {
220 foreach ($foundvalues['points'] as $points)
221 {
222 if ($points > $max) $max = $points;
223 if (((strlen($points)) == 0) || (!is_numeric($points)))
224 {
225 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
226 return FALSE;
227 }
228 if ($this->minvalueShouldBeGreater())
229 {
230 if (trim($points) != "" &&
231 $this->getMinValue() !== false &&
232 $points <= $this->getMinValue())
233 {
234 $this->setAlert($lng->txt("form_msg_value_too_low"));
235
236 return false;
237 }
238 }
239 else
240 {
241 if (trim($points) != "" &&
242 $this->getMinValue() !== false &&
243 $points < $this->getMinValue())
244 {
245 $this->setAlert($lng->txt("form_msg_value_too_low"));
246
247 return false;
248
249 }
250 }
251 }
252 }
253 if ($max == 0)
254 {
255 $this->setAlert($lng->txt("enter_enough_positive_points"));
256 return false;
257 }
258 }
259 else
260 {
261 $this->setAlert($lng->txt("msg_input_is_required"));
262 return FALSE;
263 }
264
265 return $this->checkSubItemsInput();
266 }
267
273 function insert($a_tpl)
274 {
275 global $lng;
276
277 $tpl = new ilTemplate($this->getTemplate(), true, true, "Modules/TestQuestionPool");
278 $i = 0;
279 foreach ($this->values as $value)
280 {
281 if ($this->getSingleline())
282 {
283 if (is_object($value))
284 {
285 $tpl->setCurrentBlock("prop_text_propval");
286 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
287 $tpl->parseCurrentBlock();
288 $tpl->setCurrentBlock("prop_points_propval");
289 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
290 $tpl->parseCurrentBlock();
291 }
292 $tpl->setCurrentBlock('singleline');
293 $tpl->setVariable("SIZE", $this->getSize());
294 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
295 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
296 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
297 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
298 if ($this->getDisabled())
299 {
300 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
301 }
302 $tpl->parseCurrentBlock();
303 }
304 else if (!$this->getSingleline())
305 {
306 if (is_object($value))
307 {
308 $tpl->setCurrentBlock("prop_points_propval");
309 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
310 $tpl->parseCurrentBlock();
311 }
312 $tpl->setCurrentBlock('multiline');
313 $tpl->setVariable("PROPERTY_VALUE", $this->qstObject->prepareTextareaOutput($value->getAnswertext()));
314 $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
315 $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
316 $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
317 if ($this->getDisabled())
318 {
319 $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
320 }
321 $tpl->parseCurrentBlock();
322 }
323 if ($this->getAllowMove())
324 {
325 $tpl->setCurrentBlock("move");
326 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
327 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
328 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
329 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
330 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
331 $tpl->parseCurrentBlock();
332 }
333 $tpl->setCurrentBlock("row");
334 $tpl->setVariable("POST_VAR", $this->getPostVar());
335 $tpl->setVariable("ROW_NUMBER", $i);
336 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
337 $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
338 if($this->isAddRemoveAllowed())
339 {
340 $tpl->setVariable("ADD_REMOVE_ID", $this->getPostVar() . "[$i]");
341 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
342 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
343 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
344 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
345 }
346 if ($this->getDisabled())
347 {
348 $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
349 }
350 $tpl->parseCurrentBlock();
351 $i++;
352 }
353
354 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
355 $tpl->setVariable("ANSWER_TEXT", $this->getTextInputLabel($lng));
356 $tpl->setVariable("POINTS_TEXT", $this->getPointsInputLabel($lng));
357 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
358
359 $a_tpl->setCurrentBlock("prop_generic");
360 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
361 $a_tpl->parseCurrentBlock();
362
363 global $tpl;
364 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
365 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/answerwizard.js");
366 }
367
372 protected function getTextInputLabel($lng)
373 {
374 return $lng->txt('answer_text');
375 }
376
381 protected function getPointsInputLabel($lng)
382 {
383 return $lng->txt('points');
384 }
385
389 protected function getTemplate()
390 {
391 return "tpl.prop_answerwizardinput.html";
392 }
393
395 {
396 if( isset($_POST[$this->getPostVar()]) && is_array($_POST[$this->getPostVar()]) )
397 {
399 }
400 }
401}
global $tpl
Definition: ilias.php:8
$_POST["username"]
Class for answers with a binary state indicator.
An exception for terminatinating execution or to throw for unit testing.
This class represents a single choice wizard property in a property form.
getQuestionObject()
Get question object.
checkInput()
Check input, strip slashes etc.
insert($a_tpl)
Insert property html.
setMinvalueShouldBeGreater($a_bool)
Set minvalueShouldBeGreater.
setAllowMove($a_allow_move)
Set allow move.
minvalueShouldBeGreater()
Get minvalueShouldBeGreater.
__construct($a_title="", $a_postvar="")
Constructor.
setSingleline($a_value)
Set singleline.
setMinValue($a_minvalue)
Set Minimum Value.
setQuestionObject($a_value)
Set question object.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
getMaxLength()
Get Max Length.
setSize($a_size)
Set Size.
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
global $lng
Definition: privfeed.php:17