ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRandomTestInputGUI.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 $equal_points = false;
35  protected $question_count = true;
36  protected $random_pools = array();
37 
44  function __construct($a_title = "", $a_postvar = "")
45  {
46  parent::__construct($a_title, $a_postvar);
47  $this->setRequired(true);
48  }
49 
55  function setValue($a_value)
56  {
57  $this->values = array();
58  include_once "./Modules/Test/classes/class.ilRandomTestData.php";
59  if (is_array($a_value['qpl']))
60  {
61  foreach ($a_value['qpl'] as $idx => $qpl)
62  {
63  array_push($this->values, new ilRandomTestData($a_value['count'][$idx], $qpl));
64  }
65  }
66  }
67 
68  public function setValueByArray($a_values)
69  {
70  $this->setValue($a_values[$this->getPostVar()]);
71  }
72 
78  function setUseEqualPointsOnly($a_value)
79  {
80  $this->equal_points = $a_value;
81  }
82 
89  {
90  return $this->equal_points;
91  }
92 
98  function setValues($a_values)
99  {
100  $this->values = $a_values;
101  }
102 
108  function getValues()
109  {
110  return $this->values;
111  }
112 
118  function setRandomQuestionPools($a_values)
119  {
120  $this->random_pools = $a_values;
121  }
122 
128  function setUseQuestionCount($a_value)
129  {
130  $this->question_count = $a_value;
131  }
132 
139  {
140  return $this->question_count;
141  }
142 
148  function checkInput()
149  {
150  global $lng;
151 
152  $foundvalues = $_POST[$this->getPostVar()];
153  if (is_array($foundvalues))
154  {
155  if (is_array($foundvalues['count']))
156  {
157  if (count($foundvalues['qpl']) != count(array_unique($foundvalues['qpl'])))
158  {
159  $this->setAlert($lng->txt("msg_randompool_duplicate_qpl"));
160  return false;
161  }
162  // check question count
163  if ($this->getUseQuestionCount())
164  {
165  foreach ($foundvalues['count'] as $idx => $answervalue)
166  {
167  if ((strlen($answervalue)) == 0)
168  {
169  $this->setAlert($lng->txt("msg_input_is_required"));
170  return FALSE;
171  }
172  if (!is_numeric($answervalue))
173  {
174  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
175  return FALSE;
176  }
177  if ($answervalue < 1)
178  {
179  $this->setAlert($lng->txt("msg_question_count_too_low"));
180  return FALSE;
181  }
182  if ($answervalue > $this->random_pools[$foundvalues['qpl'][$idx]]['count'])
183  {
184  $this->setAlert($lng->txt("tst_random_selection_question_count_too_high"));
185  return FALSE;
186  }
187  }
188  }
189  }
190  else
191  {
192  if ($this->getUseQuestionCount())
193  {
194  $this->setAlert($lng->txt("msg_question_count_too_low"));
195  return FALSE;
196  }
197  }
198  // check pool selection
199  if (is_array($foundvalues['qpl']))
200  {
201  foreach ($foundvalues['qpl'] as $qpl)
202  {
203  if ($qpl < 1)
204  {
205  $this->setAlert($lng->txt("msg_input_is_required"));
206  return FALSE;
207  }
208  }
209  }
210  }
211  else
212  {
213  $this->setAlert($lng->txt("msg_input_is_required"));
214  return FALSE;
215  }
216  return $this->checkSubItemsInput();
217  }
218 
224  function insert(&$a_tpl)
225  {
226  global $lng;
227 
228  $tpl = new ilTemplate("tpl.prop_randomtestinput.html", true, true, "Modules/Test");
229  $i = 0;
230  $pools = $this->random_pools;
231  foreach ($this->values as $value)
232  {
233  if (array_key_exists($value->qpl, $this->random_pools)) unset($pools[$value->qpl]);
234  }
235  foreach ($this->values as $value)
236  {
237  if ($this->getUseQuestionCount())
238  {
239  if (is_object($value))
240  {
241  $tpl->setCurrentBlock("prop_text_propval");
242  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->count));
243  $tpl->parseCurrentBlock();
244  }
245  $tpl->setCurrentBlock('question_count');
246  $tpl->setVariable("SIZE", 3);
247  $tpl->setVariable("QUESTION_COUNT_ID", $this->getPostVar() . "[count][$i]");
248  $tpl->setVariable("QUESTION_COUNT_ROW_NUMBER", $i);
249  $tpl->setVariable("POST_VAR", $this->getPostVar());
250  $tpl->setVariable("MAXLENGTH", 5);
251  if ($this->getDisabled())
252  {
253  $tpl->setVariable("DISABLED_QUESTION_COUNT", " disabled=\"disabled\"");
254  }
255  $tpl->parseCurrentBlock();
256  }
257 
258  $tpl->setCurrentBlock("option");
259  $tpl->setVariable("OPTION_VALUE", 0);
260  $tpl->setVariable("OPTION_TEXT", ilUtil::prepareFormOutput($lng->txt('select_questionpool_option')));
261  $tpl->parseCurrentBlock();
262  foreach ($this->random_pools as $qpl => $pool)
263  {
264  if (($value->qpl == $qpl) || (array_key_exists($qpl, $pools)))
265  {
266  $tpl->setCurrentBlock("option");
267  if ($value->qpl == $qpl)
268  {
269  $tpl->setVariable("OPTION_SELECTED", ' selected="selected"');
270  }
271  $tpl->setVariable("OPTION_VALUE", $qpl);
272  $tpl->setVariable("OPTION_TEXT", ilUtil::prepareFormOutput($pool['title']));
273  $tpl->parseCurrentBlock();
274  }
275  }
276 
277  $tpl->setCurrentBlock("row");
278  $class = ($i % 2 == 0) ? "even" : "odd";
279  if ($i == 0) $class .= " first";
280  if ($i == count($this->values)-1) $class .= " last";
281  $tpl->setVariable("ROW_CLASS", $class);
282  $tpl->setVariable("POST_VAR", $this->getPostVar());
283  $tpl->setVariable("ROW_NUMBER", $i);
284  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
285  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getPostVar() . "][$i]");
286  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getPostVar() . "][$i]");
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  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
293 
294  $a_tpl->setCurrentBlock("prop_generic");
295  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
296  $a_tpl->parseCurrentBlock();
297 
298 // global $tpl;
299 // include_once "./Services/YUI/classes/class.ilYuiUtil.php";
300 // ilYuiUtil::initDomEvent();
301 // $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/singlechoicewizard.js");
302  }
303 }