ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPCQuestionGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once "./Services/COPage/classes/class.ilPageContentGUI.php";
5 include_once "./Services/COPage/classes/class.ilPCQuestion.php";
6 
19 {
23  protected $access;
24 
28  protected $tabs;
29 
33  protected $user;
34 
38  protected $tree;
39 
43  protected $toolbar;
44 
49  public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
50  {
51  global $DIC;
52 
53  $this->ctrl = $DIC->ctrl();
54  $this->access = $DIC->access();
55  $this->tpl = $DIC["tpl"];
56  $this->tabs = $DIC->tabs();
57  $this->lng = $DIC->language();
58  $this->user = $DIC->user();
59  $this->tree = $DIC->repositoryTree();
60  $this->toolbar = $DIC->toolbar();
61  $ilCtrl = $DIC->ctrl();
62  $this->scormlmid = $a_pg_obj->parent_id;
63  parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
64  $ilCtrl->saveParameter($this, array("qpool_ref_id"));
65  }
66 
70  public function executeCommand()
71  {
73  $ilAccess = $this->access;
74  $tpl = $this->tpl;
75  $ilTabs = $this->tabs;
76  $lng = $this->lng;
77 
78  // get current command
79  $cmd = $ilCtrl->getCmd();
80  $next_class = $ilCtrl->getNextClass($this);
81 
82  $q_type = ($_POST["q_type"] != "")
83  ? $_POST["q_type"]
84  : $_GET["q_type"];
85 
86  switch ($next_class) {
87  default:
88  //set tabs
89  if ($cmd != "insert") {
90  $this->setTabs();
91  } elseif ($_GET["subCmd"] != "") {
92  $cmd = $_GET["subCmd"];
93  }
94 
95  $ret = $this->$cmd();
96  }
97 
98 
99 
100  return $ret;
101  }
102 
108  public function setSelfAssessmentMode($a_selfassessmentmode)
109  {
110  $this->selfassessmentmode = $a_selfassessmentmode;
111  }
112 
118  public function getSelfAssessmentMode()
119  {
120  return $this->selfassessmentmode;
121  }
122 
128  public function setInsertTabs($a_active)
129  {
130  $ilTabs = $this->tabs;
132  $lng = $this->lng;
133 
134  // new question
135  $ilTabs->addSubTab(
136  "new_question",
137  $lng->txt("cont_new_question"),
138  $ilCtrl->getLinkTarget($this, "insert")
139  );
140 
141  // copy from pool
142  $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
143  $ilTabs->addSubTab(
144  "copy_question",
145  $lng->txt("cont_copy_question_from_pool"),
146  $ilCtrl->getLinkTarget($this, "insert")
147  );
148 
149  $ilTabs->activateSubTab($a_active);
150 
151  $ilCtrl->setParameter($this, "subCmd", "");
152  }
153 
157  public function insert($a_mode = "create")
158  {
160  $lng = $this->lng;
162 
163  $this->setInsertTabs("new_question");
164 
165  $this->displayValidationError();
166 
167  // get all question types (@todo: we have to check, whether they are
168  // suitable for self assessment or not)
169  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
171  $options = array();
172  $all_types = ilUtil::sortArray($all_types, "order", "asc", true, true);
173 
174  foreach ($all_types as $k => $v) {
175  $options[$v["type_tag"]] = $k;
176  }
177 
178  // new table form (input of rows and columns)
179  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
180  $this->form_gui = new ilPropertyFormGUI();
181  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
182  $this->form_gui->setTitle($lng->txt("cont_ed_insert_pcqst"));
183 
184  // Select Question Type
185  $qtype_input = new ilSelectInputGUI($lng->txt("cont_question_type"), "q_type");
186  $qtype_input->setOptions($options);
187  $qtype_input->setRequired(true);
188  $this->form_gui->addItem($qtype_input);
189 
190  // additional content editor
191  // assessment
192  include_once("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
194  $ri = new ilRadioGroupInputGUI($this->lng->txt("tst_add_quest_cont_edit_mode"), "add_quest_cont_edit_mode");
195 
196  $ri->addOption(new ilRadioOption(
197  $this->lng->txt('tst_add_quest_cont_edit_mode_default'),
199  ));
200 
201  $ri->addOption(new ilRadioOption(
202  $this->lng->txt('tst_add_quest_cont_edit_mode_page_object'),
204  ));
205 
207 
208  $this->form_gui->addItem($ri, true);
209  } else {
210  $hi = new ilHiddenInputGUI("question_content_editing_type");
212  $this->form_gui->addItem($hi, true);
213  }
214 
215 
216  // Select Question Pool
217  /*
218  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
219  $qpools = ilObjQuestionPool::_getAvailableQuestionpools(false, false, false, true, false, "write");
220 
221  if (count($qpools) > 0)
222  {
223  $pool_options = array();
224  foreach ($qpools as $key => $value)
225  {
226  $pool_options[$key] = $value["title"];
227  }
228  $pool_input = new ilSelectInputGUI($lng->txt("cont_question_pool"), "qpool_ref_id");
229  $pool_input->setOptions($pool_options);
230  $pool_input->setRequired(true);
231  $this->form_gui->addItem($pool_input);
232  }
233  else
234  {
235  $pool_input = new ilTextInputGUI($lng->txt("cont_question_pool"), "qpool_title");
236  $pool_input->setRequired(true);
237  $this->form_gui->addItem($pool_input);
238  }
239  */
240  if ($a_mode == "edit_empty") {
241  $this->form_gui->addCommandButton("edit", $lng->txt("save"));
242  } else {
243  $this->form_gui->addCommandButton("create_pcqst", $lng->txt("save"));
244  $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
245  }
246 
247  $this->tpl->setContent($this->form_gui->getHTML());
248  }
249 
250 
254  public function create()
255  {
256  global $lng, $ilCtrl, $ilTabs;
257 
258  $ilTabs->setTabActive('question');
259 
260  $this->content_obj = new ilPCQuestion($this->getPage());
261  $this->content_obj->create($this->pg_obj, $this->hier_id);
262 
263  $this->updated = $this->pg_obj->update();
264 
265  if ($this->updated) {
266  // create question pool, if necessary
267  /* if ($_POST["qpool_ref_id"] <= 0)
268  {
269  $pool_ref_id = $this->createQuestionPool($_POST["qpool_title"]);
270  }
271  else
272  {
273  $pool_ref_id = $_POST["qpool_ref_id"];
274  }*/
275 
276  $this->pg_obj->stripHierIDs();
277  $this->pg_obj->addHierIDs();
278  $hier_id = $this->content_obj->lookupHierId();
279  $ilCtrl->setParameter($this, "q_type", $_POST["q_type"]);
280  $ilCtrl->setParameter($this, "add_quest_cont_edit_mode", $_POST["add_quest_cont_edit_mode"]);
281  // $ilCtrl->setParameter($this, "qpool_ref_id", $pool_ref_id);
282  //$ilCtrl->setParameter($this, "hier_id", $hier_id);
283  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
284  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
285 
286  $ilCtrl->redirect($this, "edit");
287  }
288 
289  $this->insert();
290  }
291 
295  public function setNewQuestionId($a_par)
296  {
297  if ($a_par["new_id"] > 0) {
298  $this->content_obj->setQuestionReference("il__qst_" . $a_par["new_id"]);
299  $this->pg_obj->update();
300  }
301  }
302 
306  public function edit()
307  {
309  $ilTabs = $this->tabs;
310 
311  $ilTabs->setTabActive('question');
312 
313 
314  if ($this->getSelfAssessmentMode()) { // behaviour in content pages, e.g. scorm
315  $q_ref = $this->content_obj->getQuestionReference();
316 
317  if ($q_ref != "") {
318  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
319  if (!($inst_id > 0)) {
321  }
322  }
323 
324  $q_type = ($_POST["q_type"] != "")
325  ? $_POST["q_type"]
326  : $_GET["q_type"];
327  $ilCtrl->setParameter($this, "q_type", $q_type);
328 
329  if ($q_id == "" && $q_type == "") {
330  return $this->insert("edit_empty");
331  }
332 
333  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
334  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
335  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
336 
337  /* $ilCtrl->setCmdClass("ilquestioneditgui");
338  $ilCtrl->setCmd("editQuestion");
339  $edit_gui = new ilQuestionEditGUI();*/
340 
341  // create question first-hand (needed for uploads)
342  if ($q_id < 1 && $q_type) {
343  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
344  $q_gui = assQuestionGUI::_getQuestionGUI($q_type);
345 
346  // feedback editing mode
347  include_once("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
349  && $_REQUEST['add_quest_cont_edit_mode'] != "") {
350  $addContEditMode = $_GET['add_quest_cont_edit_mode'];
351  } else {
353  }
354  $q_gui->object->setAdditionalContentEditingMode($addContEditMode);
355 
356  //set default tries
357  $q_gui->object->setDefaultNrOfTries(ilObjSAHSLearningModule::_getTries($this->scormlmid));
358  $q_id = $q_gui->object->createNewQuestion(true);
359  $this->content_obj->setQuestionReference("il__qst_" . $q_id);
360  $this->pg_obj->update();
361  unset($q_gui);
362  }
363  $ilCtrl->setParameterByClass("ilQuestionEditGUI", "q_id", $q_id);
364  $ilCtrl->redirectByClass(array(get_class($this->pg_obj) . "GUI", "ilQuestionEditGUI"), "editQuestion");
365 
366  /* $edit_gui->setPoolObjId(0);
367  $edit_gui->setQuestionId($q_id);
368  $edit_gui->setQuestionType($q_type);
369  $edit_gui->setSelfAssessmentEditingMode(true);
370  $edit_gui->setPageConfig($this->getPageConfig());
371  $ret = $ilCtrl->forwardCommand($edit_gui);
372  $this->tpl->setContent($ret);*/
373  return $ret;
374  } else { // behaviour in question pool
375  require_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
376  $q_gui = assQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
377  $this->ctrl->redirectByClass(array("ilobjquestionpoolgui", get_class($q_gui)), "editQuestion");
378  }
379  }
380 
381  public function feedback()
382  {
384  $ilTabs = $this->tabs;
385 
386  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
387  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
388 
389  $ilTabs->setTabActive('feedback');
390 
391  $q_ref = $this->content_obj->getQuestionReference();
392 
393  if ($q_ref != "") {
394  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
395  if (!($inst_id > 0)) {
397  }
398  }
399 
400  $ilCtrl->setCmdClass("ilquestioneditgui");
401  $ilCtrl->setCmd("feedback");
402  $edit_gui = new ilQuestionEditGUI();
403  if ($q_id > 0) {
404  $edit_gui->setQuestionId($q_id);
405  }
406  // $edit_gui->setQuestionType("assSingleChoice");
407  $edit_gui->setSelfAssessmentEditingMode(true);
408  $edit_gui->setPageConfig($this->getPageConfig());
409  $ret = $ilCtrl->forwardCommand($edit_gui);
410  $this->tpl->setContent($ret);
411  return $ret;
412  }
421  public function createQuestionPool($name = "Dummy")
422  {
423  $tree = $this->tree;
424  $parent_ref = $tree->getParentId($_GET["ref_id"]);
425  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
426  $qpl = new ilObjQuestionPool();
427  $qpl->setType("qpl");
428  $qpl->setTitle($name);
429  $qpl->setDescription("");
430  $qpl->create();
431  $qpl->createReference();
432  $qpl->putInTree($parent_ref);
433  $qpl->setPermissions($parent_ref);
434  $qpl->setOnline(1); // must be online to be available
435  $qpl->saveToDb();
436  return $qpl->getRefId();
437  }
438 
442  public function setTabs()
443  {
444  if ($this->getSelfAssessmentMode()) {
445  return;
446  }
447 
448  $ilTabs = $this->tabs;
450  $lng = $this->lng;
451  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
452 
453  if ($this->content_obj != "") {
454  $q_ref = $this->content_obj->getQuestionReference();
455  }
456 
457  if ($q_ref != "") {
458  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
459  if (!($inst_id > 0)) {
461  }
462  }
463 
464  $ilTabs->addTarget(
465  "question",
466  $ilCtrl->getLinkTarget($this, "edit"),
467  array("editQuestion", "save", "cancel", "addSuggestedSolution",
468  "cancelExplorer", "linkChilds", "removeSuggestedSolution",
469  "addPair", "addTerm", "delete", "deleteTerms", "editMode", "upload",
470  "saveEdit","uploadingImage", "uploadingImagemap", "addArea",
471  "deletearea", "saveShape", "back", "saveEdit", "changeGapType","createGaps","addItem","addYesNo", "addTrueFalse",
472  "toggleGraphicalAnswers", "setMediaMode"),
473  ""
474  );
475 
476  if ($q_id > 0) {
477  if (assQuestion::_getQuestionType($q_id) != "assTextQuestion") {
478  require_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
479  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackEditingGUI.php';
480  $tabCommands = assQuestionGUI::getCommandsFromClassConstants('ilAssQuestionFeedbackEditingGUI');
482  $ilCtrl->getLinkTargetByClass('ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW),
483  "q_id=" . (int) $q_id
484  );
485  $ilTabs->addTarget('feedback', $tabLink, $tabCommands, $ilCtrl->getCmdClass(), '');
486  }
487  }
488  }
489 
493 
497  public function insertFromPool()
498  {
500  $ilAccess = $this->access;
501  $ilTabs = $this->tabs;
502  $tpl = $this->tpl;
503  $lng = $this->lng;
504  $ilToolbar = $this->toolbar;
505  //var_dump($_SESSION["cont_qst_pool"]);
506  if ($_SESSION["cont_qst_pool"] != "" &&
507  $ilAccess->checkAccess("write", "", $_SESSION["cont_qst_pool"])
508  && ilObject::_lookupType(ilObject::_lookupObjId($_SESSION["cont_qst_pool"])) == "qpl") {
509  $this->listPoolQuestions();
510  } else {
511  $this->poolSelection();
512  }
513  }
514 
521  public function poolSelection()
522  {
524  $tree = $this->tree;
525  $tpl = $this->tpl;
526  $ilTabs = $this->tabs;
527 
528  $this->setInsertTabs("copy_question");
529 
530  include_once "./Services/COPage/classes/class.ilPoolSelectorGUI.php";
531 
532  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
533  $exp = new ilPoolSelectorGUI($this, "insert");
534 
535  // filter
536  $exp->setTypeWhiteList(array("root", "cat", "grp", "fold", "crs", "qpl"));
537  $exp->setClickableTypes(array('qpl'));
538 
539  if (!$exp->handleCommand()) {
540  $tpl->setContent($exp->getHTML());
541  }
542  }
543 
547  public function selectPool()
548  {
550 
551  $_SESSION["cont_qst_pool"] = $_GET["pool_ref_id"];
552  $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
553  $ilCtrl->redirect($this, "insert");
554  }
555 
562  public function listPoolQuestions()
563  {
564  $ilToolbar = $this->toolbar;
565  $tpl = $this->tpl;
567  $lng = $this->lng;
568 
569  ilUtil::sendInfo($lng->txt("cont_cp_question_diff_formats_info"));
570 
571  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
572  $ilToolbar->addButton(
573  $lng->txt("cont_select_other_qpool"),
574  $ilCtrl->getLinkTarget($this, "insert")
575  );
576  $ilCtrl->setParameter($this, "subCmd", "");
577 
578  $this->setInsertTabs("copy_question");
579 
580  include_once "./Services/COPage/classes/class.ilCopySelfAssQuestionTableGUI.php";
581 
582  $ilCtrl->setParameter($this, "subCmd", "listPoolQuestions");
583  $table_gui = new ilCopySelfAssQuestionTableGUI(
584  $this,
585  'insert',
586  $_SESSION["cont_qst_pool"]
587  );
588 
589  $tpl->setContent($table_gui->getHTML());
590  }
591 
598  public function copyQuestion()
599  {
601 
602  $this->content_obj = new ilPCQuestion($this->getPage());
603  $this->content_obj->create($this->pg_obj, $_GET["hier_id"]);
604 
605  $this->content_obj->copyPoolQuestionIntoPage(
606  (int) $_GET["q_id"],
607  $_GET["hier_id"]
608  );
609 
610  $this->updated = $this->pg_obj->update();
611 
612  $ilCtrl->returnToParent($this);
613  }
614 }
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
This class represents an option in a radio group.
setInsertTabs($a_active)
Set insert tabs.
Class ilQuestionEditGUI.
$_SESSION["AccountId"]
static _getQuestionType($question_id)
Returns the question type of a question with a given id.
This class represents a selection list property in a property form.
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
const ADDITIONAL_CONTENT_EDITING_MODE_PAGE_OBJECT
constant for additional content editing mode "pageobject"
$_GET["client_id"]
setSelfAssessmentMode($a_selfassessmentmode)
Set Self Assessment Mode.
create()
Create new question.
getPageConfig()
Get Page Config.
setNewQuestionId($a_par)
Set new question id.
user()
Definition: user.php:4
poolSelection()
Pool selection.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class ilPCQuestionGUI.
static getCommandsFromClassConstants($guiClassName, $cmdConstantNameBegin='CMD_')
extracts values of all constants of given class with given prefix as array can be used to get all pos...
This class represents a hidden form property in a property form.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
static & _getSelfAssessmentQuestionTypes($all_tags=false)
Get all self assessment question types.
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
This class represents a property in a property form.
addOption($a_option)
Add Option.
createQuestionPool($name="Dummy")
Creates a new questionpool and returns the reference id.
Class ilPCQuestion.
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...
static _lookupObjId($a_id)
displayValidationError()
display validation errors
$ilUser
Definition: imgupload.php:18
insert($a_mode="create")
Insert new question form.
selectPool()
Select concrete question pool.
executeCommand()
execute command
setOptions($a_options)
Set Options.
Table to select self assessment questions for copying into learning resources.
static _lookupType($a_id, $a_reference=false)
lookup object type
const ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT
constant for additional content editing mode "default"
listPoolQuestions()
List questions of pool.
insertFromPool()
Insert question from ppol.
getSelfAssessmentMode()
Get Self Assessment Mode.
Select media pool for adding objects into pages.
$ret
Definition: parser.php:6
static isAdditionalQuestionContentEditingModePageObjectEnabled()
returns the fact wether content editing with ilias page editor is enabled for questions or not ...
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
$_POST["username"]
copyQuestion()
Copy question into page.