ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestExpressPageObjectGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
39 {
40  protected $test_object;
41 
42  private ilTree $tree;
43  private ilDBInterface $db;
45 
46  public function nextQuestion()
47  {
48  $obj = new ilObjTest($this->testrequest->getRefId());
49  $questions = array_keys($obj->getQuestionTitlesAndIndexes());
50 
51  $pos = array_search($this->testrequest->raw('q_id'), $questions);
52 
53  if ($pos !== false) {
54  $next = $questions[$pos + 1];
55  } else {
56  $next = $questions[0];
57  }
58 
59  $this->ctrl->setParameter($this, 'q_id', $next);
60  $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
61 
63  }
64 
65  public function prevQuestion()
66  {
67  $obj = new ilObjTest($this->testrequest->getRefId());
68  $questions = array_keys($obj->getQuestionTitlesAndIndexes());
69 
70  $pos = array_search($this->testrequest->raw('q_id'), $questions);
71 
72  if ($pos !== false) {
73  $next = $questions[$pos - 1];
74  } else {
75  $next = $questions[0];
76  }
77 
78  $this->ctrl->setParameter($this, 'q_id', $next);
79  $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
80 
82  }
83 
84  public function __construct($a_id = 0, $a_old_nr = 0, $test_object = null)
85  {
86  global $DIC;
87  $this->tree = $DIC['tree'];
88  $this->db = $DIC['ilDB'];
89  $this->component_repository = $DIC['component.repository'];
90  $this->test_object = $test_object;
91 
92  parent::__construct($a_id, $a_old_nr);
93  }
94 
95  public function executeCommand(): string
96  {
97  $next_class = $this->ctrl->getNextClass($this);
98  $cmd = $this->ctrl->getCmd();
99 
100  switch ($next_class) {
101  case 'ilobjquestionpoolgui':
102 
103  $nodeParts = explode(':', $this->testrequest->raw('cmdNode'));
104 
105  $params = [
106  'ref_id' => $this->testrequest->getRefId(),
107  'calling_test' => $this->testrequest->getRefId(),
108  'q_id' => $this->testrequest->getQuestionId(),
109  'cmd' => $this->testrequest->raw('cmd'),
110  'cmdClass' => $this->testrequest->raw('cmdClass'),
111  'baseClass' => 'ilObjQuestionPoolGUI',
112  'test_express_mode' => '1'
113  ];
114 
116  'ilias.php' . ilUtil::appendUrlParameterString(
117  '?' . http_build_query($params, null, '&'),
118  'cmdNode=' . ($nodeParts[count($nodeParts) - 2] . ':' . $nodeParts[count($nodeParts) - 1])
119  )
120  );
121 
122  break;
123 
124  case 'ilpageeditorgui':
125 
126  if (!$this->getEnableEditing()) {
127  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
128  $this->ctrl->redirect($this, 'preview');
129  }
130 
131  $page_editor = new ilPageEditorGUI($this->getPageObject(), $this);
132  //$page_editor->setLocator($this->locator);
133  $page_editor->setHeader($this->getHeader());
134  $page_editor->setPageBackTitle($this->page_back_title);
135  $page_editor->setIntLinkReturn($this->int_link_return);
136 
137  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
138 
139  $ret = $this->ctrl->forwardCommand($page_editor);
140  if ($ret != '') {
141  $this->tpl->setContent($ret);
142  }
143  break;
144 
145  case '':
146  case 'iltestexpresspageobjectgui':
147  if ($cmd == 'view') {
148  $cmd = 'showPage';
149  $this->ctrl->setCmd($cmd);
150  }
151 
152  $q_gui = assQuestionGUI::_getQuestionGUI('', (int) $this->testrequest->raw('q_id'));
153 
154  if ($q_gui->object) {
155  $obj = ilObjectFactory::getInstanceByRefId((int) $this->testrequest->getRefId());
156  $q_gui->object->setObjId($obj->getId());
157  }
158 
159  $cmds = [
160  'handleToolbarCommand',
161  'addQuestion',
162  'questions',
163  'insertQuestions',
164  'browseForQuestions',
165  'filterAvailableQuestions',
166  'resetfilterAvailableQuestions'
167  ];
168 
169  if (in_array($cmd, $cmds)) {
170  return $this->$cmd();
171  } elseif ($q_gui->object) {
172  $total = $this->test_object->evalTotalPersons();
173 
175 
176  if ($total != 0) {
177  $link = $DIC->ui()->factory()->link()->standard(
178  $DIC->language()->txt('test_has_datasets_warning_page_view_link'),
179  $DIC->ctrl()->getLinkTargetByClass(['ilTestResultsGUI', 'ilParticipantsTestResultsGUI'])
180  );
181 
182  $message = $DIC->language()->txt('test_has_datasets_warning_page_view');
183 
184  $msgBox = $DIC->ui()->factory()->messageBox()->info($message)->withLinks([$link]);
185 
186  $DIC->ui()->mainTemplate()->setCurrentBlock('mess');
187  $DIC->ui()->mainTemplate()->setVariable(
188  'MESSAGE',
189  $DIC->ui()->renderer()->render($msgBox)
190  );
191  $DIC->ui()->mainTemplate()->parseCurrentBlock();
192  }
193 
194  if ((in_array($cmd, ['view', 'showPage']) || $cmd == 'edit') && $this->test_object->evalTotalPersons()) {
195  return $this->showPage();
196  }
197 
198  return parent::executeCommand();
199  }
200 
201  break;
202 
203  default:
204  $type = ilObjQuestionPool::getQuestionTypeByTypeId(ilUtil::stripSlashes((string) $this->testrequest->raw('qtype')));
205 
206  if (!$this->testrequest->raw('q_id')) {
207  $q_gui = $this->addPageOfQuestions(preg_replace('/(.*?)gui/i', '$1', $this->testrequest->raw('sel_question_types')));
208  $q_gui->setQuestionTabs();
209 
210  $this->ctrl->forwardCommand($q_gui);
211  break;
212  }
213 
214  $this->ctrl->setReturn($this, 'questions');
215 
216  $q_gui = assQuestionGUI::_getQuestionGUI($type, (int) $this->testrequest->raw('q_id'));
217  if ($q_gui->object) {
218  $obj = ilObjectFactory::getInstanceByRefId((int) $this->testrequest->getRefId());
219  $q_gui->object->setObjId($obj->getId());
220  }
221 
222  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_id');
223  $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
224 
225  $q_gui->setQuestionTabs();
226  $this->ctrl->forwardCommand($q_gui);
227  break;
228  }
229  return '';
230  }
231 
232  public function addPageOfQuestions($type = ''): assQuestionGUI
233  {
234  if (!$type) {
235  $qtype = $this->testrequest->raw('qtype');
236  $pool = new ilObjQuestionPool();
238  }
239 
240  $this->ctrl->setReturn($this, 'questions');
241 
242  $q_gui = assQuestionGUI::_getQuestionGUI($type);
243 
244  $obj = ilObjectFactory::getInstanceByRefId($this->testrequest->getRefId());
245 
246  $q_gui->object->setObjId($obj->getId());
247 
248  return $q_gui;
249  }
250 
251  public function handleToolbarCommand()
252  {
253  if ($this->testrequest->raw('qtype')) {
254  $questionType = ilObjQuestionPool::getQuestionTypeByTypeId($this->testrequest->raw('qtype'));
255  } elseif ($this->testrequest->raw('sel_question_types')) {
256  $questionType = $this->testrequest->raw('sel_question_types');
257  }
258 
260  $addContEditMode = $this->testrequest->raw('add_quest_cont_edit_mode');
261  } else {
263  }
264 
265  $q_gui = assQuestionGUI::_getQuestionGUI($questionType);
266 
267  $q_gui->object->setObjId(ilObject::_lookupObjectId($this->testrequest->getRefId()));
268  $q_gui->object->setAdditionalContentEditingMode($addContEditMode);
269 
270  $q_gui->object->createNewQuestion();
271 
272  $previousQuestionId = $this->testrequest->raw('position');
273 
274  switch ($this->testrequest->raw('usage')) {
275  case 3: // existing pool
276 
277  $this->ctrl->setParameterByClass('ilobjtestgui', 'sel_qpl', $this->testrequest->raw('sel_qpl'));
278  $this->ctrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
279  $this->ctrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
280  $this->ctrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
281 
282  if ($this->testrequest->raw('test_express_mode')) {
283  $this->ctrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
284  }
285 
286  if ($this->testrequest->isset('add_quest_cont_edit_mode')) {
287  $this->ctrl->setParameterByClass(
288  'ilobjtestgui',
289  'add_quest_cont_edit_mode',
290  $this->testrequest->raw('add_quest_cont_edit_mode')
291  );
292  }
293 
294  $this->ctrl->setParameterByClass('ilobjtestgui', 'usage', 3);
295  $this->ctrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
296 
297  $link = $this->ctrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
298 
300 
301  break;
302 
303  case 2: // new pool
304 
305  $this->ctrl->setParameterByClass('ilobjtestgui', 'txt_qpl', $this->testrequest->raw('txt_qpl'));
306  $this->ctrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
307  $this->ctrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
308  $this->ctrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
309 
310  if ($this->testrequest->raw('test_express_mode')) {
311  $this->ctrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
312  }
313 
314  if ($this->testrequest->isset('add_quest_cont_edit_mode')) {
315  $this->ctrl->setParameterByClass(
316  'ilobjtestgui',
317  'add_quest_cont_edit_mode',
318  $this->testrequest->raw('add_quest_cont_edit_mode')
319  );
320  }
321 
322  $this->ctrl->setParameterByClass('ilobjtestgui', 'usage', 2);
323  $this->ctrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
324 
325  $link = $this->ctrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
327 
328  break;
329 
330  case 1: // no pool
331  default:
332 
333  $this->redirectToQuestionEditPage($questionType, $q_gui->object->getId(), $previousQuestionId);
334 
335  break;
336  }
337  }
338 
339  public function addQuestion(): string
340  {
341  $subScreenId = ['createQuestion'];
342 
343  $this->ctrl->setParameter($this, 'qtype', $this->testrequest->raw('qtype'));
344 
345  $form = new ilPropertyFormGUI();
346 
347  $this->ctrl->setParameter($this, 'test_express_mode', 1);
348 
349  $form->setFormAction($this->ctrl->getFormAction($this, 'handleToolbarCommand'));
350  $form->setTitle($this->lng->txt('ass_create_question'));
351 
352  $pool = new ilObjQuestionPool();
353  $questionTypes = $pool->getQuestionTypes(false, true, false);
354  $options = [];
355 
356  // question type
357  foreach ($questionTypes as $label => $data) {
358  $options[$data['question_type_id']] = $label;
359  }
360 
361  $si = new ilSelectInputGUI($this->lng->txt('question_type'), 'qtype');
362  $si->setOptions($options);
363  $form->addItem($si, true);
364 
365  // position
366  $questions = $this->test_object->getQuestionTitlesAndIndexes();
367  if ($questions) {
368  $si = new ilSelectInputGUI($this->lng->txt('position'), 'position');
369  $options = ['0' => $this->lng->txt('first')];
370  foreach ($questions as $key => $title) {
371  $options[$key] = $this->lng->txt('behind') . ' ' . $title . ' [' . $this->lng->txt('question_id_short') . ': ' . $key . ']';
372  }
373  $si->setOptions($options);
374  $si->setValue($this->testrequest->raw('q_id'));
375  $form->addItem($si, true);
376  }
377 
378  // content editing mode
380  $subScreenId[] = 'editMode';
381 
382  $ri = new ilRadioGroupInputGUI($this->lng->txt('tst_add_quest_cont_edit_mode'), 'add_quest_cont_edit_mode');
383 
384  $option_ipe = new ilRadioOption(
385  $this->lng->txt('tst_add_quest_cont_edit_mode_IPE'),
387  );
388  $option_ipe->setInfo($this->lng->txt('tst_add_quest_cont_edit_mode_IPE_info'));
389  $ri->addOption($option_ipe);
390 
391  $option_rte = new ilRadioOption(
392  $this->lng->txt('tst_add_quest_cont_edit_mode_RTE'),
394  );
395  $option_rte->setInfo($this->lng->txt('tst_add_quest_cont_edit_mode_RTE_info'));
396  $ri->addOption($option_rte);
397 
399 
400  $form->addItem($ri, true);
401  } else {
402  $hi = new ilHiddenInputGUI('question_content_editing_type');
404  $form->addItem($hi, true);
405  }
406 
407  $subScreenId[] = 'poolSelect';
408 
409  // use pool
410  $usage = new ilRadioGroupInputGUI($this->lng->txt('assessment_pool_selection'), 'usage');
411  $usage->setRequired(true);
412  $no_pool = new ilRadioOption($this->lng->txt('assessment_no_pool'), '1');
413  $usage->addOption($no_pool);
414  $existing_pool = new ilRadioOption($this->lng->txt('assessment_existing_pool'), '3');
415  $usage->addOption($existing_pool);
416  $new_pool = new ilRadioOption($this->lng->txt('assessment_new_pool'), '2');
417  $usage->addOption($new_pool);
418  $form->addItem($usage);
419 
420  $usage->setValue(1);
421 
422  $questionpools = ilObjQuestionPool::_getAvailableQuestionpools(false, false, true, false, false, 'write');
423  $pools_data = [];
424  foreach ($questionpools as $key => $p) {
425  $pools_data[$key] = $p['title'];
426  }
427  $pools = new ilSelectInputGUI($this->lng->txt('select_questionpool'), 'sel_qpl');
428  $pools->setOptions($pools_data);
429  $existing_pool->addSubItem($pools);
430 
431  $name = new ilTextInputGUI($this->lng->txt('name'), 'txt_qpl');
432  $name->setSize(50);
433  $name->setMaxLength(50);
434  $new_pool->addSubItem($name);
435 
436  $form->addCommandButton('handleToolbarCommand', $this->lng->txt('create'));
437  $form->addCommandButton('questions', $this->lng->txt('cancel'));
438 
439  $this->help->setSubScreenId(implode('_', $subScreenId));
440 
441  return $form->getHTML();
442  }
443 
444  public function questions()
445  {
446  $this->ctrl->saveParameterByClass('ilobjtestgui', 'q_id');
447  $this->ctrl->redirectByClass('ilobjtestgui', 'showPage');
448  }
449 
450  private function redirectToQuestionEditPage($questionType, $qid, $prev_qid)
451  {
452  $cmdClass = $questionType . 'GUI';
453 
454  $this->ctrl->setParameterByClass($cmdClass, 'ref_id', $this->testrequest->getRefId());
455  $this->ctrl->setParameterByClass($cmdClass, 'sel_question_types', $questionType);
456  $this->ctrl->setParameterByClass($cmdClass, 'test_ref_id', $this->testrequest->getRefId());
457  $this->ctrl->setParameterByClass($cmdClass, 'calling_test', $this->testrequest->getRefId());
458  $this->ctrl->setParameterByClass($cmdClass, 'q_id', $qid);
459  $this->ctrl->setParameterByClass($cmdClass, 'prev_qid', $prev_qid);
460 
461  if ($this->testrequest->raw('test_express_mode')) {
462  $this->ctrl->setParameterByClass($cmdClass, 'test_express_mode', 1);
463  }
464 
465  $this->ctrl->redirectByClass(
466  ['ilRepositoryGUI', 'ilObjTestGUI', $questionType . 'GUI'],
467  'editQuestion'
468  );
469  }
470 
471  private function redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid)
472  {
473  $this->ctrl->setParameterByClass('ilObjTestGUI', 'ref_id', $this->testrequest->getRefId());
474  $this->ctrl->setParameterByClass('ilObjTestGUI', 'q_id', $qid);
475  $this->ctrl->setParameterByClass('ilObjTestGUI', 'sel_question_types', $questionType);
476  $this->ctrl->setParameterByClass('ilObjTestGUI', 'prev_qid', $prev_qid);
477  $redir = $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'createQuestion', '', false, false);
478 
479  ilUtil::redirect($redir);
480  }
481 
482  public function insertQuestions()
483  {
484  $selected_array = (is_array($_POST['q_id'])) ? $_POST['q_id'] : [];
485  if (!count($selected_array)) {
486  $this->tpl->setOnScreenMessage('info', $this->lng->txt('tst_insert_missing_question'), true);
487  $this->ctrl->redirect($this, 'browseForQuestions');
488  } else {
489  $manscoring = false;
490 
491  $test_question_set_config_factory = new ilTestQuestionSetConfigFactory(
492  $this->tree,
493  $this->db,
494  $this->lng,
495  $this->log,
496  $this->component_repository,
497  $this->test_object,
498  $this->questioninfo
499  );
500  $test_question_set_config = $test_question_set_config_factory->getQuestionSetConfig();
501 
502  foreach ($selected_array as $key => $value) {
503  $last_question_id = $this->test_object->insertQuestion($test_question_set_config, $value);
504 
505  if (!$manscoring) {
506  $manscoring = $manscoring | assQuestion::_needsManualScoring($value);
507  }
508  }
509  $this->test_object->saveCompleteStatus($test_question_set_config);
510  if ($manscoring) {
511  $this->tpl->setOnScreenMessage('info', $this->lng->txt('manscoring_hint'), true);
512  } else {
513  $this->tpl->setOnScreenMessage('success', $this->lng->txt('tst_questions_inserted'), true);
514  }
515 
516  $this->ctrl->setParameter($this, 'q_id', $last_question_id);
517  $this->ctrl->redirect($this, 'showPage');
518  return;
519  }
520  }
521 }
__construct($a_id=0, $a_old_nr=0, $test_object=null)
const ADDITIONAL_CONTENT_EDITING_MODE_IPE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Readable part of repository interface to ilComponentDataDB.
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
This class represents a selection list property in a property form.
setOutputMode(string $a_mode=self::PRESENTATION)
static _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(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
setInfo(string $a_info)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static getQuestionTypeByTypeId($type_id)
setOptions(array $a_options)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getQuestionGUI(string $question_type='', int $question_id=-1)
Creates a question gui representation and returns the alias to the question gui.
Page Editor GUI class.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _needsManualScoring(int $question_id)
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
setFormAction(string $a_formaction)
ILIAS COPage Link LinkManager $link
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
string $key
Consumer key/client ID value.
Definition: System.php:193
static _lookupObjectId(int $ref_id)
Basic GUI class for assessment questions.
setRequired(bool $a_required)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
static redirect(string $a_script)
const ADDITIONAL_CONTENT_EDITING_MODE_RTE
redirectToQuestionEditPage($questionType, $qid, $prev_qid)
static isAdditionalQuestionContentEditingModePageObjectEnabled()
Returns the fact wether content editing with ilias page editor is enabled for questions or not...
$message
Definition: xapiexit.php:32
ilPropertyFormGUI $form
redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid)
ilTestExpressPageObjectGUI: assMultipleChoiceGUI, assClozeTestGUI, assMatchingQuestionGUI ilTestExpr...