ILIAS  release_4-4 Revision
class.ilTestExpressPageObjectGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php";
5 include_once 'Modules/Test/classes/class.ilTestExpressPage.php';
6 
25 {
26  public function nextQuestion()
27  {
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  {
35  ilUtil::sendInfo('test_express_end_reached_moved_to_first', true);
36  $next = $questions[0];
37  }
38  elseif( $pos !== false )
39  {
40  $next = $questions[$pos + 1];
41  }
42  else
43  {
44  $next = $questions[0];
45  }
46 
47  $this->ctrl->setParameter($this, 'q_id', $next);
48  $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
49 
50  ilUtil::redirect($link);
51  }
52 
53  public function prevQuestion()
54  {
55  $obj = new ilObjTest($_REQUEST['ref_id']);
56  $questions = array_keys($obj->getQuestionTitlesAndIndexes());
57 
58  $pos = array_search($_REQUEST['q_id'], $questions);
59 
60  if( $pos == 0 )
61  {
62  ilUtil::sendInfo('test_express_start_reached_moved_to_last', true);
63  $next = $questions[count($questions) - 1];
64  }
65  elseif( $pos !== false )
66  {
67  $next = $questions[$pos - 1];
68  }
69  else
70  {
71  $next = $questions[0];
72  }
73 
74  $this->ctrl->setParameter($this, 'q_id', $next);
75  $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
76 
77  ilUtil::redirect($link);
78  }
79 
80  public function __construct($a_id = 0, $a_old_nr = 0) {
81  parent::__construct($a_id, $a_old_nr);
82  }
83 
84  function &executeCommand()
85  {
86  global $ilCtrl, $ilTabs, $ilUser, $lng;
87 
88  $next_class = $this->ctrl->getNextClass($this);
89  $cmd = $this->ctrl->getCmd();
90 
91  switch ($next_class)
92  {
93  case 'ilobjquestionpoolgui':
94 
95  $nodeParts = explode(':', $_GET['cmdNode']);
96 
97  $params = array(
98  'ref_id' => $_GET['ref_id'],
99  'calling_test' => $_GET['ref_id'],
100  'q_id' => $_GET['q_id'],
101  'cmd' => $_GET['cmd'],
102  'cmdClass' => $_GET['cmdClass'],
103  'cmdNode' => $nodeParts[count($nodeParts) - 2] . ':' . $nodeParts[count($nodeParts) - 1],
104  'baseClass' => 'ilObjQuestionPoolGUI',
105  'test_express_mode' => '1'
106  );
107 
108  ilUtil::redirect('ilias.php?' . http_build_query($params, null, '&'));
109 
110  break;
111 
112  case "ilpageeditorgui":
113 
114  if (!$this->getEnableEditing())
115  {
116  ilUtil::sendFailure($lng->txt("permission_denied"), true);
117  $ilCtrl->redirect($this, "preview");
118  }
119 
120  $page_editor = & new ilPageEditorGUI($this->getPageObject(), $this);
121  $page_editor->setLocator($this->locator);
122  $page_editor->setHeader($this->getHeader());
123  $page_editor->setPageBackTitle($this->page_back_title);
124  $page_editor->setIntLinkReturn($this->int_link_return);
125 
126  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
127 
128  $ret = & $this->ctrl->forwardCommand($page_editor);
129 
130  break;
131 
132  case '':
133  case 'iltestexpresspageobjectgui':
134 
135  include_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
136 
137  if( $cmd == 'view' )
138  {
139  $cmd = 'showPage';
140  }
141 
142  $q_gui = & assQuestionGUI::_getQuestionGUI('', $_REQUEST["q_id"]);
143 
144  if ($q_gui->object)
145  {
147  $q_gui->object->setObjId($obj->getId());
148  }
149 
150  $cmds = array(
151  'handleToolbarCommand',
152  'addQuestion',
153  'questions',
154  'insertQuestions',
155  'browseForQuestions',
156  'filterAvailableQuestions',
157  'resetfilterAvailableQuestions'
158  );
159 
160  if( in_array($cmd, $cmds) )
161  {
162  return $this->$cmd();
163  }
164  elseif( $q_gui->object )
165  {
166  $total = $this->test_object->evalTotalPersons();
167 
169 
170  if( $total != 0 )
171  {
172  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', "participants");
173  $link = "<a href=\"".$link."\">".$lng->txt("test_has_datasets_warning_page_view_link")."</a>";
174  ilUtil::sendInfo($lng->txt("test_has_datasets_warning_page_view")." ".$link);
175  }
176 
177  if( in_array($cmd, array('view', 'showPage')) || $cmd == 'edit' && $this->test_object->evalTotalPersons() )
178  {
179  return $this->showPage();
180  }
181 
182  return parent::executeCommand();
183  }
184 
185  break;
186 
187  default:
188 
189  $qtype = $_REQUEST['qtype'];
191 
192  if( !$_GET['q_id'] )
193  {
194  $q_gui = $this->addPageOfQuestions(preg_replace('/(.*?)gui/i', '$1', $_GET['sel_question_types']));
195  $q_gui->setQuestionTabs();
196 
197  $ret = $this->ctrl->forwardCommand($q_gui);
198 
199  break;
200  }
201 
202  $this->ctrl->setReturn($this, "questions");
203 
204  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
205  $q_gui = & assQuestionGUI::_getQuestionGUI($type, $_GET["q_id"]);
206 
207  if( $q_gui->object )
208  {
210  $q_gui->object->setObjId($obj->getId());
211  }
212 
213  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_id');
214  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
215 
216  $q_gui->setQuestionTabs();
217  $ret = & $this->ctrl->forwardCommand($q_gui);
218 
219  break;
220  }
221  }
222 
223  public function addPageOfQuestions($type = '')
224  {
225  global $ilCtrl;
226 
227  if( !$type )
228  {
229  $qtype = $_REQUEST['qtype'];
230  $pool = new ilObjQuestionPool();
232  }
233 
234  $this->ctrl->setReturn($this, "questions");
235 
236  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
237  $q_gui = & assQuestionGUI::_getQuestionGUI($type);
238 
240 
241  $q_gui->object->setObjId($obj->getId());
242 
243  return $q_gui;
244  }
245 
246  public function handleToolbarCommand()
247  {
248  global $ilCtrl;
249 
250  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
251 
252  if( $_REQUEST['qtype'] )
253  {
254  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
255  $questionType = ilObjQuestionPool::getQuestionTypeByTypeId($_REQUEST['qtype']);
256  }
257  elseif( $_REQUEST['sel_question_types'] )
258  {
259  $questionType = $_REQUEST['sel_question_types'];
260  }
261  require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
263  {
264  $addContEditMode = $_POST['add_quest_cont_edit_mode'];
265  }
266  else
267  {
269  }
270 
271  $q_gui =& assQuestionGUI::_getQuestionGUI($questionType);
272 
273  // CHECK THIS !!! --> obj or ref id ???
274  $q_gui->object->setObjId($_GET['ref_id']);
275  $q_gui->object->setAdditionalContentEditingMode($addContEditMode);
276 
277  $q_gui->object->createNewQuestion();
278 
279  $previousQuestionId = $_REQUEST['position'];
280 
281  switch( $_REQUEST['usage'] )
282  {
283  case 3: // existing pool
284 
285  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_qpl', $_REQUEST['sel_qpl']);
286  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
287  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
288  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
289 
290  if ($_REQUEST['test_express_mode'])
291  {
292  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
293  }
294 
295  if( isset($_REQUEST['add_quest_cont_edit_mode']) )
296  {
297  $ilCtrl->setParameterByClass(
298  'ilobjtestgui', 'add_quest_cont_edit_mode', $_REQUEST['add_quest_cont_edit_mode']
299  );
300  }
301 
302  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 3);
303  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
304 
305  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
306 
307  ilUtil::redirect($link);
308 
309  break;
310 
311  case 2: // new pool
312 
313  $ilCtrl->setParameterByClass('ilobjtestgui', 'txt_qpl', $_REQUEST['txt_qpl']);
314  $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
315  $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
316  $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
317 
318  if ($_REQUEST['test_express_mode'])
319  {
320  $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
321  }
322 
323  if( isset($_REQUEST['add_quest_cont_edit_mode']) )
324  {
325  $ilCtrl->setParameterByClass(
326  'ilobjtestgui', 'add_quest_cont_edit_mode', $_REQUEST['add_quest_cont_edit_mode']
327  );
328  }
329 
330  $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 2);
331  $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
332 
333  $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
334  ilUtil::redirect($link);
335 
336  break;
337 
338  case 1: // no pool
339  default:
340 
341  $this->redirectToQuestionEditPage($questionType, $q_gui->object->getId(), $previousQuestionId);
342 
343  break;
344  }
345  }
346 
347  public function addQuestion()
348  {
349  global $lng, $ilCtrl, $tpl;
350 
351  include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
352 
353  $ilCtrl->setParameter($this, 'qtype', $_REQUEST['qtype']);
354 
355  $form = new ilPropertyFormGUI();
356 
357  $ilCtrl->setParameter($this, 'test_express_mode', 1);
358 
359  $form->setFormAction($ilCtrl->getFormAction($this, "handleToolbarCommand"));
360  $form->setTitle($lng->txt("ass_create_question"));
361  include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
362 
363  $pool = new ilObjQuestionPool();
364  $questionTypes = $pool->getQuestionTypes(false, true);
365  $options = array();
366 
367  // question type
368  foreach($questionTypes as $label => $data)
369  {
370  $options[$data['question_type_id']] = $label;
371  }
372 
373  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
374  $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
375  $si->setOptions($options);
376  $form->addItem($si, true);
377 
378  // position
379  $questions = $this->test_object->getQuestionTitlesAndIndexes();
380  if($questions)
381  {
382  $si = new ilSelectInputGUI($lng->txt("position"), "position");
383  $options = array('0' => $lng->txt('first'));
384  foreach($questions as $key => $title)
385  {
386  $options[$key] = $lng->txt('behind') . ' '. $title . ' ['.$this->lng->txt('question_id_short') . ': '. $key .']';
387  }
388  $si->setOptions($options);
389  $si->setValue($_REQUEST['q_id']);
390  $form->addItem($si, true);
391  }
392 
393  // content editing mode
395  {
396  $ri = new ilRadioGroupInputGUI($lng->txt("tst_add_quest_cont_edit_mode"), "add_quest_cont_edit_mode");
397 
398  $ri->addOption(new ilRadioOption(
399  $lng->txt('tst_add_quest_cont_edit_mode_default'),
401  ));
402 
403  $ri->addOption(new ilRadioOption(
404  $lng->txt('tst_add_quest_cont_edit_mode_page_object'),
406  ));
407 
409 
410  $form->addItem($ri, true);
411  }
412  else
413  {
414  $hi = new ilHiddenInputGUI("question_content_editing_type");
416  $form->addItem($hi, true);
417  }
418 
419  if($this->test_object->getPoolUsage())
420  {
421  // use pool
422  $usage = new ilRadioGroupInputGUI($this->lng->txt("assessment_pool_selection"), "usage");
423  $usage->setRequired(true);
424  $no_pool = new ilRadioOption($this->lng->txt("assessment_no_pool"), 1);
425  $usage->addOption($no_pool);
426  $existing_pool = new ilRadioOption($this->lng->txt("assessment_existing_pool"), 3);
427  $usage->addOption($existing_pool);
428  $new_pool = new ilRadioOption($this->lng->txt("assessment_new_pool"), 2);
429  $usage->addOption($new_pool);
430  $form->addItem($usage);
431 
432  $usage->setValue(1);
433 
434  $questionpools = ilObjQuestionPool::_getAvailableQuestionpools(FALSE, FALSE, TRUE, FALSE, FALSE, "write");
435  $pools_data = array();
436  foreach($questionpools as $key => $p)
437  {
438  $pools_data[$key] = $p['title'];
439  }
440  $pools = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "sel_qpl");
441  $pools->setOptions($pools_data);
442  $existing_pool->addSubItem($pools);
443 
444  $name = new ilTextInputGUI($this->lng->txt("name"), "txt_qpl");
445  $name->setSize(50);
446  $name->setMaxLength(50);
447  $new_pool->addSubItem($name);
448  }
449 
450  $form->addCommandButton("handleToolbarCommand", $lng->txt("create"));
451  $form->addCommandButton("questions", $lng->txt("cancel"));
452 
453  return $tpl->setContent($form->getHTML());
454  }
455 
456  public function questions()
457  {
458  global $ilCtrl;
459 
460  $ilCtrl->saveParameterByClass('ilobjtestgui', 'q_id');
461 
462  $ilCtrl->redirectByClass('ilobjtestgui', 'showPage');
463  }
464 
465  private function redirectToQuestionEditPage($questionType, $qid, $prev_qid)
466  {
467  $cmdClass = $questionType.'GUI';
468 
469  $this->ctrl->setParameterByClass($cmdClass, 'ref_id', $_GET['ref_id']);
470  $this->ctrl->setParameterByClass($cmdClass, 'sel_question_types', $questionType);
471  $this->ctrl->setParameterByClass($cmdClass, 'test_ref_id', $_GET['ref_id']);
472  $this->ctrl->setParameterByClass($cmdClass, 'calling_test', $_GET['ref_id']);
473  $this->ctrl->setParameterByClass($cmdClass, 'q_id', $qid);
474  $this->ctrl->setParameterByClass($cmdClass, 'prev_qid', $prev_qid);
475 
476  if ($_REQUEST['test_express_mode'])
477  {
478  $this->ctrl->setParameterByClass($cmdClass, 'test_express_mode', 1);
479  }
480 
481  $this->ctrl->redirectByClass(
482  array('ilRepositoryGUI', 'ilObjTestGUI', $questionType."GUI"), 'editQuestion'
483  );
484  }
485 
486  private function redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid)
487  {
488  $this->ctrl->setParameterByClass('ilObjTestGUI', 'ref_id', $_REQUEST['ref_id']);
489  $this->ctrl->setParameterByClass('ilObjTestGUI', 'q_id', $qid);
490  $this->ctrl->setParameterByClass('ilObjTestGUI', 'sel_question_types', $questionType);
491  $this->ctrl->setParameterByClass('ilObjTestGUI', 'prev_qid', $prev_qid);
492  $redir = $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'createQuestion', '', false, false);
493 
494  ilUtil::redirect($redir);
495  }
496 
498  {
499  global $ilAccess, $tpl, $ilCtrl;
500 
501  $ilCtrl->setParameterByClass(get_class($this), "browse", "1");
502 
503  include_once "./Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php";
504  $table_gui = new ilTestQuestionBrowserTableGUI($this, 'browseForQuestions', (($ilAccess->checkAccess("write", "", $_REQUEST['ref_id']) ? true : false)));
505  $arrFilter = array();
506  foreach ($table_gui->getFilterItems() as $item)
507  {
508  if ($item->getValue() !== false)
509  {
510  $arrFilter[$item->getPostVar()] = $item->getValue();
511  }
512  }
513  $data = $this->test_object->getAvailableQuestions($arrFilter, 1);
514 
515  $table_gui->setData($data);
516  $tpl->setVariable('ADM_CONTENT', $table_gui->getHTML());
517  }
518 
519  function insertQuestions()
520  {
521  $selected_array = (is_array($_POST['q_id'])) ? $_POST['q_id'] : array();
522  if (!count($selected_array))
523  {
524  ilUtil::sendInfo($this->lng->txt("tst_insert_missing_question"), true);
525  $this->ctrl->redirect($this, "browseForQuestions");
526  }
527  else
528  {
529  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
530  $manscoring = FALSE;
531 
532  global $tree, $ilDB, $ilPluginAdmin;
533 
534  require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
535  $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $this->test_object);
536  $testQuestionSetConfig = $testQuestionSetConfigFactory->getQuestionSetConfig();
537 
538  foreach ($selected_array as $key => $value)
539  {
540  $last_question_id = $this->test_object->insertQuestion( $testQuestionSetConfig, $value );
541 
542  if (!$manscoring)
543  {
544  $manscoring = $manscoring | assQuestion::_needsManualScoring($value);
545  }
546  }
547  $this->test_object->saveCompleteStatus( $testQuestionSetConfig );
548  if ($manscoring)
549  {
550  ilUtil::sendInfo($this->lng->txt("manscoring_hint"), TRUE);
551  }
552  else
553  {
554  ilUtil::sendSuccess($this->lng->txt("tst_questions_inserted"), TRUE);
555  }
556 
557  $this->ctrl->setParameter($this, 'q_id', $last_question_id);
558  $this->ctrl->redirect($this, "showPage");
559  return;
560  }
561  }
562 
563  public function filterAvailableQuestions()
564  {
565  include_once "./Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php";
566  $table_gui = new ilTestQuestionBrowserTableGUI($this, 'browseForQuestions');
567  $table_gui->writeFilterToSession();
568  $this->ctrl->redirect($this, "browseForQuestions");
569  }
570 
572  {
573  include_once "./Modules/Test/classes/tables/class.ilTestQuestionBrowserTableGUI.php";
574  $table_gui = new ilTestQuestionBrowserTableGUI($this, 'browseForQuestions');
575  $table_gui->resetFilter();
576  $this->ctrl->redirect($this, "browseForQuestions");
577  }
578 
579 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
This class represents an option in a radio group.
const IL_PAGE_PREVIEW
$_POST['username']
Definition: cron.php:12
getPageObject()
Get Page Object.
getInstanceByRefId($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
This class represents a selection list property in a property form.
This class represents a property form user interface.
const ADDITIONAL_CONTENT_EDITING_MODE_PAGE_OBJECT
constant for additional content editing mode "pageobject"
$_GET["client_id"]
static getQuestionTypeByTypeId($type_id)
$cmd
Definition: sahs_server.php:35
Question page GUI class.
Page Editor GUI class.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
This class represents a hidden form property in a property form.
This class represents a property in a property form.
addOption($a_option)
Add Option.
setValue($a_value)
Set Value.
if(!is_array($argv)) $options
getEnableEditing()
Get Enable Editing.
setSize($a_size)
Set Size.
& _getQuestionGUI($question_type, $question_id=-1)
Creates a question gui representation and returns the alias to the question gui note: please do not u...
This class represents a text property in a property form.
const IL_PAGE_EDIT
setOptions($a_options)
Set Options.
_needsManualScoring($question_id)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT
constant for additional content editing mode "default"
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
global $ilUser
Definition: imgupload.php:15
redirectToQuestionEditPage($questionType, $qid, $prev_qid)
static isAdditionalQuestionContentEditingModePageObjectEnabled()
returns the fact wether content editing with ilias page editor is enabled for questions or not ...
& _getAvailableQuestionpools($use_object_id=FALSE, $equal_points=FALSE, $could_be_offline=FALSE, $showPath=FALSE, $with_questioncount=FALSE, $permission="read", $usr_id="")
Returns the available question pools for the active user.
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid)
static redirect($a_script)
http redirect to other script
ilTestExpressPageObjectGUI: assMultipleChoiceGUI, assClozeTestGUI, assMatchingQuestionGUI ilTestExpr...
setRequired($a_required)
Set Required.
setOutputMode($a_mode=IL_PAGE_PRESENTATION)
Set Output Mode.