ILIAS  Release_4_2_x_branch Revision 61807
 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  $q_gui->object->setObjId($_GET['ref_id']);
214  $q_gui->object->createNewQuestion();
215 
216 
217  $previousQuestionId = $_REQUEST['position'];
218 
219  switch($_REQUEST['usage']) {
220  case 3: // existing pool
221  global $ilCtrl;
222  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_qpl', $_REQUEST['sel_qpl']);
223  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
224  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
225  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
226  if ($_REQUEST['test_express_mode'])
227  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
228  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 3);
229  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
230 
231  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
232  ilUtil::redirect($link);
233  break;
234  case 2: // new pool
235  global $ilCtrl;
236  $ilCtrl->setParameterByClass('ilobjtestgui', 'txt_qpl', $_REQUEST['txt_qpl']);
237  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
238  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
239  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
240  if ($_REQUEST['test_express_mode'])
241  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
242  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 2);
243  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
244 
245  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
246  ilUtil::redirect($link);
247  break;
248  case 1: // no pool
249  default:
250  $this->redirectToQuestionEditPage($questionType, $q_gui->object->getId(), $previousQuestionId);
251  break;
252  }
253  }
254 
255  public function addQuestion() {
256  global $lng, $ilCtrl, $tpl;
257 
258  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
259 
260  $ilCtrl->setParameter($this, 'qtype', $_REQUEST['qtype']);
261 
262  $form = new ilPropertyFormGUI();
263 
264  $ilCtrl->setParameter($this, 'test_express_mode', 1);
265 
266  $form->setFormAction($ilCtrl->getFormAction($this, "handleToolbarCommand"));
267  $form->setTitle($lng->txt("test_create_question"));
268  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
269 
270  $pool = new ilObjQuestionPool();
271  $questionTypes = $pool->getQuestionTypes();
272  $options = array();
273 
274  // question type
275  foreach($questionTypes as $label => $data) {
276  $options[$data['question_type_id']] = $label;
277  }
278 
279  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
280  $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
281  $si->setOptions($options);
282  $form->addItem($si, true);
283 
284  // position
285  $questions = $this->test_object->getQuestionTitlesAndIndexes();
286  if ($questions) {
287  $si = new ilSelectInputGUI($lng->txt("position"), "position");
288  $options = array('0' => $lng->txt('first'));
289  foreach($questions as $key => $title) {
290  $options[$key] = $lng->txt('behind') . ' '. $title;
291  }
292  $si->setOptions($options);
293  $si->setValue($_REQUEST['q_id']);
294  $form->addItem($si, true);
295  }
296 
297  if ($this->test_object->getPoolUsage()) {
298  // use pool
299  $usage = new ilRadioGroupInputGUI($this->lng->txt("assessment_pool_selection"), "usage");
300  $usage->setRequired(true);
301  $no_pool = new ilRadioOption($this->lng->txt("assessment_no_pool"), 1);
302  $usage->addOption($no_pool);
303  $existing_pool = new ilRadioOption($this->lng->txt("assessment_existing_pool"), 3);
304  $usage->addOption($existing_pool);
305  $new_pool = new ilRadioOption($this->lng->txt("assessment_new_pool"), 2);
306  $usage->addOption($new_pool);
307  $form->addItem($usage);
308 
309  $usage->setValue(1);
310 
311  $questionpools = ilObjQuestionPool::_getAvailableQuestionpools(FALSE, FALSE, TRUE, FALSE, FALSE, "write");
312  $pools_data = array();
313  foreach($questionpools as $key => $p) {
314  $pools_data[$key] = $p['title'];
315  }
316  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_qpl");
317  $pools->setOptions($pools_data);
318  $existing_pool->addSubItem($pools);
319 
320 
321  $name = new ilTextInputGUI($this->lng->txt("cat_create_qpl"), "txt_qpl");
322  $name->setSize(50);
323  $name->setMaxLength(50);
324  $new_pool->addSubItem($name);
325  }
326 
327 
328  $form->addCommandButton("handleToolbarCommand", $lng->txt("submit"));
329  $form->addCommandButton("questions", $lng->txt("cancel"));
330 
331  return $tpl->setContent($form->getHTML());
332 
333  }
334 
335  public function questions() {
336  global $ilCtrl;
337  $ilCtrl->saveParameterByClass('ilobjtestgui', 'q_id');
338  $ilCtrl->redirectByClass('ilobjtestgui', 'showPage');
339  }
340 
341  private function redirectToQuestionEditPage($questionType, $qid, $prev_qid) {
342  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
343 
344  $ref_id = $_GET['ref_id'];
345  $sel_question_types = $questionType;
346  $cmd = 'editQuestion';
347  $cmdClass = strtolower($questionType);
348  $cmdNode = $_GET['cmdNode'];
349  $baseClass = 'ilObjTestGUI';
350 
351  $node = ilTestExpressPage::getNodeId(strtolower($questionType) . 'gui');
352 
353  $cmdNodes = explode(':', $_GET['cmdNode']);
354  $firstNode = $cmdNodes[0];
355 
356  $linkParams = array(
357  'ref_id' => $_GET['ref_id'],
358  'sel_question_types' => $questionType,
359  'cmd' => 'editQuestion',
360  'cmdClass' => strtolower($questionType) . 'gui',
361  'cmdNode' => $firstNode . ':' . $node,
362  'baseClass' => 'ilObjTestGUI',
363  'test_ref_id' => $_GET['ref_id'],
364  'calling_test' => $_GET['ref_id'],
365  //'express_mode' => 'true',
366  'q_id' => $qid,
367  'prev_qid' => $prev_qid
368  );
369 
370  if ($_REQUEST['test_express_mode'])
371  $linkParams['test_express_mode'] = 1;
372 
373  ilUtil::redirect('ilias.php?' . http_build_query($linkParams, 'null', '&'));
374  }
375 
376  private function redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid) {
377  $this->ctrl->setParameterByClass('ilObjTestGUI', 'ref_id', $_REQUEST['ref_id']);
378  $this->ctrl->setParameterByClass('ilObjTestGUI', 'q_id', $qid);
379  $this->ctrl->setParameterByClass('ilObjTestGUI', 'sel_question_types', $questionType);
380  $this->ctrl->setParameterByClass('ilObjTestGUI', 'prev_qid', $prev_qid);
381  $redir = $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'createQuestion', '', false, false);
382 
383  ilUtil::redirect($redir);
384  }
385 
387  {
388  global $ilAccess, $tpl, $ilCtrl;
389 
390  $ilCtrl->setParameterByClass(get_class($this), "browse", "1");
391 
392  include_once "./Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php";
393  $table_gui = new ilTestQuestionBrowserTableGUI($this, 'browseForQuestions', (($ilAccess->checkAccess("write", "", $_REQUEST['ref_id']) ? true : false)));
394  $arrFilter = array();
395  foreach ($table_gui->getFilterItems() as $item)
396  {
397  if ($item->getValue() !== false)
398  {
399  $arrFilter[$item->getPostVar()] = $item->getValue();
400  }
401  }
402  $data = $this->test_object->getAvailableQuestions($arrFilter, 1);
403 
404  $table_gui->setData($data);
405  $tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
406  }
407 
408  function insertQuestions()
409  {
410  $selected_array = (is_array($_POST['q_id'])) ? $_POST['q_id'] : array();
411  if (!count($selected_array))
412  {
413  ilUtil::sendInfo($this->lng->txt("tst_insert_missing_question"), true);
414  $this->ctrl->redirect($this, "browseForQuestions");
415  }
416  else
417  {
418  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
419  $manscoring = FALSE;
420  foreach ($selected_array as $key => $value)
421  {
422  $last_question_id = $this->test_object->insertQuestion($value);
423  if (!$manscoring)
424  {
425  $manscoring = $manscoring | assQuestion::_needsManualScoring($value);
426  }
427  }
428  $this->test_object->saveCompleteStatus();
429  if ($manscoring)
430  {
431  ilUtil::sendInfo($this->lng->txt("manscoring_hint"), TRUE);
432  }
433  else
434  {
435  ilUtil::sendSuccess($this->lng->txt("tst_questions_inserted"), TRUE);
436  }
437 
438  $this->ctrl->setParameter($this, 'q_id', $last_question_id);
439  $this->ctrl->redirect($this, "showPage");
440  return;
441  }
442  }
443 
444  public function filterAvailableQuestions()
445  {
446  include_once "./Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php";
447  $table_gui = new ilTestQuestionBrowserTableGUI($this, 'browseForQuestions');
448  $table_gui->writeFilterToSession();
449  $this->ctrl->redirect($this, "browseForQuestions");
450  }
451 
453  {
454  include_once "./Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php";
455  $table_gui = new ilTestQuestionBrowserTableGUI($this, 'browseForQuestions');
456  $table_gui->resetFilter();
457  $this->ctrl->redirect($this, "browseForQuestions");
458  }
459 
460 }
461 
462 ?>