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