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