ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
24  function ilPCQuestionGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
25  {
26  global $ilCtrl;
27  $this->scormlmid = $a_pg_obj->parent_id;
28  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
29  $ilCtrl->saveParameter($this, array("qpool_ref_id"));
30  }
31 
35  function &executeCommand()
36  {
37  global $ilCtrl, $ilAccess, $tpl, $ilTabs, $lng;
38 
39  // get current command
40  $cmd = $ilCtrl->getCmd();
41  $next_class = $ilCtrl->getNextClass($this);
42 
43  $q_type = ($_POST["q_type"] != "")
44  ? $_POST["q_type"]
45  : $_GET["q_type"];
46 
47  switch($next_class)
48  {
49  default:
50  //set tabs
51  if ($cmd != "insert")
52  {
53  $this->setTabs();
54  }
55  else if ($_GET["subCmd"] != "")
56  {
57  $cmd = $_GET["subCmd"];
58  }
59 
60  $ret = $this->$cmd();
61  }
62 
63 
64 
65  return $ret;
66  }
67 
73  function setSelfAssessmentMode($a_selfassessmentmode)
74  {
75  $this->selfassessmentmode = $a_selfassessmentmode;
76  }
77 
84  {
85  return $this->selfassessmentmode;
86  }
87 
93  function setInsertTabs($a_active)
94  {
95  global $ilTabs, $ilCtrl, $lng;
96 
97  // new question
98  $ilTabs->addSubTab("new_question",
99  $lng->txt("cont_new_question"),
100  $ilCtrl->getLinkTarget($this, "insert"));
101 
102  // copy from pool
103  $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
104  $ilTabs->addSubTab("copy_question",
105  $lng->txt("cont_copy_question_from_pool"),
106  $ilCtrl->getLinkTarget($this, "insert"));
107 
108  $ilTabs->activateSubTab($a_active);
109 
110  $ilCtrl->setParameter($this, "subCmd", "");
111  }
112 
116  function insert($a_mode = "create")
117  {
118  global $ilUser, $lng, $ilCtrl;
119 
120  $this->setInsertTabs("new_question");
121 
122  $this->displayValidationError();
123 
124  // get all question types (@todo: we have to check, whether they are
125  // suitable for self assessment or not)
126  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
128  $options = array();
129  $all_types = ilUtil::sortArray($all_types, "order", "asc", true, true);
130 
131  foreach ($all_types as $k => $v)
132  {
133  $options[$v["type_tag"]] = $k;
134  }
135 
136  // new table form (input of rows and columns)
137  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
138  $this->form_gui = new ilPropertyFormGUI();
139  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
140  $this->form_gui->setTitle($lng->txt("cont_ed_insert_pcqst"));
141 
142  // Select Question Type
143  $qtype_input = new ilSelectInputGUI($lng->txt("cont_question_type"), "q_type");
144  $qtype_input->setOptions($options);
145  $qtype_input->setRequired(true);
146  $this->form_gui->addItem($qtype_input);
147 
148  // additional content editor
149  // assessment
150  include_once("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
152  {
153  $ri = new ilRadioGroupInputGUI($this->lng->txt("tst_add_quest_cont_edit_mode"), "add_quest_cont_edit_mode");
154 
155  $ri->addOption(new ilRadioOption(
156  $this->lng->txt('tst_add_quest_cont_edit_mode_default'),
158  ));
159 
160  $ri->addOption(new ilRadioOption(
161  $this->lng->txt('tst_add_quest_cont_edit_mode_page_object'),
163  ));
164 
166 
167  $this->form_gui->addItem($ri, true);
168  }
169  else
170  {
171  $hi = new ilHiddenInputGUI("question_content_editing_type");
173  $this->form_gui->addItem($hi, true);
174  }
175 
176 
177  // Select Question Pool
178 /*
179  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
180  $qpools = ilObjQuestionPool::_getAvailableQuestionpools(false, false, false, true, false, "write");
181 
182  if (count($qpools) > 0)
183  {
184  $pool_options = array();
185  foreach ($qpools as $key => $value)
186  {
187  $pool_options[$key] = $value["title"];
188  }
189  $pool_input = new ilSelectInputGUI($lng->txt("cont_question_pool"), "qpool_ref_id");
190  $pool_input->setOptions($pool_options);
191  $pool_input->setRequired(true);
192  $this->form_gui->addItem($pool_input);
193  }
194  else
195  {
196  $pool_input = new ilTextInputGUI($lng->txt("cont_question_pool"), "qpool_title");
197  $pool_input->setRequired(true);
198  $this->form_gui->addItem($pool_input);
199  }
200 */
201  if ($a_mode == "edit_empty")
202  {
203  $this->form_gui->addCommandButton("edit", $lng->txt("save"));
204  }
205  else
206  {
207  $this->form_gui->addCommandButton("create_pcqst", $lng->txt("save"));
208  $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
209  }
210 
211  $this->tpl->setContent($this->form_gui->getHTML());
212  }
213 
214 
218  function create()
219  {
220  global $lng, $ilCtrl, $ilTabs;
221 
222  $ilTabs->setTabActive('question');
223 
224  $this->content_obj = new ilPCQuestion($this->getPage());
225  $this->content_obj->create($this->pg_obj, $this->hier_id);
226 
227  $this->updated = $this->pg_obj->update();
228 
229  if ($this->updated)
230  {
231  // create question pool, if necessary
232 /* if ($_POST["qpool_ref_id"] <= 0)
233  {
234  $pool_ref_id = $this->createQuestionPool($_POST["qpool_title"]);
235  }
236  else
237  {
238  $pool_ref_id = $_POST["qpool_ref_id"];
239  }*/
240 
241  $this->pg_obj->stripHierIDs();
242  $this->pg_obj->addHierIDs();
243  $hier_id = $this->content_obj->lookupHierId();
244  $ilCtrl->setParameter($this, "q_type", $_POST["q_type"]);
245  $ilCtrl->setParameter($this, "add_quest_cont_edit_mode", $_POST["add_quest_cont_edit_mode"]);
246 // $ilCtrl->setParameter($this, "qpool_ref_id", $pool_ref_id);
247  //$ilCtrl->setParameter($this, "hier_id", $hier_id);
248  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
249  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
250 
251  $ilCtrl->redirect($this, "edit");
252  }
253 
254  $this->insert();
255  }
256 
260  function setNewQuestionId($a_par)
261  {
262  if ($a_par["new_id"] > 0)
263  {
264  $this->content_obj->setQuestionReference("il__qst_".$a_par["new_id"]);
265  $this->pg_obj->update();
266  }
267  }
268 
272  function edit()
273  {
274  global $ilCtrl, $ilTabs;
275 
276  $ilTabs->setTabActive('question');
277 
278 
279  if ($this->getSelfAssessmentMode()) // behaviour in content pages, e.g. scorm
280  {
281  $q_ref = $this->content_obj->getQuestionReference();
282 
283  if ($q_ref != "")
284  {
285  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
286  if (!($inst_id > 0))
287  {
289  }
290  }
291 
292  $q_type = ($_POST["q_type"] != "")
293  ? $_POST["q_type"]
294  : $_GET["q_type"];
295  $ilCtrl->setParameter($this, "q_type", $q_type);
296 
297  if ($q_id == "" && $q_type == "")
298  {
299  return $this->insert("edit_empty");
300  }
301 
302  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
303  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
304  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
305 
306 /* $ilCtrl->setCmdClass("ilquestioneditgui");
307  $ilCtrl->setCmd("editQuestion");
308  $edit_gui = new ilQuestionEditGUI();*/
309 
310  // create question first-hand (needed for uploads)
311  if($q_id < 1 && $q_type)
312  {
313  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
314  $q_gui =& assQuestionGUI::_getQuestionGUI($q_type);
315 
316  // feedback editing mode
317  include_once("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
319  && $_REQUEST['add_quest_cont_edit_mode'] != "")
320  {
321  $addContEditMode = $_GET['add_quest_cont_edit_mode'];
322  }
323  else
324  {
326  }
327  $q_gui->object->setAdditionalContentEditingMode($addContEditMode);
328 
329  //set default tries
330  $q_gui->object->setDefaultNrOfTries(ilObjSAHSLearningModule::_getTries($this->scormlmid));
331  $q_id = $q_gui->object->createNewQuestion(true);
332  $this->content_obj->setQuestionReference("il__qst_".$q_id);
333  $this->pg_obj->update();
334  unset($q_gui);
335  }
336  $ilCtrl->setParameterByClass("ilQuestionEditGUI", "q_id", $q_id);
337  $ilCtrl->redirectByClass(array(get_class($this->pg_obj)."GUI", "ilQuestionEditGUI"), "editQuestion");
338 
339 /* $edit_gui->setPoolObjId(0);
340  $edit_gui->setQuestionId($q_id);
341  $edit_gui->setQuestionType($q_type);
342  $edit_gui->setSelfAssessmentEditingMode(true);
343  $edit_gui->setPageConfig($this->getPageConfig());
344  $ret = $ilCtrl->forwardCommand($edit_gui);
345  $this->tpl->setContent($ret);*/
346  return $ret;
347  }
348  else // behaviour in question pool
349  {
350  require_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
351  $q_gui =& assQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
352  $this->ctrl->redirectByClass(array("ilobjquestionpoolgui", get_class($q_gui)), "editQuestion");
353  }
354  }
355 
356  function feedback()
357  {
358  global $ilCtrl, $ilTabs;
359 
360  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
361  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
362 
363  $ilTabs->setTabActive('feedback');
364 
365  $q_ref = $this->content_obj->getQuestionReference();
366 
367  if ($q_ref != "")
368  {
369  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
370  if (!($inst_id > 0))
371  {
373  }
374  }
375 
376  $ilCtrl->setCmdClass("ilquestioneditgui");
377  $ilCtrl->setCmd("feedback");
378  $edit_gui = new ilQuestionEditGUI();
379  if ($q_id > 0)
380  {
381  $edit_gui->setQuestionId($q_id);
382  }
383 // $edit_gui->setQuestionType("assSingleChoice");
384  $edit_gui->setSelfAssessmentEditingMode(true);
385  $edit_gui->setPageConfig($this->getPageConfig());
386  $ret = $ilCtrl->forwardCommand($edit_gui);
387  $this->tpl->setContent($ret);
388  return $ret;
389 
390  }
399  function createQuestionPool($name = "Dummy")
400  {
401  global $tree;
402  $parent_ref = $tree->getParentId($_GET["ref_id"]);
403  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
404  $qpl = new ilObjQuestionPool();
405  $qpl->setType("qpl");
406  $qpl->setTitle($name);
407  $qpl->setDescription("");
408  $qpl->create();
409  $qpl->createReference();
410  $qpl->putInTree($parent_ref);
411  $qpl->setPermissions($parent_ref);
412  $qpl->setOnline(1); // must be online to be available
413  $qpl->saveToDb();
414  return $qpl->getRefId();
415  }
416 
420  function setTabs()
421  {
422  if ($this->getSelfAssessmentMode())
423  {
424  return;
425  }
426 
427  global $ilTabs, $ilCtrl, $lng;
428  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
429 
430  if ($this->content_obj!="") {
431  $q_ref = $this->content_obj->getQuestionReference();
432  }
433 
434  if ($q_ref != "")
435  {
436  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
437  if (!($inst_id > 0))
438  {
440  }
441  }
442 
443  $ilTabs->addTarget("question",
444  $ilCtrl->getLinkTarget($this, "edit"), array("editQuestion", "save", "cancel", "addSuggestedSolution",
445  "cancelExplorer", "linkChilds", "removeSuggestedSolution",
446  "addPair", "addTerm", "delete", "deleteTerms", "editMode", "upload",
447  "saveEdit","uploadingImage", "uploadingImagemap", "addArea",
448  "deletearea", "saveShape", "back", "saveEdit", "changeGapType","createGaps","addItem","addYesNo", "addTrueFalse",
449  "toggleGraphicalAnswers", "setMediaMode"),
450  "");
451 
452  if ($q_id > 0)
453  {
454  if (assQuestion::_getQuestionType($q_id)!= "assTextQuestion")
455  {
456  require_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
457  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackEditingGUI.php';
458  $tabCommands = assQuestionGUI::getCommandsFromClassConstants('ilAssQuestionFeedbackEditingGUI');
460  $ilCtrl->getLinkTargetByClass('ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW),
461  "q_id=".(int)$q_id
462  );
463  $ilTabs->addTarget('feedback', $tabLink, $tabCommands, $ilCtrl->getCmdClass(), '');
464  }
465  }
466  }
467 
471 
475  function insertFromPool()
476  {
477  global $ilCtrl, $ilAccess, $ilTabs, $tpl, $lng, $ilToolbar;
478 //var_dump($_SESSION["cont_qst_pool"]);
479  if ($_SESSION["cont_qst_pool"] != "" &&
480  $ilAccess->checkAccess("write", "", $_SESSION["cont_qst_pool"])
481  && ilObject::_lookupType(ilObject::_lookupObjId($_SESSION["cont_qst_pool"])) == "qpl")
482  {
483  $this->listPoolQuestions();
484  }
485  else
486  {
487  $this->poolSelection();
488  }
489  }
490 
497  function poolSelection()
498  {
499  global $ilCtrl, $tree, $tpl, $ilTabs;
500 
501  $this->setInsertTabs("copy_question");
502 
503  include_once "./Services/COPage/classes/class.ilPoolSelectorGUI.php";
504 
505  $exp = new ilPoolSelectorGUI($ilCtrl->getLinkTarget($this, "insert"));
506 
507  if ($_GET["expand"] == "")
508  {
509  $expanded = $tree->readRootId();
510  }
511  else
512  {
513  $expanded = $_GET["expand"];
514  }
515  $exp->setExpand($expanded);
516 
517  $exp->setTargetGet("sel_id");
518  $ilCtrl->setParameter($this, "target_type", $a_type);
519  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
520  $exp->setParamsGet($this->ctrl->getParameterArray($this, "insert"));
521 
522  // filter
523  $exp->setFiltered(true);
524  $exp->setFilterMode(IL_FM_POSITIVE);
525  $exp->addFilter("root");
526  $exp->addFilter("cat");
527  $exp->addFilter("grp");
528  $exp->addFilter("fold");
529  $exp->addFilter("crs");
530  $exp->addFilter("qpl");
531  $exp->setContentGUIClass("ilpcquestiongui");
532  $exp->setSelectableTypes(array('qpl'));
533 
534  $exp->setOutput(0);
535 
536  $tpl->setContent($exp->getOutput());
537  }
538 
542  function selectPool()
543  {
544  global $ilCtrl;
545 
546  $_SESSION["cont_qst_pool"] = $_GET["pool_ref_id"];
547  $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
548  $ilCtrl->redirect($this, "insert");
549  }
550 
557  function listPoolQuestions()
558  {
559  global $ilToolbar, $tpl, $ilCtrl, $lng;
560 
561  ilUtil::sendInfo($lng->txt("cont_cp_question_diff_formats_info"));
562 
563  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
564  $ilToolbar->addButton(
565  $lng->txt("cont_select_other_qpool"),
566  $ilCtrl->getLinkTarget($this, "insert"));
567  $ilCtrl->setParameter($this, "subCmd", "");
568 
569  $this->setInsertTabs("copy_question");
570 
571  include_once "./Services/COPage/classes/class.ilCopySelfAssQuestionTableGUI.php";
572 
573  $ilCtrl->setParameter($this, "subCmd", "listPoolQuestions");
574  $table_gui = new ilCopySelfAssQuestionTableGUI($this, 'insert',
575  $_SESSION["cont_qst_pool"]);
576 
577  $tpl->setContent($table_gui->getHTML());
578  }
579 
586  function copyQuestion()
587  {
588  global $ilCtrl;
589 
590  $this->content_obj = new ilPCQuestion($this->getPage());
591  $this->content_obj->create($this->pg_obj, $_GET["hier_id"]);
592 
593  $this->content_obj->copyPoolQuestionIntoPage(
594  (int) $_GET["q_id"], $_GET["hier_id"]);
595 
596  $this->updated = $this->pg_obj->update();
597 
598  $ilCtrl->returnToParent($this);
599  }
600 
601 }
602 ?>