ILIAS  Release_4_4_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 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
12 {
13  protected $values = array();
14  protected $equal_points = false;
15  protected $question_count = true;
16  protected $random_pools = array();
17 
24  function __construct($a_title = "", $a_postvar = "")
25  {
26  parent::__construct($a_title, $a_postvar);
27  $this->setRequired(true);
28  }
29 
35  function setValue($a_value)
36  {
37  $this->values = array();
38  include_once "./Modules/Test/classes/class.ilRandomTestData.php";
39  if (is_array($a_value['qpl']))
40  {
41  foreach ($a_value['qpl'] as $idx => $qpl)
42  {
43  array_push($this->values, new ilRandomTestData($a_value['count'][$idx], $qpl));
44  }
45  }
46  }
47 
48  public function setValueByArray($a_values)
49  {
50  $this->setValue($a_values[$this->getPostVar()]);
51  }
52 
58  function setUseEqualPointsOnly($a_value)
59  {
60  $this->equal_points = $a_value;
61  }
62 
69  {
70  return $this->equal_points;
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 setRandomQuestionPools($a_values)
99  {
100  $this->random_pools = $a_values;
101  }
102 
108  function setUseQuestionCount($a_value)
109  {
110  $this->question_count = $a_value;
111  }
112 
119  {
120  return $this->question_count;
121  }
122 
128  function checkInput()
129  {
130  global $lng;
131 
132  $foundvalues = $_POST[$this->getPostVar()];
133  if (is_array($foundvalues))
134  {
135  if (is_array($foundvalues['count']))
136  {
137  if (count($foundvalues['qpl']) != count(array_unique($foundvalues['qpl'])))
138  {
139  $this->setAlert($lng->txt("msg_randompool_duplicate_qpl"));
140  return false;
141  }
142  // check question count
143  if ($this->getUseQuestionCount())
144  {
145  foreach ($foundvalues['count'] as $idx => $answervalue)
146  {
147  if ((strlen($answervalue)) == 0)
148  {
149  $this->setAlert($lng->txt("msg_input_is_required"));
150  return FALSE;
151  }
152  if (!is_numeric($answervalue))
153  {
154  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
155  return FALSE;
156  }
157  if ($answervalue < 1)
158  {
159  $this->setAlert($lng->txt("msg_question_count_too_low"));
160  return FALSE;
161  }
162  if ($answervalue > $this->random_pools[$foundvalues['qpl'][$idx]]['count'])
163  {
164  $this->setAlert($lng->txt("tst_random_selection_question_count_too_high"));
165  return FALSE;
166  }
167  }
168  }
169  }
170  else
171  {
172  if ($this->getUseQuestionCount())
173  {
174  $this->setAlert($lng->txt("msg_question_count_too_low"));
175  return FALSE;
176  }
177  }
178  // check pool selection
179  if (is_array($foundvalues['qpl']))
180  {
181  foreach ($foundvalues['qpl'] as $qpl)
182  {
183  if ($qpl < 1)
184  {
185  $this->setAlert($lng->txt("msg_input_is_required"));
186  return FALSE;
187  }
188  }
189  }
190  }
191  else
192  {
193  $this->setAlert($lng->txt("msg_input_is_required"));
194  return FALSE;
195  }
196  return $this->checkSubItemsInput();
197  }
198 
204  function insert(&$a_tpl)
205  {
206  global $lng;
207 
208  $tpl = new ilTemplate("tpl.prop_randomtestinput.html", true, true, "Modules/Test");
209  $i = 0;
210  $pools = $this->random_pools;
211  foreach ($this->values as $value)
212  {
213  if (array_key_exists($value->qpl, $this->random_pools)) unset($pools[$value->qpl]);
214  }
215  foreach ($this->values as $value)
216  {
217  if ($this->getUseQuestionCount())
218  {
219  if (is_object($value))
220  {
221  $tpl->setCurrentBlock("prop_text_propval");
222  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->count));
223  $tpl->parseCurrentBlock();
224  }
225  $tpl->setCurrentBlock('question_count');
226  $tpl->setVariable("SIZE", 3);
227  $tpl->setVariable("QUESTION_COUNT_ID", $this->getPostVar() . "[count][$i]");
228  $tpl->setVariable("QUESTION_COUNT_ROW_NUMBER", $i);
229  $tpl->setVariable("POST_VAR", $this->getPostVar());
230  $tpl->setVariable("MAXLENGTH", 5);
231  if ($this->getDisabled())
232  {
233  $tpl->setVariable("DISABLED_QUESTION_COUNT", " disabled=\"disabled\"");
234  }
235  $tpl->parseCurrentBlock();
236  }
237 
238  $tpl->setCurrentBlock("option");
239  $tpl->setVariable("OPTION_VALUE", 0);
240  $tpl->setVariable("OPTION_TEXT", ilUtil::prepareFormOutput($lng->txt('select_questionpool_option')));
241  $tpl->parseCurrentBlock();
242  foreach ($this->random_pools as $qpl => $pool)
243  {
244  if (($value->qpl == $qpl) || (array_key_exists($qpl, $pools)))
245  {
246  $tpl->setCurrentBlock("option");
247  if ($value->qpl == $qpl)
248  {
249  $tpl->setVariable("OPTION_SELECTED", ' selected="selected"');
250  }
251  $tpl->setVariable("OPTION_VALUE", $qpl);
252  $tpl->setVariable("OPTION_TEXT", ilUtil::prepareFormOutput($pool['title']));
253  $tpl->parseCurrentBlock();
254  }
255  }
256 
257  $tpl->setCurrentBlock("row");
258  $class = ($i % 2 == 0) ? "even" : "odd";
259  if ($i == 0) $class .= " first";
260  if ($i == count($this->values)-1) $class .= " last";
261  $tpl->setVariable("ROW_CLASS", $class);
262  $tpl->setVariable("POST_VAR", $this->getPostVar());
263  $tpl->setVariable("ROW_NUMBER", $i);
264  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
265  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getPostVar() . "][$i]");
266  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getPostVar() . "][$i]");
267  $tpl->setVariable("ADD_BUTTON", ilUtil::getImagePath('edit_add.png'));
268  $tpl->setVariable("REMOVE_BUTTON", ilUtil::getImagePath('edit_remove.png'));
269  $tpl->parseCurrentBlock();
270  $i++;
271  }
272  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
273 
274  $a_tpl->setCurrentBlock("prop_generic");
275  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
276  $a_tpl->parseCurrentBlock();
277 
278 // global $tpl;
279 // include_once "./Services/YUI/classes/class.ilYuiUtil.php";
280 // ilYuiUtil::initDomEvent();
281 // $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/singlechoicewizard.js");
282  }
283 }