ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $singleline = true;
18 protected $qstObject = null;
19 protected $minvalue = false;
20 protected $minvalueShouldBeGreater = false;
21
28 function __construct($a_title = "", $a_postvar = "")
29 {
30 parent::__construct($a_title, $a_postvar);
31 $this->setSize('25');
32 $this->validationRegexp = "";
33 }
34
40 function setValue($a_value)
41 {
42 $this->values = array();
43 if (is_array($a_value))
44 {
45 if (is_array($a_value['answer']))
46 {
47 foreach ($a_value['answer'] as $index => $value)
48 {
49 include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
50 $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, $a_value['imagename'][$index]);
51 array_push($this->values, $answer);
52 }
53 }
54 }
55 }
56
62 function setValues($a_values)
63 {
64 $this->values = $a_values;
65 }
66
72 function getValues()
73 {
74 return $this->values;
75 }
76
82 function setSingleline($a_value)
83 {
84 $this->singleline = $a_value;
85 }
86
92 function getSingleline()
93 {
94 return $this->singleline;
95 }
96
102 function setQuestionObject($a_value)
103 {
104 $this->qstObject =& $a_value;
105 }
106
113 {
114 return $this->qstObject;
115 }
116
122 function setAllowMove($a_allow_move)
123 {
124 $this->allowMove = $a_allow_move;
125 }
126
132 function getAllowMove()
133 {
134 return $this->allowMove;
135 }
136
143 {
144 $this->minvalueShouldBeGreater = $a_bool;
145 }
146
153 {
155 }
161 function setMinValue($a_minvalue)
162 {
163 $this->minvalue = $a_minvalue;
164 }
165
171 function getMinValue()
172 {
173 return $this->minvalue;
174 }
180 function checkInput()
181 {
182 global $lng;
184 $foundvalues = $_POST[$this->getPostVar()];
185 if (is_array($foundvalues))
186 {
187 // check answers
188 if (is_array($foundvalues['answer']))
189 {
190 foreach ($foundvalues['answer'] as $aidx => $answervalue)
191 {
192 if ((strlen($answervalue)) == 0)
193 {
194 $this->setAlert($lng->txt("msg_input_is_required"));
195 return FALSE;
196 }
197 }
198 }
199 // check points
200 $max = 0;
201 if (is_array($foundvalues['points']))
202 {
203 foreach ($foundvalues['points'] as $points)
204 {
205 if ($points > $max) $max = $points;
206 if (((strlen($points)) == 0) || (!is_numeric($points)))
207 {
208 $this->setAlert($lng->txt("form_msg_numeric_value_required"));
209 return FALSE;
210 }
211 if ($this->minvalueShouldBeGreater())
212 {
213 if (trim($points) != "" &&
214 $this->getMinValue() !== false &&
215 $points <= $this->getMinValue())
216 {
217 $this->setAlert($lng->txt("form_msg_value_too_low"));
218
219 return false;
220 }
221 }
222 else
223 {
224 if (trim($points) != "" &&
225 $this->getMinValue() !== false &&
226 $points < $this->getMinValue())
227 {
228 $this->setAlert($lng->txt("form_msg_value_too_low"));
229
230 return false;
231
232 }
233 }
234 }
235 }
236 if ($max == 0)
237 {
238 $this->setAlert($lng->txt("enter_enough_positive_points"));
239 return false;
240 }
241 }
242 else
243 {
244 $this->setAlert($lng->txt("msg_input_is_required"));
245 return FALSE;
246 }
247
248 return $this->checkSubItemsInput();
249 }
250
256 function insert(&$a_tpl)
257 {
258 global $lng;
259
260 $tpl = new ilTemplate($this->getTemplate(), true, true, "Modules/TestQuestionPool");
261 $i = 0;
262 foreach ($this->values as $value)
263 {
264 if ($this->getSingleline())
265 {
266 if (is_object($value))
267 {
268 $tpl->setCurrentBlock("prop_text_propval");
269 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
270 $tpl->parseCurrentBlock();
271 $tpl->setCurrentBlock("prop_points_propval");
272 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
273 $tpl->parseCurrentBlock();
274 }
275 $tpl->setCurrentBlock('singleline');
276 $tpl->setVariable("SIZE", $this->getSize());
277 $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
278 $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
279 $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
280 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
281 if ($this->getDisabled())
282 {
283 $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
284 }
285 $tpl->parseCurrentBlock();
286 }
287 else if (!$this->getSingleline())
288 {
289 if (is_object($value))
290 {
291 $tpl->setCurrentBlock("prop_points_propval");
292 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
293 $tpl->parseCurrentBlock();
294 }
295 $tpl->setCurrentBlock('multiline');
296 $tpl->setVariable("PROPERTY_VALUE", $this->qstObject->prepareTextareaOutput($value->getAnswertext()));
297 $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
298 $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
299 $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
300 if ($this->getDisabled())
301 {
302 $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
303 }
304 $tpl->parseCurrentBlock();
305 }
306 if ($this->getAllowMove())
307 {
308 $tpl->setCurrentBlock("move");
309 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
310 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
311 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
312 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
313 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
314 $tpl->parseCurrentBlock();
315 }
316 $tpl->setCurrentBlock("row");
317 $tpl->setVariable("POST_VAR", $this->getPostVar());
318 $tpl->setVariable("ROW_NUMBER", $i);
319 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
320 $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
321 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
322 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
323 if ($this->getDisabled())
324 {
325 $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
326 }
327 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
328 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
329 $tpl->parseCurrentBlock();
330 $i++;
331 }
332
333 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
334 $tpl->setVariable("ANSWER_TEXT", $this->getTextInputLabel($lng));
335 $tpl->setVariable("POINTS_TEXT", $this->getPointsInputLabel($lng));
336 $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
337
338 $a_tpl->setCurrentBlock("prop_generic");
339 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
340 $a_tpl->parseCurrentBlock();
341
342 global $tpl;
343 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
344 $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/answerwizard.js");
345 }
346
351 protected function getTextInputLabel($lng)
352 {
353 return $lng->txt('answer_text');
354 }
355
360 protected function getPointsInputLabel($lng)
361 {
362 return $lng->txt('points');
363 }
364
368 protected function getTemplate()
369 {
370 return "tpl.prop_answerwizardinput.html";
371 }
372
374 {
375 if( isset($_POST[$this->getPostVar()]) && is_array($_POST[$this->getPostVar()]) )
376 {
378 }
379 }
380}
global $tpl
Definition: ilias.php:8
Class for answers with a binary state indicator.
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
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40