ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
12 {
13  protected $values = array();
14  protected $allowMove = false;
15  protected $singleline = true;
16  protected $qstObject = null;
17  protected $minvalue = false;
18  protected $minvalueShouldBeGreater = false;
19 
20  protected $disable_actions;
21  protected $disable_text;
22 
29  {
30  $this->disable_actions = $disable_actions;
31  return $this;
32  }
33 
39  public function setDisableText($disable_text)
40  {
41  $this->disable_text = $disable_text;
42  return $this;
43  }
44 
51  function __construct($a_title = "", $a_postvar = "")
52  {
53  parent::__construct($a_title, $a_postvar);
54  $this->setSize('25');
55  $this->validationRegexp = "";
56  }
57 
63  function setValue($a_value)
64  {
65  $this->values = array();
66  if (is_array($a_value))
67  {
68  if (is_array($a_value['answer']))
69  {
70  foreach ($a_value['answer'] as $index => $value)
71  {
72  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
73  $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, $a_value['imagename'][$index]);
74  array_push($this->values, $answer);
75  }
76  }
77  }
78  }
79 
85  function setValues($a_values)
86  {
87  $this->values = $a_values;
88  }
89 
95  function getValues()
96  {
97  return $this->values;
98  }
99 
105  function setSingleline($a_value)
106  {
107  $this->singleline = $a_value;
108  }
109 
115  function getSingleline()
116  {
117  return $this->singleline;
118  }
119 
125  function setQuestionObject($a_value)
126  {
127  $this->qstObject =& $a_value;
128  }
129 
135  function getQuestionObject()
136  {
137  return $this->qstObject;
138  }
139 
145  function setAllowMove($a_allow_move)
146  {
147  $this->allowMove = $a_allow_move;
148  }
149 
155  function getAllowMove()
156  {
157  return $this->allowMove;
158  }
159 
165  function setMinvalueShouldBeGreater($a_bool)
166  {
167  $this->minvalueShouldBeGreater = $a_bool;
168  }
169 
176  {
178  }
184  function setMinValue($a_minvalue)
185  {
186  $this->minvalue = $a_minvalue;
187  }
188 
194  function getMinValue()
195  {
196  return $this->minvalue;
197  }
203  function checkInput()
204  {
205  global $lng;
206  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
207  $foundvalues = $_POST[$this->getPostVar()];
208  if (is_array($foundvalues))
209  {
210  // check answers
211  if (is_array($foundvalues['answer']))
212  {
213  foreach ($foundvalues['answer'] as $aidx => $answervalue)
214  {
215  if ((strlen($answervalue)) == 0)
216  {
217  $this->setAlert($lng->txt("msg_input_is_required"));
218  return FALSE;
219  }
220  }
221  }
222  // check points
223  $max = 0;
224  if (is_array($foundvalues['points']))
225  {
226  foreach ($foundvalues['points'] as $points)
227  {
228  if ($points > $max) $max = $points;
229  if (((strlen($points)) == 0) || (!is_numeric($points)))
230  {
231  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
232  return FALSE;
233  }
234  if ($this->minvalueShouldBeGreater())
235  {
236  if (trim($points) != "" &&
237  $this->getMinValue() !== false &&
238  $points <= $this->getMinValue())
239  {
240  $this->setAlert($lng->txt("form_msg_value_too_low"));
241 
242  return false;
243  }
244  }
245  else
246  {
247  if (trim($points) != "" &&
248  $this->getMinValue() !== false &&
249  $points < $this->getMinValue())
250  {
251  $this->setAlert($lng->txt("form_msg_value_too_low"));
252 
253  return false;
254 
255  }
256  }
257  }
258  }
259  if ($max == 0)
260  {
261  $this->setAlert($lng->txt("enter_enough_positive_points"));
262  return false;
263  }
264  }
265  else
266  {
267  $this->setAlert($lng->txt("msg_input_is_required"));
268  return FALSE;
269  }
270 
271  return $this->checkSubItemsInput();
272  }
273 
279  function insert(&$a_tpl)
280  {
281  global $lng;
282 
283  $tpl = new ilTemplate("tpl.prop_answerwizardinput.html", true, true, "Modules/TestQuestionPool");
284  $i = 0;
285  foreach ($this->values as $value)
286  {
287  if ($this->getSingleline())
288  {
289  if (is_object($value))
290  {
291  $tpl->setCurrentBlock("prop_text_propval");
292  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
293  $tpl->parseCurrentBlock();
294  $tpl->setCurrentBlock("prop_points_propval");
295  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
296  $tpl->parseCurrentBlock();
297  }
298  $tpl->setCurrentBlock('singleline');
299  $tpl->setVariable("SIZE", $this->getSize());
300  $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
301  $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
302  $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
303  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
304  if ($this->getDisabled() || $this->disable_text)
305  {
306  $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
307  }
308  $tpl->parseCurrentBlock();
309  }
310  else if (!$this->getSingleline())
311  {
312  if (is_object($value))
313  {
314  $tpl->setCurrentBlock("prop_points_propval");
315  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
316  $tpl->parseCurrentBlock();
317  }
318  $tpl->setCurrentBlock('multiline');
319  $tpl->setVariable("PROPERTY_VALUE", $this->qstObject->prepareTextareaOutput($value->getAnswertext()));
320  $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
321  $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
322  $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
323  if ($this->getDisabled())
324  {
325  $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
326  }
327  $tpl->parseCurrentBlock();
328  }
329  if ($this->getAllowMove())
330  {
331  $tpl->setCurrentBlock("move");
332  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
333  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
334  $tpl->setVariable("MOVE_ID", $this->getPostVar() . "[$i]");
335  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.png'));
336  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.png'));
337  $tpl->parseCurrentBlock();
338  }
339  $tpl->setCurrentBlock("row");
340  $class = ($i % 2 == 0) ? "even" : "odd";
341  if ($i == 0) $class .= " first";
342  if ($i == count($this->values)-1) $class .= " last";
343  $tpl->setVariable("ROW_CLASS", $class);
344  $tpl->setVariable("POST_VAR", $this->getPostVar());
345  $tpl->setVariable("ROW_NUMBER", $i);
346  if(!$this->disable_actions)
347  {
348  $tpl->setVariable( "ID", $this->getPostVar() . "[answer][$i]" );
349  $tpl->setVariable( "POINTS_ID", $this->getPostVar() . "[points][$i]" );
350  $tpl->setVariable( "CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]" );
351  $tpl->setVariable( "CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]" );
352  }
353  if ($this->getDisabled())
354  {
355  $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
356  }
357  if(!$this->disable_actions)
358  {
359  $tpl->setVariable( "ADD_BUTTON", ilUtil::getImagePath( 'edit_add.png' ) );
360  $tpl->setVariable( "REMOVE_BUTTON", ilUtil::getImagePath( 'edit_remove.png' ) );
361  }
362  $tpl->parseCurrentBlock();
363  $i++;
364  }
365 
366  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
367  $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
368  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
369  if(!$this->disable_actions)
370  {
371  $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
372  }
373 
374  $a_tpl->setCurrentBlock("prop_generic");
375  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
376  $a_tpl->parseCurrentBlock();
377 
378  global $tpl;
379  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
381  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/answerwizard.js");
382  }
383 }