ILIAS  Release_4_2_x_branch Revision 61807
 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 
44  function __construct($a_title = "", $a_postvar = "")
45  {
46  parent::__construct($a_title, $a_postvar);
47  $this->setSize('25');
48  $this->validationRegexp = "";
49  }
50 
56  function setValue($a_value)
57  {
58  $this->values = array();
59  if (is_array($a_value))
60  {
61  if (is_array($a_value['answer']))
62  {
63  foreach ($a_value['answer'] as $index => $value)
64  {
65  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
66  $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, $a_value['imagename'][$index]);
67  array_push($this->values, $answer);
68  }
69  }
70  }
71  }
72 
78  function setValues($a_values)
79  {
80  $this->values = $a_values;
81  }
82 
88  function getValues()
89  {
90  return $this->values;
91  }
92 
98  function setSingleline($a_value)
99  {
100  $this->singleline = $a_value;
101  }
102 
108  function getSingleline()
109  {
110  return $this->singleline;
111  }
112 
118  function setQuestionObject($a_value)
119  {
120  $this->qstObject =& $a_value;
121  }
122 
128  function getQuestionObject()
129  {
130  return $this->qstObject;
131  }
132 
138  function setAllowMove($a_allow_move)
139  {
140  $this->allowMove = $a_allow_move;
141  }
142 
148  function getAllowMove()
149  {
150  return $this->allowMove;
151  }
152 
158  function checkInput()
159  {
160  global $lng;
161  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
162  $foundvalues = $_POST[$this->getPostVar()];
163  if (is_array($foundvalues))
164  {
165  // check answers
166  if (is_array($foundvalues['answer']))
167  {
168  foreach ($foundvalues['answer'] as $aidx => $answervalue)
169  {
170  if ((strlen($answervalue)) == 0)
171  {
172  $this->setAlert($lng->txt("msg_input_is_required"));
173  return FALSE;
174  }
175  }
176  }
177  // check points
178  $max = 0;
179  if (is_array($foundvalues['points']))
180  {
181  foreach ($foundvalues['points'] as $points)
182  {
183  if ($points > $max) $max = $points;
184  if (((strlen($points)) == 0) || (!is_numeric($points)))
185  {
186  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
187  return FALSE;
188  }
189  }
190  }
191  if ($max == 0)
192  {
193  $this->setAlert($lng->txt("enter_enough_positive_points"));
194  return false;
195  }
196  }
197  else
198  {
199  $this->setAlert($lng->txt("msg_input_is_required"));
200  return FALSE;
201  }
202 
203  return $this->checkSubItemsInput();
204  }
205 
211  function insert(&$a_tpl)
212  {
213  global $lng;
214 
215  $tpl = new ilTemplate("tpl.prop_answerwizardinput.html", true, true, "Modules/TestQuestionPool");
216  $i = 0;
217  foreach ($this->values as $value)
218  {
219  if ($this->getSingleline())
220  {
221  if (is_object($value))
222  {
223  $tpl->setCurrentBlock("prop_text_propval");
224  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
225  $tpl->parseCurrentBlock();
226  $tpl->setCurrentBlock("prop_points_propval");
227  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
228  $tpl->parseCurrentBlock();
229  }
230  $tpl->setCurrentBlock('singleline');
231  $tpl->setVariable("SIZE", $this->getSize());
232  $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
233  $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
234  $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
235  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
236  if ($this->getDisabled())
237  {
238  $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
239  }
240  $tpl->parseCurrentBlock();
241  }
242  else if (!$this->getSingleline())
243  {
244  if (is_object($value))
245  {
246  $tpl->setCurrentBlock("prop_points_propval");
247  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
248  $tpl->parseCurrentBlock();
249  }
250  $tpl->setCurrentBlock('multiline');
251  $tpl->setVariable("PROPERTY_VALUE", $this->qstObject->prepareTextareaOutput($value->getAnswertext()));
252  $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
253  $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
254  $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
255  if ($this->getDisabled())
256  {
257  $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
258  }
259  $tpl->parseCurrentBlock();
260  }
261  if ($this->getAllowMove())
262  {
263  $tpl->setCurrentBlock("move");
264  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
265  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
266  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
267  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.gif'));
268  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.gif'));
269  $tpl->parseCurrentBlock();
270  }
271  $tpl->setCurrentBlock("row");
272  $class = ($i % 2 == 0) ? "even" : "odd";
273  if ($i == 0) $class .= " first";
274  if ($i == count($this->values)-1) $class .= " last";
275  $tpl->setVariable("ROW_CLASS", $class);
276  $tpl->setVariable("POST_VAR", $this->getPostVar());
277  $tpl->setVariable("ROW_NUMBER", $i);
278  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
279  $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
280  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
281  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
282  if ($this->getDisabled())
283  {
284  $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
285  }
286  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
287  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
288  $tpl->parseCurrentBlock();
289  $i++;
290  }
291 
292  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
293  $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
294  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
295  $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
296 
297  $a_tpl->setCurrentBlock("prop_generic");
298  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
299  $a_tpl->parseCurrentBlock();
300 
301  global $tpl;
302  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
304  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/answerwizard.js");
305  }
306 }