ILIAS  Release_4_0_x_branch Revision 61816
 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  // check question count
158  if ($this->getUseQuestionCount())
159  {
160  foreach ($foundvalues['count'] as $idx => $answervalue)
161  {
162  if ((strlen($answervalue)) == 0)
163  {
164  $this->setAlert($lng->txt("msg_input_is_required"));
165  return FALSE;
166  }
167  if (!is_numeric($answervalue))
168  {
169  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
170  return FALSE;
171  }
172  if ($answervalue < 1)
173  {
174  $this->setAlert($lng->txt("msg_question_count_too_low"));
175  return FALSE;
176  }
177  if ($answervalue > $this->random_pools[$foundvalues['qpl'][$idx]]['count'])
178  {
179  $this->setAlert($lng->txt("tst_random_selection_question_count_too_high"));
180  return FALSE;
181  }
182  }
183  }
184  }
185  else
186  {
187  if ($this->getUseQuestionCount())
188  {
189  $this->setAlert($lng->txt("msg_question_count_too_low"));
190  return FALSE;
191  }
192  }
193  // check pool selection
194  if (is_array($foundvalues['qpl']))
195  {
196  foreach ($foundvalues['qpl'] as $qpl)
197  {
198  if ($qpl < 1)
199  {
200  $this->setAlert($lng->txt("msg_input_is_required"));
201  return FALSE;
202  }
203  }
204  }
205  }
206  else
207  {
208  $this->setAlert($lng->txt("msg_input_is_required"));
209  return FALSE;
210  }
211  return $this->checkSubItemsInput();
212  }
213 
219  function insert(&$a_tpl)
220  {
221  global $lng;
222 
223  $tpl = new ilTemplate("tpl.prop_randomtestinput.html", true, true, "Modules/Test");
224  $i = 0;
225  $pools = $this->random_pools;
226  foreach ($this->values as $value)
227  {
228  if (array_key_exists($value->qpl, $this->random_pools)) unset($pools[$value->qpl]);
229  }
230  foreach ($this->values as $value)
231  {
232  if ($this->getUseQuestionCount())
233  {
234  if (is_object($value))
235  {
236  $tpl->setCurrentBlock("prop_text_propval");
237  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->count));
238  $tpl->parseCurrentBlock();
239  }
240  $tpl->setCurrentBlock('question_count');
241  $tpl->setVariable("SIZE", 3);
242  $tpl->setVariable("QUESTION_COUNT_ID", $this->getPostVar() . "[count][$i]");
243  $tpl->setVariable("QUESTION_COUNT_ROW_NUMBER", $i);
244  $tpl->setVariable("POST_VAR", $this->getPostVar());
245  $tpl->setVariable("MAXLENGTH", 5);
246  if ($this->getDisabled())
247  {
248  $tpl->setVariable("DISABLED_QUESTION_COUNT", " disabled=\"disabled\"");
249  }
250  $tpl->parseCurrentBlock();
251  }
252 
253  $tpl->setCurrentBlock("option");
254  $tpl->setVariable("OPTION_VALUE", 0);
255  $tpl->setVariable("OPTION_TEXT", ilUtil::prepareFormOutput($lng->txt('select_questionpool_option')));
256  $tpl->parseCurrentBlock();
257  foreach ($this->random_pools as $qpl => $pool)
258  {
259  if (($value->qpl == $qpl) || (array_key_exists($qpl, $pools)))
260  {
261  $tpl->setCurrentBlock("option");
262  if ($value->qpl == $qpl)
263  {
264  $tpl->setVariable("OPTION_SELECTED", ' selected="selected"');
265  }
266  $tpl->setVariable("OPTION_VALUE", $qpl);
267  $tpl->setVariable("OPTION_TEXT", ilUtil::prepareFormOutput($pool['title']));
268  $tpl->parseCurrentBlock();
269  }
270  }
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() . "[$i]");
280  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getPostVar() . "][$i]");
281  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getPostVar() . "][$i]");
282  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
283  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
284  $tpl->parseCurrentBlock();
285  $i++;
286  }
287  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
288 
289  $a_tpl->setCurrentBlock("prop_generic");
290  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
291  $a_tpl->parseCurrentBlock();
292 
293 // global $tpl;
294 // include_once "./Services/YUI/classes/class.ilYuiUtil.php";
295 // ilYuiUtil::initDomEvent();
296 // $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/singlechoicewizard.js");
297  }
298 }