ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
4include_once "./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php";
5include_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 !== false) {
34 $next = $questions[$pos + 1];
35 } else {
36 $next = $questions[0];
37 }
38
39 $this->ctrl->setParameter($this, 'q_id', $next);
40 $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
41
42 ilUtil::redirect($link);
43 }
44
45 public function prevQuestion()
46 {
47 $obj = new ilObjTest($_REQUEST['ref_id']);
48 $questions = array_keys($obj->getQuestionTitlesAndIndexes());
49
50 $pos = array_search($_REQUEST['q_id'], $questions);
51
52 if ($pos !== false) {
53 $next = $questions[$pos - 1];
54 } else {
55 $next = $questions[0];
56 }
57
58 $this->ctrl->setParameter($this, 'q_id', $next);
59 $link = $this->ctrl->getLinkTarget($this, 'edit', '', '', false);
60
61 ilUtil::redirect($link);
62 }
63
64 public function __construct($a_id = 0, $a_old_nr = 0)
65 {
66 parent::__construct($a_id, $a_old_nr);
67 }
68
69 public function executeCommand()
70 {
71 global $DIC; /* @var ILIAS\DI\Container $DIC */
72 $ilCtrl = $DIC['ilCtrl'];
73 $ilTabs = $DIC['ilTabs'];
74 $ilUser = $DIC['ilUser'];
75 $lng = $DIC['lng'];
76
77 $next_class = $this->ctrl->getNextClass($this);
78 $cmd = $this->ctrl->getCmd();
79
80 switch ($next_class) {
81 case 'ilobjquestionpoolgui':
82
83 $nodeParts = explode(':', $_GET['cmdNode']);
84
85 $params = array(
86 'ref_id' => $_GET['ref_id'],
87 'calling_test' => $_GET['ref_id'],
88 'q_id' => $_GET['q_id'],
89 'cmd' => $_GET['cmd'],
90 'cmdClass' => $_GET['cmdClass'],
91 'baseClass' => 'ilObjQuestionPoolGUI',
92 'test_express_mode' => '1'
93 );
94
97 '?' . http_build_query($params, null, '&'),
98 'cmdNode=' . ($nodeParts[count($nodeParts) - 2] . ':' . $nodeParts[count($nodeParts) - 1])
99 )
100 );
101
102 break;
103
104 case "ilpageeditorgui":
105
106 if (!$this->getEnableEditing()) {
107 ilUtil::sendFailure($lng->txt("permission_denied"), true);
108 $ilCtrl->redirect($this, "preview");
109 }
110
111 $page_editor = new ilPageEditorGUI($this->getPageObject(), $this);
112 $page_editor->setLocator($this->locator);
113 $page_editor->setHeader($this->getHeader());
114 $page_editor->setPageBackTitle($this->page_back_title);
115 $page_editor->setIntLinkReturn($this->int_link_return);
116
117 $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
118
119 $ret = &$this->ctrl->forwardCommand($page_editor);
120
121 break;
122
123 case '':
124 case 'iltestexpresspageobjectgui':
125
126 include_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
127
128 if ($cmd == 'view') {
129 $cmd = 'showPage';
130 $ilCtrl->setCmd($cmd);
131 }
132
133 $q_gui = assQuestionGUI::_getQuestionGUI('', (int) $_REQUEST["q_id"]);
134
135 if ($q_gui->object) {
136 $obj = ilObjectFactory::getInstanceByRefId((int) $_REQUEST['ref_id']);
137 $q_gui->object->setObjId($obj->getId());
138 }
139
140 $cmds = array(
141 'handleToolbarCommand',
142 'addQuestion',
143 'questions',
144 'insertQuestions',
145 'browseForQuestions',
146 'filterAvailableQuestions',
147 'resetfilterAvailableQuestions'
148 );
149
150 if (in_array($cmd, $cmds)) {
151 return $this->$cmd();
152 } elseif ($q_gui->object) {
153 $total = $this->test_object->evalTotalPersons();
154
156
157 if ($total != 0) {
158 $link = $DIC->ui()->factory()->link()->standard(
159 $DIC->language()->txt("test_has_datasets_warning_page_view_link"),
160 $DIC->ctrl()->getLinkTargetByClass(array('ilTestResultsGUI', 'ilParticipantsTestResultsGUI'))
161 );
162
163 $message = $DIC->language()->txt("test_has_datasets_warning_page_view");
164
165 $msgBox = $DIC->ui()->factory()->messageBox()->info($message)->withLinks(array($link));
166
167 $DIC->ui()->mainTemplate()->setCurrentBlock('mess');
168 $DIC->ui()->mainTemplate()->setVariable(
169 'MESSAGE',
170 $DIC->ui()->renderer()->render($msgBox)
171 );
172 $DIC->ui()->mainTemplate()->parseCurrentBlock();
173 }
174
175 if ((in_array($cmd, array('view', 'showPage')) || $cmd == 'edit') && $this->test_object->evalTotalPersons()) {
176 return $this->showPage();
177 }
178
179 return parent::executeCommand();
180 }
181
182 break;
183
184 default:
186
187 if (!$_GET['q_id']) {
188 $q_gui = $this->addPageOfQuestions(preg_replace('/(.*?)gui/i', '$1', $_GET['sel_question_types']));
189 $q_gui->setQuestionTabs();
190
191 $this->ctrl->forwardCommand($q_gui);
192 break;
193 }
194
195 $this->ctrl->setReturn($this, "questions");
196
197 require_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
198 $q_gui = assQuestionGUI::_getQuestionGUI($type, (int) $_GET['q_id']);
199 if ($q_gui->object) {
201 $q_gui->object->setObjId($obj->getId());
202 }
203
204 $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_id');
205 $this->ctrl->saveParameterByClass('ilpageeditorgui', 'q_mode');
206
207 $q_gui->setQuestionTabs();
208 $this->ctrl->forwardCommand($q_gui);
209 break;
210 }
211 }
212
213 public function addPageOfQuestions($type = '')
214 {
215 global $DIC;
216 $ilCtrl = $DIC['ilCtrl'];
217
218 if (!$type) {
219 $qtype = $_REQUEST['qtype'];
220 $pool = new ilObjQuestionPool();
222 }
223
224 $this->ctrl->setReturn($this, "questions");
225
226 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
228
230
231 $q_gui->object->setObjId($obj->getId());
232
233 return $q_gui;
234 }
235
236 public function handleToolbarCommand()
237 {
238 global $DIC;
239 $ilCtrl = $DIC['ilCtrl'];
240
241 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
242
243 if ($_REQUEST['qtype']) {
244 include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
245 $questionType = ilObjQuestionPool::getQuestionTypeByTypeId($_REQUEST['qtype']);
246 } elseif ($_REQUEST['sel_question_types']) {
247 $questionType = $_REQUEST['sel_question_types'];
248 }
249
250 include_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
252 $addContEditMode = $_REQUEST['add_quest_cont_edit_mode'];
253 } else {
255 }
256
257 $q_gui = &assQuestionGUI::_getQuestionGUI($questionType);
258
259 $q_gui->object->setObjId(ilObject::_lookupObjectId($_GET['ref_id']));
260 $q_gui->object->setAdditionalContentEditingMode($addContEditMode);
261
262 $q_gui->object->createNewQuestion();
263
264 $previousQuestionId = $_REQUEST['position'];
265
266 switch ($_REQUEST['usage']) {
267 case 3: // existing pool
268
269 $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_qpl', $_REQUEST['sel_qpl']);
270 $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
271 $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
272 $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
273
274 if ($_REQUEST['test_express_mode']) {
275 $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
276 }
277
278 if (isset($_REQUEST['add_quest_cont_edit_mode'])) {
279 $ilCtrl->setParameterByClass(
280 'ilobjtestgui',
281 'add_quest_cont_edit_mode',
282 $_REQUEST['add_quest_cont_edit_mode']
283 );
284 }
285
286 $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 3);
287 $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
288
289 $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
290
291 ilUtil::redirect($link);
292
293 break;
294
295 case 2: // new pool
296
297 $ilCtrl->setParameterByClass('ilobjtestgui', 'txt_qpl', $_REQUEST['txt_qpl']);
298 $ilCtrl->setParameterByClass('ilobjtestgui', 'sel_question_types', $questionType);
299 $ilCtrl->setParameterByClass('ilobjtestgui', 'q_id', $q_gui->object->getId());
300 $ilCtrl->setParameterByClass('ilobjtestgui', 'prev_qid', $previousQuestionId);
301
302 if ($_REQUEST['test_express_mode']) {
303 $ilCtrl->setParameterByClass('ilobjtestgui', 'test_express_mode', 1);
304 }
305
306 if (isset($_REQUEST['add_quest_cont_edit_mode'])) {
307 $ilCtrl->setParameterByClass(
308 'ilobjtestgui',
309 'add_quest_cont_edit_mode',
310 $_REQUEST['add_quest_cont_edit_mode']
311 );
312 }
313
314 $ilCtrl->setParameterByClass('ilobjtestgui', 'usage', 2);
315 $ilCtrl->setParameterByClass('ilobjtestgui', 'calling_test', $this->test_object->getId());
316
317 $link = $ilCtrl->getLinkTargetByClass('ilobjtestgui', 'executeCreateQuestion', false, false, false);
318 ilUtil::redirect($link);
319
320 break;
321
322 case 1: // no pool
323 default:
324
325 $this->redirectToQuestionEditPage($questionType, $q_gui->object->getId(), $previousQuestionId);
326
327 break;
328 }
329 }
330
331 public function addQuestion()
332 {
333 global $DIC;
334 $lng = $DIC['lng'];
335 $ilCtrl = $DIC['ilCtrl'];
336 $tpl = $DIC['tpl'];
337 global $DIC; /* @var \ILIAS\DI\Container $DIC */
338 $ilHelp = $DIC['ilHelp']; /* @var ilHelpGUI $ilHelp */
339
340 $subScreenId = array('createQuestion');
341
342 include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
343
344 $ilCtrl->setParameter($this, 'qtype', $_REQUEST['qtype']);
345
346 $form = new ilPropertyFormGUI();
347
348 $ilCtrl->setParameter($this, 'test_express_mode', 1);
349
350 $form->setFormAction($ilCtrl->getFormAction($this, "handleToolbarCommand"));
351 $form->setTitle($lng->txt("ass_create_question"));
352 include_once 'Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
353
354 $pool = new ilObjQuestionPool();
355 $questionTypes = $pool->getQuestionTypes(false, true, false);
356 $options = array();
357
358 // question type
359 foreach ($questionTypes as $label => $data) {
360 $options[$data['question_type_id']] = $label;
361 }
362
363 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
364 $si = new ilSelectInputGUI($lng->txt("question_type"), "qtype");
365 $si->setOptions($options);
366 $form->addItem($si, true);
367
368 // position
369 $questions = $this->test_object->getQuestionTitlesAndIndexes();
370 if ($questions) {
371 $si = new ilSelectInputGUI($lng->txt("position"), "position");
372 $options = array('0' => $lng->txt('first'));
373 foreach ($questions as $key => $title) {
374 $options[$key] = $lng->txt('behind') . ' ' . $title . ' [' . $this->lng->txt('question_id_short') . ': ' . $key . ']';
375 }
376 $si->setOptions($options);
377 $si->setValue($_REQUEST['q_id']);
378 $form->addItem($si, true);
379 }
380
381 // content editing mode
383 $subScreenId[] = 'editMode';
384
385 $ri = new ilRadioGroupInputGUI($lng->txt("tst_add_quest_cont_edit_mode"), "add_quest_cont_edit_mode");
386
387 $ri->addOption(new ilRadioOption(
388 $lng->txt('tst_add_quest_cont_edit_mode_default'),
390 ));
391
392 $ri->addOption(new ilRadioOption(
393 $lng->txt('tst_add_quest_cont_edit_mode_page_object'),
395 ));
396
398
399 $form->addItem($ri, true);
400 } else {
401 $hi = new ilHiddenInputGUI("question_content_editing_type");
403 $form->addItem($hi, true);
404 }
405
406 if ($this->test_object->getPoolUsage()) {
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 = array();
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
437 $form->addCommandButton("handleToolbarCommand", $lng->txt("create"));
438 $form->addCommandButton("questions", $lng->txt("cancel"));
439
440 $ilHelp->setSubScreenId(implode('_', $subScreenId));
441
442 return $tpl->setContent($form->getHTML());
443 }
444
445 public function questions()
446 {
447 global $DIC;
448 $ilCtrl = $DIC['ilCtrl'];
449
450 $ilCtrl->saveParameterByClass('ilobjtestgui', 'q_id');
451
452 $ilCtrl->redirectByClass('ilobjtestgui', 'showPage');
453 }
454
455 private function redirectToQuestionEditPage($questionType, $qid, $prev_qid)
456 {
457 $cmdClass = $questionType . 'GUI';
458
459 $this->ctrl->setParameterByClass($cmdClass, 'ref_id', $_GET['ref_id']);
460 $this->ctrl->setParameterByClass($cmdClass, 'sel_question_types', $questionType);
461 $this->ctrl->setParameterByClass($cmdClass, 'test_ref_id', $_GET['ref_id']);
462 $this->ctrl->setParameterByClass($cmdClass, 'calling_test', $_GET['ref_id']);
463 $this->ctrl->setParameterByClass($cmdClass, 'q_id', $qid);
464 $this->ctrl->setParameterByClass($cmdClass, 'prev_qid', $prev_qid);
465
466 if ($_REQUEST['test_express_mode']) {
467 $this->ctrl->setParameterByClass($cmdClass, 'test_express_mode', 1);
468 }
469
470 $this->ctrl->redirectByClass(
471 array('ilRepositoryGUI', 'ilObjTestGUI', $questionType . "GUI"),
472 'editQuestion'
473 );
474 }
475
476 private function redirectToQuestionPoolSelectionPage($questionType, $qid, $prev_qid)
477 {
478 $this->ctrl->setParameterByClass('ilObjTestGUI', 'ref_id', $_REQUEST['ref_id']);
479 $this->ctrl->setParameterByClass('ilObjTestGUI', 'q_id', $qid);
480 $this->ctrl->setParameterByClass('ilObjTestGUI', 'sel_question_types', $questionType);
481 $this->ctrl->setParameterByClass('ilObjTestGUI', 'prev_qid', $prev_qid);
482 $redir = $this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'createQuestion', '', false, false);
483
484 ilUtil::redirect($redir);
485 }
486
487 public function insertQuestions()
488 {
489 $selected_array = (is_array($_POST['q_id'])) ? $_POST['q_id'] : array();
490 if (!count($selected_array)) {
491 ilUtil::sendInfo($this->lng->txt("tst_insert_missing_question"), true);
492 $this->ctrl->redirect($this, "browseForQuestions");
493 } else {
494 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
495 $manscoring = false;
496
497 global $DIC;
498 $tree = $DIC['tree'];
499 $ilDB = $DIC['ilDB'];
500 $ilPluginAdmin = $DIC['ilPluginAdmin'];
501
502 require_once 'Modules/Test/classes/class.ilTestQuestionSetConfigFactory.php';
503 $testQuestionSetConfigFactory = new ilTestQuestionSetConfigFactory($tree, $ilDB, $ilPluginAdmin, $this->test_object);
504 $testQuestionSetConfig = $testQuestionSetConfigFactory->getQuestionSetConfig();
505
506 foreach ($selected_array as $key => $value) {
507 $last_question_id = $this->test_object->insertQuestion($testQuestionSetConfig, $value);
508
509 if (!$manscoring) {
510 $manscoring = $manscoring | assQuestion::_needsManualScoring($value);
511 }
512 }
513 $this->test_object->saveCompleteStatus($testQuestionSetConfig);
514 if ($manscoring) {
515 ilUtil::sendInfo($this->lng->txt("manscoring_hint"), true);
516 } else {
517 ilUtil::sendSuccess($this->lng->txt("tst_questions_inserted"), true);
518 }
519
520 $this->ctrl->setParameter($this, 'q_id', $last_question_id);
521 $this->ctrl->redirect($this, "showPage");
522 return;
523 }
524 }
525}
$total
Definition: Utf8Test.php:87
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
const IL_PAGE_EDIT
const IL_PAGE_PREVIEW
static _getQuestionGUI($question_type, $question_id=-1)
Creates a question gui representation and returns the alias to the question gui note: please do not u...
const ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT
constant for additional content editing mode "default"
static _needsManualScoring($question_id)
const ADDITIONAL_CONTENT_EDITING_MODE_PAGE_OBJECT
constant for additional content editing mode "pageobject"
Question page GUI class.
showPage()
display content of page
This class represents a hidden form property in a property form.
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($a_ref_id, $stop_on_error=true)
get an instance of an Ilias object by reference id
static _lookupObjectId($a_ref_id)
lookup object id
Page Editor GUI class.
getPageObject()
Get Page Object.
setOutputMode($a_mode=IL_PAGE_PRESENTATION)
Set Output Mode.
getEnableEditing()
Get Enable Editing.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
@ilCtrl_Calls ilTestExpressPageObjectGUI: assMultipleChoiceGUI, assClozeTestGUI, assMatchingQuestionG...
__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 appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$key
Definition: croninfo.php:18
global $ilCtrl
Definition: ilias.php:18
catch(Exception $e) $message
$ret
Definition: parser.php:6
$type
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18
$data
Definition: bench.php:6