ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAnswerWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
33  protected $values = array();
34  protected $allowMove = false;
35  protected $singleline = true;
36  protected $qstObject = null;
37  protected $minvalue = false;
38  protected $minvalueShouldBeGreater = false;
39 
46  function __construct($a_title = "", $a_postvar = "")
47  {
48  parent::__construct($a_title, $a_postvar);
49  $this->setSize('25');
50  $this->validationRegexp = "";
51  }
52 
58  function setValue($a_value)
59  {
60  $this->values = array();
61  if (is_array($a_value))
62  {
63  if (is_array($a_value['answer']))
64  {
65  foreach ($a_value['answer'] as $index => $value)
66  {
67  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
68  $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, $a_value['imagename'][$index]);
69  array_push($this->values, $answer);
70  }
71  }
72  }
73  }
74 
80  function setValues($a_values)
81  {
82  $this->values = $a_values;
83  }
84 
90  function getValues()
91  {
92  return $this->values;
93  }
94 
100  function setSingleline($a_value)
101  {
102  $this->singleline = $a_value;
103  }
104 
110  function getSingleline()
111  {
112  return $this->singleline;
113  }
114 
120  function setQuestionObject($a_value)
121  {
122  $this->qstObject =& $a_value;
123  }
124 
130  function getQuestionObject()
131  {
132  return $this->qstObject;
133  }
134 
140  function setAllowMove($a_allow_move)
141  {
142  $this->allowMove = $a_allow_move;
143  }
144 
150  function getAllowMove()
151  {
152  return $this->allowMove;
153  }
154 
160  function setMinvalueShouldBeGreater($a_bool)
161  {
162  $this->minvalueShouldBeGreater = $a_bool;
163  }
164 
171  {
173  }
179  function setMinValue($a_minvalue)
180  {
181  $this->minvalue = $a_minvalue;
182  }
183 
189  function getMinValue()
190  {
191  return $this->minvalue;
192  }
198  function checkInput()
199  {
200  global $lng;
201  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
202  $foundvalues = $_POST[$this->getPostVar()];
203  if (is_array($foundvalues))
204  {
205  // check answers
206  if (is_array($foundvalues['answer']))
207  {
208  foreach ($foundvalues['answer'] as $aidx => $answervalue)
209  {
210  if ((strlen($answervalue)) == 0)
211  {
212  $this->setAlert($lng->txt("msg_input_is_required"));
213  return FALSE;
214  }
215  }
216  }
217  // check points
218  $max = 0;
219  if (is_array($foundvalues['points']))
220  {
221  foreach ($foundvalues['points'] as $points)
222  {
223  if ($points > $max) $max = $points;
224  if (((strlen($points)) == 0) || (!is_numeric($points)))
225  {
226  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
227  return FALSE;
228  }
229  if ($this->minvalueShouldBeGreater())
230  {
231  if (trim($points) != "" &&
232  $this->getMinValue() !== false &&
233  $points <= $this->getMinValue())
234  {
235  $this->setAlert($lng->txt("form_msg_value_too_low"));
236 
237  return false;
238  }
239  }
240  else
241  {
242  if (trim($points) != "" &&
243  $this->getMinValue() !== false &&
244  $points < $this->getMinValue())
245  {
246  $this->setAlert($lng->txt("form_msg_value_too_low"));
247 
248  return false;
249 
250  }
251  }
252  }
253  }
254  if ($max == 0)
255  {
256  $this->setAlert($lng->txt("enter_enough_positive_points"));
257  return false;
258  }
259  }
260  else
261  {
262  $this->setAlert($lng->txt("msg_input_is_required"));
263  return FALSE;
264  }
265 
266  return $this->checkSubItemsInput();
267  }
268 
274  function insert(&$a_tpl)
275  {
276  global $lng;
277 
278  $tpl = new ilTemplate("tpl.prop_answerwizardinput.html", true, true, "Modules/TestQuestionPool");
279  $i = 0;
280  foreach ($this->values as $value)
281  {
282  if ($this->getSingleline())
283  {
284  if (is_object($value))
285  {
286  $tpl->setCurrentBlock("prop_text_propval");
287  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
288  $tpl->parseCurrentBlock();
289  $tpl->setCurrentBlock("prop_points_propval");
290  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
291  $tpl->parseCurrentBlock();
292  }
293  $tpl->setCurrentBlock('singleline');
294  $tpl->setVariable("SIZE", $this->getSize());
295  $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
296  $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
297  $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
298  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
299  if ($this->getDisabled())
300  {
301  $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
302  }
303  $tpl->parseCurrentBlock();
304  }
305  else if (!$this->getSingleline())
306  {
307  if (is_object($value))
308  {
309  $tpl->setCurrentBlock("prop_points_propval");
310  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
311  $tpl->parseCurrentBlock();
312  }
313  $tpl->setCurrentBlock('multiline');
314  $tpl->setVariable("PROPERTY_VALUE", $this->qstObject->prepareTextareaOutput($value->getAnswertext()));
315  $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
316  $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
317  $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
318  if ($this->getDisabled())
319  {
320  $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
321  }
322  $tpl->parseCurrentBlock();
323  }
324  if ($this->getAllowMove())
325  {
326  $tpl->setCurrentBlock("move");
327  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
328  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
329  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
330  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.png'));
331  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.png'));
332  $tpl->parseCurrentBlock();
333  }
334  $tpl->setCurrentBlock("row");
335  $class = ($i % 2 == 0) ? "even" : "odd";
336  if ($i == 0) $class .= " first";
337  if ($i == count($this->values)-1) $class .= " last";
338  $tpl->setVariable("ROW_CLASS", $class);
339  $tpl->setVariable("POST_VAR", $this->getPostVar());
340  $tpl->setVariable("ROW_NUMBER", $i);
341  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
342  $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
343  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
344  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
345  if ($this->getDisabled())
346  {
347  $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
348  }
349  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
350  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
351  $tpl->parseCurrentBlock();
352  $i++;
353  }
354 
355  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
356  $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
357  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
358  $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
359 
360  $a_tpl->setCurrentBlock("prop_generic");
361  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
362  $a_tpl->parseCurrentBlock();
363 
364  global $tpl;
365  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
367  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/answerwizard.js");
368  }
369 }