ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilErrorTextWizardInputGUI.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 $key_size = 20;
35  protected $value_size = 20;
36  protected $key_maxlength = 255;
37  protected $value_maxlength = 255;
38  protected $key_name = "";
39  protected $value_name = "";
40 
47  function __construct($a_title = "", $a_postvar = "")
48  {
49  parent::__construct($a_title, $a_postvar);
50  }
51 
57  function setValue($a_value)
58  {
59  $this->values = array();
60  if (is_array($a_value))
61  {
62  include_once "./Modules/TestQuestionPool/classes/class.assAnswerErrorText.php";
63  if (is_array($a_value['key']))
64  {
65  foreach ($a_value['key'] as $idx => $key)
66  {
67  array_push($this->values, new assAnswerErrorText($key, $a_value['value'][$idx], str_replace(",", ".", $a_value['points'][$idx])));
68  }
69  }
70  }
71  }
72 
78  function setKeySize($a_size)
79  {
80  $this->key_size = $a_size;
81  }
82 
88  function getKeySize()
89  {
90  return $this->key_size;
91  }
92 
98  function setValueSize($a_size)
99  {
100  $this->value_size = $a_size;
101  }
102 
108  function getValueSize()
109  {
110  return $this->value_size;
111  }
112 
118  function setKeyMaxlength($a_maxlength)
119  {
120  $this->key_maxlength = $a_maxlength;
121  }
122 
128  function getKeyMaxlength()
129  {
130  return $this->key_maxlength;
131  }
132 
138  function setValueMaxlength($a_maxlength)
139  {
140  $this->value_maxlength = $a_maxlength;
141  }
142 
148  function getValueMaxlength()
149  {
150  return $this->value_maxlength;
151  }
152 
158  function setValueName($a_name)
159  {
160  $this->value_name = $a_name;
161  }
162 
168  function getValueName()
169  {
170  return $this->value_name;
171  }
172 
178  function setKeyName($a_name)
179  {
180  $this->key_name = $a_name;
181  }
182 
188  function getKeyName()
189  {
190  return $this->key_name;
191  }
192 
198  function setValues($a_values)
199  {
200  $this->values = $a_values;
201  }
202 
208  function getValues()
209  {
210  return $this->values;
211  }
212 
218  function checkInput()
219  {
220  global $lng;
221 
222  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
223  $foundvalues = $_POST[$this->getPostVar()];
224  if (is_array($foundvalues))
225  {
226  // check answers
227  if (is_array($foundvalues['key']) && is_array($foundvalues['value']))
228  {
229  foreach ($foundvalues['key'] as $val)
230  {
231  if ($this->getRequired() && (strlen($val)) == 0)
232  {
233  $this->setAlert($lng->txt("msg_input_is_required"));
234  return FALSE;
235  }
236  }
237  foreach ($foundvalues['value'] as $val)
238  {
239  if ($this->getRequired() && (strlen($val)) == 0)
240  {
241  $this->setAlert($lng->txt("msg_input_is_required"));
242  return FALSE;
243  }
244  }
245  foreach ($foundvalues['points'] as $val)
246  {
247  if ($this->getRequired() && (strlen($val)) == 0)
248  {
249  $this->setAlert($lng->txt("msg_input_is_required"));
250  return FALSE;
251  }
252  if (!is_numeric(str_replace(",", ".", $val)))
253  {
254  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
255  return FALSE;
256  }
257  }
258  }
259  else
260  {
261  if ($this->getRequired())
262  {
263  $this->setAlert($lng->txt("msg_input_is_required"));
264  return FALSE;
265  }
266  }
267  }
268  else
269  {
270  if ($this->getRequired())
271  {
272  $this->setAlert($lng->txt("msg_input_is_required"));
273  return FALSE;
274  }
275  }
276  return $this->checkSubItemsInput();
277  }
278 
284  function insert(&$a_tpl)
285  {
286  global $lng;
287 
288  $tpl = new ilTemplate("tpl.prop_errortextwizardinput.html", true, true, "Modules/TestQuestionPool");
289  $i = 0;
290  foreach ($this->values as $value)
291  {
292  if (is_object($value))
293  {
294  if (strlen($value->text_wrong))
295  {
296  $tpl->setCurrentBlock("prop_key_propval");
297  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_wrong));
298  $tpl->parseCurrentBlock();
299  }
300  if (strlen($value->text_correct))
301  {
302  $tpl->setCurrentBlock("prop_value_propval");
303  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->text_correct));
304  $tpl->parseCurrentBlock();
305  }
306  if (strlen($value->points))
307  {
308  $tpl->setCurrentBlock("prop_points_propval");
309  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->points));
310  $tpl->parseCurrentBlock();
311  }
312  }
313 
314  $tpl->setCurrentBlock("row");
315  $class = ($i % 2 == 0) ? "even" : "odd";
316  if ($i == 0) $class .= " first";
317  if ($i == count($this->values)-1) $class .= " last";
318  $tpl->setVariable("ROW_CLASS", $class);
319  $tpl->setVariable("ROW_NUMBER", $i);
320 
321  $tpl->setVariable("KEY_SIZE", $this->getKeySize());
322  $tpl->setVariable("KEY_ID", $this->getPostVar() . "[key][$i]");
323  $tpl->setVariable("KEY_MAXLENGTH", $this->getKeyMaxlength());
324 
325  $tpl->setVariable("VALUE_SIZE", $this->getValueSize());
326  $tpl->setVariable("VALUE_ID", $this->getPostVar() . "[value][$i]");
327  $tpl->setVariable("VALUE_MAXLENGTH", $this->getValueMaxlength());
328 
329  $tpl->setVariable("POST_VAR", $this->getPostVar());
330 
331  $tpl->parseCurrentBlock();
332 
333  $i++;
334  }
335  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
336  $tpl->setVariable("KEY_TEXT", $this->getKeyName());
337  $tpl->setVariable("VALUE_TEXT", $this->getValueName());
338  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
339 
340  $a_tpl->setCurrentBlock("prop_generic");
341  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
342  $a_tpl->parseCurrentBlock();
343  }
344 }