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