ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilPCQuestionGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\Test\Settings\GlobalSettings\Repository as TestSettingsRepository;
20
27{
28 protected \ILIAS\TestQuestionPool\Questions\PublicInterface $questioninfo;
30 protected int $scormlmid;
31 protected bool $selfassessmentmode;
33 protected ilTabsGUI $tabs;
34 protected ilObjUser $user;
35 protected ilTree $tree;
38
39 public function __construct(
40 ilPageObject $a_pg_obj,
41 ?ilPageContent $a_content_obj,
42 string $a_hier_id,
43 string $a_pc_id = ""
44 ) {
45 global $DIC;
46
47 $this->ctrl = $DIC->ctrl();
48 $this->access = $DIC->access();
49 $this->tpl = $DIC["tpl"];
50 $this->tabs = $DIC->tabs();
51 $this->lng = $DIC->language();
52 $this->user = $DIC->user();
53 $this->tree = $DIC->repositoryTree();
54 $this->toolbar = $DIC->toolbar();
55 $ilCtrl = $DIC->ctrl();
56 $this->scormlmid = $a_pg_obj->parent_id;
57 $this->questioninfo = $DIC->testQuestion();
58 $this->ipe_for_questions_enabled = (bool) $DIC['ilSetting']->get('enable_tst_page_edit', false);
59 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
60 $ilCtrl->saveParameter($this, array("qpool_ref_id"));
61 }
62
67 public function executeCommand()
68 {
69 $ilCtrl = $this->ctrl;
70
71 // get current command
72 $cmd = $ilCtrl->getCmd();
73 $next_class = $ilCtrl->getNextClass($this);
74
75 switch ($next_class) {
76 default:
77 //set tabs
78 if ($cmd != "insert") {
79 $this->setTabs();
80 } elseif ($this->sub_command != "") {
81 $cmd = $this->sub_command;
82 }
83
84 if ($cmd === 'create_pcqst') {
85 return $this->create();
86 }
87
88 $ret = $this->$cmd();
89 }
90
91 return $ret;
92 }
93
94 public function setSelfAssessmentMode(bool $a_selfassessmentmode): void
95 {
96 $this->selfassessmentmode = $a_selfassessmentmode;
97 }
98
99 public function getSelfAssessmentMode(): bool
100 {
102 }
103
104 public function setInsertTabs(string $a_active): void
105 {
106 $ilTabs = $this->tabs;
107 $ilCtrl = $this->ctrl;
109
110 // new question
111 $ilTabs->addSubTab(
112 "new_question",
113 $lng->txt("cont_new_question"),
114 $ilCtrl->getLinkTarget($this, "insert")
115 );
116
117 // copy from pool
118 $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
119 $ilTabs->addSubTab(
120 "copy_question",
121 $lng->txt("cont_copy_question_from_pool"),
122 $ilCtrl->getLinkTarget($this, "insert")
123 );
124
125 $ilTabs->activateSubTab($a_active);
126
127 $ilCtrl->setParameter($this, "subCmd", "");
128 }
129
133 public function insert(string $a_mode = "create"): void
134 {
136 $ilCtrl = $this->ctrl;
137
138 $this->setInsertTabs("new_question");
139
140 $this->displayValidationError();
141
142 // get all question types (@todo: we have to check, whether they are
143 // suitable for self assessment or not)
145 $options = array();
146 $all_types = ilArrayUtil::sortArray($all_types, "order", "asc", true, true);
147
148 foreach ($all_types as $k => $v) {
149 $options[$v["type_tag"]] = $k;
150 }
151
152 // new table form (input of rows and columns)
153 $this->form_gui = new ilPropertyFormGUI();
154 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
155 $this->form_gui->setTitle($lng->txt("cont_ed_insert_pcqst"));
156
157 // Select Question Type
158 $qtype_input = new ilSelectInputGUI($lng->txt("cont_question_type"), "q_type");
159 $qtype_input->setOptions($options);
160 $qtype_input->setRequired(true);
161 $this->form_gui->addItem($qtype_input);
162
163 // additional content editor
164 // assessment
165 if ($this->ipe_for_questions_enabled) {
166 $ri = new ilRadioGroupInputGUI($this->lng->txt("tst_add_quest_cont_edit_mode"), "add_quest_cont_edit_mode");
167
168 $option_rte = new ilRadioOption(
169 $this->lng->txt('tst_add_quest_cont_edit_mode_plain'),
171 );
172 $option_rte->setInfo($this->lng->txt('tst_add_quest_cont_edit_mode_plain_info'));
173 $ri->addOption($option_rte);
174
175 $option_ipe = new ilRadioOption(
176 $this->lng->txt('tst_add_quest_cont_edit_mode_IPE'),
178 );
179 $option_ipe->setInfo($this->lng->txt('tst_add_quest_cont_edit_mode_IPE_info'));
180 $ri->addOption($option_ipe);
181
183
184 $this->form_gui->addItem($ri);
185 } else {
186 $hi = new ilHiddenInputGUI("question_content_editing_type");
188 $this->form_gui->addItem($hi);
189 }
190
191 if ($a_mode == "edit_empty") {
192 $this->form_gui->addCommandButton("edit", $lng->txt("save"));
193 } else {
194 $this->form_gui->addCommandButton("create_pcqst", $lng->txt("save"));
195 $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
196 }
197
198 $this->tpl->setContent($this->form_gui->getHTML());
199 }
200
201
205 public function create(): void
206 {
207 global $ilCtrl, $ilTabs;
208
209 $ilTabs->setTabActive('question');
210
211 $this->content_obj = new ilPCQuestion($this->getPage());
212 $this->content_obj->create($this->pg_obj, $this->hier_id);
213
214 $this->updated = $this->pg_obj->update();
215
216 if ($this->updated) {
217 $this->pg_obj->stripHierIDs();
218 $this->pg_obj->addHierIDs();
219 $ilCtrl->setParameter(
220 $this,
221 "q_type",
222 $this->request->getString("q_type")
223 );
224 $ilCtrl->setParameter(
225 $this,
226 "add_quest_cont_edit_mode",
227 $this->request->getString("add_quest_cont_edit_mode")
228 );
229 // $ilCtrl->setParameter($this, "qpool_ref_id", $pool_ref_id);
230 //$ilCtrl->setParameter($this, "hier_id", $hier_id);
231 $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
232 $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
233
234 $ilCtrl->redirect($this, "edit");
235 }
236
237 $this->insert();
238 }
239
243 public function setNewQuestionId(array $a_par): void
244 {
245 if ($a_par["new_id"] > 0) {
246 $this->content_obj->setQuestionReference("il__qst_" . $a_par["new_id"]);
247 $this->pg_obj->update();
248 }
249 }
250
254 public function edit(): void
255 {
256 $ilCtrl = $this->ctrl;
257 $ilTabs = $this->tabs;
258 $q_id = "";
259
260 $ilTabs->setTabActive('question');
261
262 if ($this->getSelfAssessmentMode()) { // behaviour in content pages, e.g. scorm
263 $q_ref = $this->content_obj->getQuestionReference();
264
265 if ($q_ref != "") {
266 $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
267 if (!($inst_id > 0)) {
269 }
270 }
271
272 $q_type = $this->request->getString("q_type");
273 $ilCtrl->setParameter($this, "q_type", $q_type);
274
275 if ($q_id == "" && $q_type == "") {
276 $this->insert("edit_empty");
277 return;
278 }
279
280 // create question first-hand (needed for uploads)
281 if ($q_id < 1 && $q_type) {
282 $q_gui = assQuestionGUI::_getQuestionGUI($q_type);
283
284 // feedback editing mode
285 $add_quest_cont_edit_mode = $this->request->getString("add_quest_cont_edit_mode");
286 if ($this->ipe_for_questions_enabled
287 && $add_quest_cont_edit_mode != "") {
288 $addContEditMode = $add_quest_cont_edit_mode;
289 } else {
291 }
292 $q_gui->getObject()->setAdditionalContentEditingMode($addContEditMode);
293
294 //set default tries
295 $q_gui->getObject()->setObjId(0);
296 $q_id = $q_gui->getObject()->createNewQuestion(true);
297 $this->content_obj->setQuestionReference("il__qst_" . $q_id);
298 $this->pg_obj->update();
299 unset($q_gui);
300 }
301 $ilCtrl->setParameterByClass("ilQuestionEditGUI", "q_id", $q_id);
302 $ilCtrl->redirectByClass(array(get_class($this->pg_obj) . "GUI", "ilQuestionEditGUI"), "editQuestion");
303 } else { // behaviour in question pool
304 $q_gui = assQuestionGUI::_getQuestionGUI('', $this->request->getInt('q_id'));
305 $this->ctrl->redirectByClass($q_gui::class, 'editQuestion');
306 }
307 }
308
313 public function feedback()
314 {
315 $ilCtrl = $this->ctrl;
316 $ilTabs = $this->tabs;
317 $q_id = "";
318
319 $ilTabs->setTabActive('feedback');
320
321 $q_ref = $this->content_obj->getQuestionReference();
322
323 if ($q_ref != "") {
324 $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
325 if (!($inst_id > 0)) {
327 }
328 }
329
330 $edit_gui = new ilQuestionEditGUI();
331 if ($q_id > 0) {
332 $edit_gui->setQuestionId($q_id);
333 }
334 // $edit_gui->setQuestionType("assSingleChoice");
335 $edit_gui->setSelfAssessmentEditingMode(true);
336 $edit_gui->setPageConfig($this->getPageConfig());
337 $ret = $ilCtrl->forwardCommand($edit_gui);
338 $this->tpl->setContent($ret);
339 return $ret;
340 }
341
346 public function createQuestionPool(string $name = "Dummy"): int
347 {
349 $parent_ref = $tree->getParentId($this->requested_ref_id);
350 $qpl = new ilObjQuestionPool();
351 $qpl->setType("qpl");
352 $qpl->setTitle($name);
353 $qpl->setDescription("");
354 $qpl->create();
355 $qpl->createReference();
356 $qpl->putInTree($parent_ref);
357 $qpl->setPermissions($parent_ref);
358 $qpl->setOnline(1); // must be online to be available
359 $qpl->saveToDb();
360 return $qpl->getRefId();
361 }
362
363 public function setTabs(): void
364 {
365 $q_ref = "";
366 $q_id = 0;
367
368 if ($this->getSelfAssessmentMode()) {
369 return;
370 }
371
372 $ilTabs = $this->tabs;
373 $ilCtrl = $this->ctrl;
374
375 if (!is_null($this->content_obj)) {
376 $q_ref = $this->content_obj->getQuestionReference();
377 }
378
379 if ($q_ref != "") {
380 $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
381 if (!($inst_id > 0)) {
383 }
384 }
385
386 $ilTabs->addTarget(
387 "question",
388 $ilCtrl->getLinkTarget($this, "edit"),
389 array("editQuestion", "save", "cancel", "addSuggestedSolution",
390 "cancelExplorer", "linkChilds", "removeSuggestedSolution",
391 "addPair", "addTerm", "delete", "deleteTerms", "editMode", "upload",
392 "saveEdit","uploadingImage", "uploadingImagemap", "addArea",
393 "deletearea", "saveShape", "back", "saveEdit", "changeGapType","createGaps","addItem","addYesNo", "addTrueFalse",
394 "toggleGraphicalAnswers", "setMediaMode"),
395 ""
396 );
397
398 if ($q_id > 0) {
399 if ($this->questioninfo->getGeneralQuestionProperties($q_id)->getClassName() != "assTextQuestion") {
400 $tabCommands = assQuestionGUI::getCommandsFromClassConstants('ilAssQuestionFeedbackEditingGUI');
402 $ilCtrl->getLinkTargetByClass('ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW),
403 "q_id=" . $q_id
404 );
405 $ilTabs->addTarget('feedback', $tabLink, $tabCommands, $ilCtrl->getCmdClass(), '');
406 }
407 }
408 }
409
413
417 public function insertFromPool(): void
418 {
419 $ilAccess = $this->access;
420 if ($this->edit_repo->getQuestionPool() > 0 &&
421 $ilAccess->checkAccess("write", "", $this->edit_repo->getQuestionPool())
422 && ilObject::_lookupType(ilObject::_lookupObjId($this->edit_repo->getQuestionPool())) == "qpl") {
423 $this->listPoolQuestions();
424 } else {
425 $this->poolSelection();
426 }
427 }
428
429 public function poolSelection(): void
430 {
431 $ilCtrl = $this->ctrl;
433
434 $this->setInsertTabs("copy_question");
435
436 $ilCtrl->setParameter($this, "subCmd", "poolSelection");
437 $exp = new ilPoolSelectorGUI($this, "insert");
438
439 // filter
440 $exp->setTypeWhiteList(array("root", "cat", "grp", "fold", "crs", "qpl"));
441 $exp->setClickableTypes(array('qpl'));
442
443 if (!$exp->handleCommand()) {
444 $tpl->setContent($exp->getHTML());
445 }
446 }
447
448 public function selectPool(): void
449 {
450 $ilCtrl = $this->ctrl;
451
452 $this->edit_repo->setQuestionPool($this->request->getInt("pool_ref_id"));
453 $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
454 $ilCtrl->redirect($this, "insert");
455 }
456
457 public function listPoolQuestions(): void
458 {
459 $ilToolbar = $this->toolbar;
461 $ilCtrl = $this->ctrl;
463
464 $this->tpl->setOnScreenMessage('info', $lng->txt("cont_cp_question_diff_formats_info"));
465
466 $ilCtrl->setParameter($this, "subCmd", "poolSelection");
467 $ilToolbar->addButton(
468 $lng->txt("cont_select_other_qpool"),
469 $ilCtrl->getLinkTarget($this, "insert")
470 );
471 $ilCtrl->setParameter($this, "subCmd", "");
472
473 $this->setInsertTabs("copy_question");
474
475 $ilCtrl->setParameter($this, "subCmd", "listPoolQuestions");
476 $table_gui = new ilCopySelfAssQuestionTableGUI(
477 $this,
478 'insert',
479 $this->edit_repo->getQuestionPool()
480 );
481
482 $tpl->setContent($table_gui->getHTML());
483 }
484
485 public function copyQuestion(): void
486 {
487 $ilCtrl = $this->ctrl;
488
489 $this->content_obj = new ilPCQuestion($this->getPage());
490 $this->content_obj->create(
491 $this->pg_obj,
492 $this->request->getHierId()
493 );
494
495 $this->content_obj->copyPoolQuestionIntoPage(
496 $this->request->getInt("q_id"),
497 $this->request->getHierId()
498 );
499
500 $this->updated = $this->pg_obj->update();
501
502 $ilCtrl->returnToParent($this);
503 }
504}
static getCommandsFromClassConstants(string $guiClassName, string $cmdConstantNameBegin='CMD_')
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 sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
getCmd(?string $fallback_command=null)
@inheritDoc
This class represents a hidden form property in a property form.
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 & _getSelfAssessmentQuestionTypes($all_tags=false)
User class.
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS TestQuestionPool Questions PublicInterface $questioninfo
ilPropertyFormGUI $form_gui
create()
Create new question.
insertFromPool()
Insert question from ppol.
__construct(ilPageObject $a_pg_obj, ?ilPageContent $a_content_obj, string $a_hier_id, string $a_pc_id="")
createQuestionPool(string $name="Dummy")
Creates a new questionpool and returns the reference id.
ilAccessHandler $access
setSelfAssessmentMode(bool $a_selfassessmentmode)
setInsertTabs(string $a_active)
setNewQuestionId(array $a_par)
Set new question id.
insert(string $a_mode="create")
Insert new question form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
ilGlobalTemplateInterface $tpl
Content object of ilPageObject (see ILIAS DTD).
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
Class ilQuestionEditGUI.
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTabActive(string $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
getParentId(int $a_node_id)
get parent id of given node
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
setContent(string $a_html)
Sets content for standard template.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26