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