ILIAS  Release_4_0_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 /*
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  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
162  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()], false, ilObjAdvancedEditing::_getUsedHTMLTagsAsString("assessment"));
163  $foundvalues = $_POST[$this->getPostVar()];
164  if (is_array($foundvalues))
165  {
166  // check answers
167  if (is_array($foundvalues['answer']))
168  {
169  foreach ($foundvalues['answer'] as $aidx => $answervalue)
170  {
171  if ((strlen($answervalue)) == 0)
172  {
173  $this->setAlert($lng->txt("msg_input_is_required"));
174  return FALSE;
175  }
176  }
177  }
178  // check points
179  $max = 0;
180  if (is_array($foundvalues['points']))
181  {
182  foreach ($foundvalues['points'] as $points)
183  {
184  if ($points > $max) $max = $points;
185  if (((strlen($points)) == 0) || (!is_numeric($points)))
186  {
187  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
188  return FALSE;
189  }
190  }
191  }
192  if ($max == 0)
193  {
194  $this->setAlert($lng->txt("enter_enough_positive_points"));
195  return false;
196  }
197  }
198  else
199  {
200  $this->setAlert($lng->txt("msg_input_is_required"));
201  return FALSE;
202  }
203 
204  return $this->checkSubItemsInput();
205  }
206 
212  function insert(&$a_tpl)
213  {
214  global $lng;
215 
216  $tpl = new ilTemplate("tpl.prop_answerwizardinput.html", true, true, "Modules/TestQuestionPool");
217  $i = 0;
218  foreach ($this->values as $value)
219  {
220  if ($this->getSingleline())
221  {
222  if (is_object($value))
223  {
224  $tpl->setCurrentBlock("prop_text_propval");
225  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
226  $tpl->parseCurrentBlock();
227  $tpl->setCurrentBlock("prop_points_propval");
228  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
229  $tpl->parseCurrentBlock();
230  }
231  $tpl->setCurrentBlock('singleline');
232  $tpl->setVariable("SIZE", $this->getSize());
233  $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
234  $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
235  $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
236  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
237  if ($this->getDisabled())
238  {
239  $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
240  }
241  $tpl->parseCurrentBlock();
242  }
243  else if (!$this->getSingleline())
244  {
245  if (is_object($value))
246  {
247  $tpl->setCurrentBlock("prop_points_propval");
248  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
249  $tpl->parseCurrentBlock();
250  }
251  $tpl->setCurrentBlock('multiline');
252  $tpl->setVariable("PROPERTY_VALUE", $this->qstObject->prepareTextareaOutput($value->getAnswertext()));
253  $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
254  $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
255  $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
256  if ($this->getDisabled())
257  {
258  $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
259  }
260  $tpl->parseCurrentBlock();
261  }
262  if ($this->getAllowMove())
263  {
264  $tpl->setCurrentBlock("move");
265  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
266  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
267  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
268  $tpl->setVariable("UP_BUTTON", ilUtil::getImagePath('a_up.gif'));
269  $tpl->setVariable("DOWN_BUTTON", ilUtil::getImagePath('a_down.gif'));
270  $tpl->parseCurrentBlock();
271  }
272  $tpl->setCurrentBlock("row");
273  $class = ($i % 2 == 0) ? "even" : "odd";
274  if ($i == 0) $class .= " first";
275  if ($i == count($this->values)-1) $class .= " last";
276  $tpl->setVariable("ROW_CLASS", $class);
277  $tpl->setVariable("POST_VAR", $this->getPostVar());
278  $tpl->setVariable("ROW_NUMBER", $i);
279  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
280  $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
281  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
282  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
283  if ($this->getDisabled())
284  {
285  $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
286  }
287  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
288  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
289  $tpl->parseCurrentBlock();
290  $i++;
291  }
292 
293  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
294  $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
295  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
296  $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
297 
298  $a_tpl->setCurrentBlock("prop_generic");
299  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
300  $a_tpl->parseCurrentBlock();
301 
302  global $tpl;
303  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
305  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/answerwizard.js");
306  }
307 }