ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestExpressPageObjectGUI.php
Go to the documentation of this file.
1 <?php
2 
3 include_once("./Services/COPage/classes/class.ilPageObjectGUI.php");
4 include_once 'Modules/Test/classes/class.ilTestExpressPage.php';
5 
26 
27  public function nextQuestion() {
28  $obj = new ilObjTest($_REQUEST['ref_id']);
29  $questions = array_keys($obj->getQuestionTitlesAndIndexes());
30 
31  $pos = array_search($_REQUEST['q_id'], $questions);
32 
33  if ($pos == count($questions) - 1) {
34  ilUtil::sendInfo('test_express_end_reached_moved_to_first', true);
35  $next = $questions[0];
36  } else if ($pos !== false) {
37  $next = $questions[$pos + 1];
38  } else {
39  $next = $questions[0];
40  }
41 
42  $this->ctrl->setParameter($this, 'q_id', $next);
43  $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
44 
45  ilUtil::redirect($link);
46  }
47 
48  public function prevQuestion() {
49  $obj = new ilObjTest($_REQUEST['ref_id']);
50  $questions = array_keys($obj->getQuestionTitlesAndIndexes());
51 
52  $pos = array_search($_REQUEST['q_id'], $questions);
53 
54  if ($pos == 0) {
55  ilUtil::sendInfo('test_express_start_reached_moved_to_last', true);
56  $next = $questions[count($questions) - 1];
57  } else if ($pos !== false) {
58  $next = $questions[$pos - 1];
59  } else {
60  $next = $questions[0];
61  }
62 
63  $this->ctrl->setParameter($this, 'q_id', $next);
64  $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
65 
66  ilUtil::redirect($link);
67  }
68 
69  function &executeCommand() {
70  global $ilCtrl, $ilTabs, $ilUser, $lng;
71 
72  $next_class = $this->ctrl->getNextClass($this);
73  $cmd = $this->ctrl->getCmd();
74 
75  switch ($next_class) {
76  case 'ilobjquestionpoolgui':
77  $nodeParts = explode(':', $_GET['cmdNode']);
78 
79  $params = array(
80  'ref_id' => $_GET['ref_id'],
81  'calling_test' => $_GET['ref_id'],
82  'q_id' => $_GET['q_id'],
83  'cmd' => $_GET['cmd'],
84  'cmdClass' => $_GET['cmdClass'],
85  'cmdNode' => $nodeParts[count($nodeParts) - 2] . ':' . $nodeParts[count($nodeParts) - 1],
86  'baseClass' => 'ilObjQuestionPoolGUI',
87  'test_express_mode' => '1'
88  );
89  ilUtil::redirect('ilias.php?' . http_build_query($params, null, '&'));
90  break;
91 
92  case "ilpageeditorgui":
93  if (!$this->getEnableEditing()) {
94  ilUtil::sendFailure($lng->txt("permission_denied"), true);
95  $ilCtrl->redirect($this, "preview");
96  }
97  $page_editor = & new ilPageEditorGUI($this->getPageObject(), $this);
98  $page_editor->setLocator($this->locator);
99  $page_editor->setHeader($this->getHeader());
100  $page_editor->setPageBackTitle($this->page_back_title);
101  $page_editor->setEnableInternalLinks($this->getEnabledInternalLinks());
102  $page_editor->setEnableKeywords($this->getEnableKeywords());
103  $page_editor->setIntLinkHelpDefault($this->int_link_def_type,
104  $this->int_link_def_id);
105  $page_editor->setIntLinkReturn($this->int_link_return);
106 
107 
108  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
109 
110  $ret = & $this->ctrl->forwardCommand($page_editor);
111  break;
112 
113  case '':
114  case 'iltestexpresspageobjectgui':
115  include_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
116 
117  if ($cmd == 'view')
118  $cmd = 'showPage';
119 
120  $q_gui = & assQuestionGUI::_getQuestionGUI('', $_REQUEST["q_id"]);
121  if ($q_gui->object) {
123  $q_gui->object->setObjId($obj->getId());
124  }
125 
126  if (in_array($cmd, array(
127  'handleToolbarCommand',
128  'addQuestion',
129  'questions',
130  'insertQuestions',
131  'browseForQuestions',
132  'filterAvailableQuestions',
133  'resetfilterAvailableQuestions'
134  ))) {
135  return $this->$cmd();
136  }
137  else if ($q_gui->object) {
138 
139  $total = $this->test_object->evalTotalPersons();
140 
142 
143  if($total != 0)
144  {
145  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', "participants");
146  $link = "<a href=\"".$link."\">".$lng->txt("test_has_datasets_warning_page_view_link")."</a>";
147  ilUtil::sendInfo($lng->txt("test_has_datasets_warning_page_view")." ".$link);
148  }
149 
150  if (in_array($cmd, array('view', 'showPage')) || $cmd == 'edit' && $this->test_object->evalTotalPersons()) {
151  return $this->showPage();
152  }
153  return parent::executeCommand();
154  }
155  break;
156 
157  default:
158  $qtype = $_REQUEST['qtype'];
160 
161  if (!$_GET['q_id']) {
162  $q_gui = $this->addPageOfQuestions(preg_replace('/(.*?)gui/i', '$1', $_GET['sel_question_types']));
163  $q_gui->setQuestionTabs();
164 
165  $ret = $this->ctrl->forwardCommand($q_gui);
166 
167  break;
168  } else {
169 
170  }
171  $this->ctrl->setReturn($this, "questions");
172  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
173  $q_gui = & assQuestionGUI::_getQuestionGUI($type, $_GET["q_id"]);
174 
175  if ($q_gui->object) {
177  $q_gui->object->setObjId($obj->getId());
178  }
179  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_id');
180  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
181 
182  $q_gui->setQuestionTabs();
183  $ret = & $this->ctrl->forwardCommand($q_gui);
184  break;
185  }
186  }
187 
188  public function addPageOfQuestions($type = '') {
189  global $ilCtrl;
190  if (!$type) {
191  $qtype = $_REQUEST['qtype'];
192  $pool = new ilObjQuestionPool();
194  }
195  $this->ctrl->setReturn($this, "questions");
196  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
197  $q_gui = & assQuestionGUI::_getQuestionGUI($type);
199  $q_gui->object->setObjId($obj->getId());
200  return $q_gui;
201  }
202 
203  public function handleToolbarCommand() {
204  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
205  if ($_REQUEST['qtype']) {
206  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
207  $questionType = ilObjQuestionPool::getQuestionTypeByTypeId($_REQUEST['qtype']);
208  }
209  else if ($_REQUEST['sel_question_types']) {
210  $questionType = $_REQUEST['sel_question_types'];
211  }
212  $q_gui =& assQuestionGUI::_getQuestionGUI($questionType);
213 
214  // CHECK THIS !!! --> obj or ref id ???
215  $q_gui->object->setObjId($_GET['ref_id']);
216 
217  $q_gui->object->createNewQuestion();
218 
219 
220  $previousQuestionId = $_REQUEST['position'];
221 
222  switch($_REQUEST['usage']) {
223  case 3: // existing pool
224  global $ilCtrl;
225  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_qpl', $_REQUEST['sel_qpl']);
226  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
227  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
228  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
229  if ($_REQUEST['test_express_mode'])
230  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
231  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 3);
232  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
233 
234  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
235  ilUtil::redirect($link);
236  break;
237  case 2: // new pool
238  global $ilCtrl;
239  $ilCtrl->setParameterByClass('ilobjtestgui', 'txt_qpl', $_REQUEST['txt_qpl']);
240  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
241  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
242  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
243  if ($_REQUEST['test_express_mode'])
244  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
245  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 2);
246  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
247 
248  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
249  ilUtil::redirect($link);
250  break;
251  case 1: // no pool
252  default:
253  $this->redirectToQuestionEditPage($questionType, $q_gui->object->getId(), $previousQuestionId);
254  break;
255  }
256  }
257 
258  public function addQuestion() {
259  global $lng, $ilCtrl, $tpl;
260 
261  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
262 
263  $ilCtrl->setParameter($this, 'qtype', $_REQUEST['qtype']);
264 
265  $form = new ilPropertyFormGUI();
266 
267  $ilCtrl->setParameter($this, 'test_express_mode', 1);
268 
269  $form->setFormAction($ilCtrl->getFormAction($this, "handleToolbarCommand"));
270  $form->setTitle($lng->txt("test_create_question"));
271  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
272 
273  $pool = new ilObjQuestionPool();
274  $questionTypes = $pool->getQuestionTypes(false, true);
275  $options = array();
276 
277  // question type
278  foreach($questionTypes as $label => $data) {
279  $options[$data['question_type_id']] = $label;
280  }
281 
282  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
283  $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
284  $si->setOptions($options);
285  $form->addItem($si, true);
286 
287  // position
288  $questions = $this->test_object->getQuestionTitlesAndIndexes();
289  if ($questions) {
290  $si = new ilSelectInputGUI($lng->txt("position"), "position");
291  $options = array('0' => $lng->txt('first'));
292  foreach($questions as $key => $title) {
293  $options[$key] = $lng->txt('behind') . ' '. $title;
294  }
295  $si->setOptions($options);
296  $si->setValue($_REQUEST['q_id']);
297  $form->addItem($si, true);
298  }
299 
300  if ($this->test_object->getPoolUsage()) {
301  // use pool
302  $usage = new ilRadioGroupInputGUI($this->lng->txt("assessment_pool_selection"), "usage");
303  $usage->setRequired(true);
304  $no_pool = new ilRadioOption($this->lng->txt("assessment_no_pool"), 1);
305  $usage->addOption($no_pool);
306  $existing_pool = new ilRadioOption($this->lng->txt("assessment_existing_pool"), 3);
307  $usage->addOption($existing_pool);
308  $new_pool = new ilRadioOption($this->lng->txt("assessment_new_pool"), 2);
309  $usage->addOption($new_pool);
310  $form->addItem($usage);
311 
312  $usage->setValue(1);
313 
314  $questionpools = ilObjQuestionPool::_getAvailableQuestionpools(FALSE, FALSE, TRUE, FALSE, FALSE, "write");
315  $pools_data = array();
316  foreach($questionpools as $key => $p) {
317  $pools_data[$key] = $p['title'];
318  }
319  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_qpl");
320  $pools->setOptions($pools_data);
321  $existing_pool->addSubItem($pools);
322 
323 
324  $name = new ilTextInputGUI($this->lng->txt("name"), "txt_qpl");
325  $name->setSize(50);
326  $name->setMaxLength(50);
327  $new_pool->addSubItem($name);
328  }
329 
330 
331  $form->addCommandButton("handleToolbarCommand", $lng->txt("create"));
332  $form->addCommandButton("questions", $lng->txt("cancel"));
333 
334  return $tpl->setContent($form->getHTML());
335 
336  }
337 
338  public function questions() {
339  global $ilCtrl;
340  $ilCtrl->saveParameterByClass('ilobjtestgui', 'q_id');
341  $ilCtrl->redirectByClass('ilobjtestgui', 'showPage');
342  }
343 
344  private function redirectToQuestionEditPage($questionType, $qid, $prev_qid) {
345  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
346 
347  $ref_id = $_GET['ref_id'];
348  $sel_question_types = $questionType;
349  $cmd = 'editQuestion';
350  $cmdClass = strtolower($questionType);
351  $cmdNode = $_GET['cmdNode'];
352  $baseClass = 'ilObjTestGUI';
353 
354  $node = ilTestExpressPage::getNodeId(strtolower($questionType) . 'gui');
355 
356  $cmdNodes = explode(':', $_GET['cmdNode']);
357  $firstNode = $cmdNodes[0];
358 
359  $linkParams = array(
360  'ref_id' => $_GET['ref_id'],
361  'sel_question_types' => $questionType,
362  'cmd' => 'editQuestion',
363  'cmdClass' => strtolower($questionType) . 'gui',
364  'cmdNode' => $firstNode . ':' . $node,
365  'baseClass' => 'ilObjTestGUI',
366  'test_ref_id' => $_GET['ref_id'],
367  'calling_test' => $_GET['ref_id'],
368  //'express_mode' => 'true',
369  'q_id' => $qid,
370  'prev_qid' => $prev_qid
371  );
372 
373  if ($_REQUEST['test_express_mode'])
374  $linkParams['test_express_mode'] = 1;
375 
376  ilUtil::redirect('ilias.php?' . http_build_query($linkParams, 'null', '&'));
377  }
378 
379  private function redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid) {
380  $this->ctrl->setParameterByClass('ilObjTestGUI', 'ref_id', $_REQUEST['ref_id']);
381  $this->ctrl->setParameterByClass('ilObjTestGUI', 'q_id', $qid);
382  $this->ctrl->setParameterByClass('ilObjTestGUI', 'sel_question_types', $questionType);
383  $this->ctrl->setParameterByClass('ilObjTestGUI', 'prev_qid', $prev_qid);
384  $redir = $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'createQuestion', '', false, false);
385 
386  ilUtil::redirect($redir);
387  }
388 
390  {
391  global $ilAccess, $tpl, $ilCtrl;
392 
393  $ilCtrl->setParameterByClass(get_class($this), "browse", "1");
394 
395  include_once "./Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php";
396  $table_gui = new ilTestQuestionBrowserTableGUI($this, 'browseForQuestions', (($ilAccess->checkAccess("write", "", $_REQUEST['ref_id']) ? true : false)));
397  $arrFilter = array();
398  foreach ($table_gui->getFilterItems() as $item)
399  {
400  if ($item->getValue() !== false)
401  {
402  $arrFilter[$item->getPostVar()] = $item->getValue();
403  }
404  }
405  $data = $this->test_object->getAvailableQuestions($arrFilter, 1);
406 
407  $table_gui->setData($data);
408  $tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
409  }
410 
411  function insertQuestions()
412  {
413  $selected_array = (is_array($_POST['q_id'])) ? $_POST['q_id'] : array();
414  if (!count($selected_array))
415  {
416  ilUtil::sendInfo($this->lng->txt("tst_insert_missing_question"), true);
417  $this->ctrl->redirect($this, "browseForQuestions");
418  }
419  else
420  {
421  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
422  $manscoring = FALSE;
423  foreach ($selected_array as $key => $value)
424  {
425  $last_question_id = $this->test_object->insertQuestion($value);
426  if (!$manscoring)
427  {
428  $manscoring = $manscoring | assQuestion::_needsManualScoring($value);
429  }
430  }
431  $this->test_object->saveCompleteStatus();
432  if ($manscoring)
433  {
434  ilUtil::sendInfo($this->lng->txt("manscoring_hint"), TRUE);
435  }
436  else
437  {
438  ilUtil::sendSuccess($this->lng->txt("tst_questions_inserted"), TRUE);
439  }
440 
441  $this->ctrl->setParameter($this, 'q_id', $last_question_id);
442  $this->ctrl->redirect($this, "showPage");
443  return;
444  }
445  }
446 
447  public function filterAvailableQuestions()
448  {
449  include_once "./Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php";
450  $table_gui = new ilTestQuestionBrowserTableGUI($this, 'browseForQuestions');
451  $table_gui->writeFilterToSession();
452  $this->ctrl->redirect($this, "browseForQuestions");
453  }
454 
456  {
457  include_once "./Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php";
458  $table_gui = new ilTestQuestionBrowserTableGUI($this, 'browseForQuestions');
459  $table_gui->resetFilter();
460  $this->ctrl->redirect($this, "browseForQuestions");
461  }
462 
463 }
464 
465 ?>