ILIAS  release_4-3 Revision
 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 
20 {
21  var $page_config = null;
22 
27  function ilPCQuestionGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
28  {
29  global $ilCtrl;
30  $this->scormlmid = $a_pg_obj->parent_id;
31  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
32  $ilCtrl->saveParameter($this, array("qpool_ref_id"));
33  }
34 
40  function setPageConfig($a_val)
41  {
42  $this->page_config = $a_val;
43  }
44 
50  function getPageConfig()
51  {
52  return $this->page_config;
53  }
54 
58  function &executeCommand()
59  {
60  global $ilCtrl;
61 
62  // get current command
63  $cmd = $ilCtrl->getCmd();
64  $next_class = $ilCtrl->getNextClass($this);
65 
66  $q_type = ($_POST["q_type"] != "")
67  ? $_POST["q_type"]
68  : $_GET["q_type"];
69 
70 
71 
72  switch($next_class)
73  {
74 
75  case "ilquestioneditgui":
76  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
77 
78  $edit_gui = new ilQuestionEditGUI();
79  if ($q_type != "")
80  {
81  $edit_gui->setQuestionType($q_type);
82  }
83  $edit_gui->setPageConfig($this->getPageConfig());
84  //$edit_gui->setPoolRefId($qpool_ref_id);
85  $this->setTabs();
86  $edit_gui->addNewIdListener($this, "setNewQuestionId");
87  $edit_gui->setSelfAssessmentEditingMode(true);
88  $ret = $ilCtrl->forwardCommand($edit_gui);
89  $this->tpl->setContent($ret);
90  break;
91 
92  default:
93  //set tabs
94  if ($cmd != "insert")
95  {
96  $this->setTabs();
97  }
98  else if ($_GET["subCmd"] != "")
99  {
100  $cmd = $_GET["subCmd"];
101  }
102 
103  $ret = $this->$cmd();
104  }
105 
106 
107 
108  return $ret;
109  }
110 
116  function setSelfAssessmentMode($a_selfassessmentmode)
117  {
118  $this->selfassessmentmode = $a_selfassessmentmode;
119  }
120 
127  {
128  return $this->selfassessmentmode;
129  }
130 
136  function setInsertTabs($a_active)
137  {
138  global $ilTabs, $ilCtrl, $lng;
139 
140  // new question
141  $ilTabs->addSubTab("new_question",
142  $lng->txt("cont_new_question"),
143  $ilCtrl->getLinkTarget($this, "insert"));
144 
145  // copy from pool
146  $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
147  $ilTabs->addSubTab("copy_question",
148  $lng->txt("cont_copy_question_from_pool"),
149  $ilCtrl->getLinkTarget($this, "insert"));
150 
151  $ilTabs->activateSubTab($a_active);
152 
153  $ilCtrl->setParameter($this, "subCmd", "");
154  }
155 
159  function insert($a_mode = "create")
160  {
161  global $ilUser, $lng, $ilCtrl;
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  {
176  $options[$v["type_tag"]] = $k;
177  }
178 
179  // new table form (input of rows and columns)
180  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
181  $this->form_gui = new ilPropertyFormGUI();
182  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
183  $this->form_gui->setTitle($lng->txt("cont_ed_insert_pcqst"));
184 
185  // Select Question Type
186  $qtype_input = new ilSelectInputGUI($lng->txt("cont_question_type"), "q_type");
187  $qtype_input->setOptions($options);
188  $qtype_input->setRequired(true);
189  $this->form_gui->addItem($qtype_input);
190 
191  // Select Question Pool
192 /*
193  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
194  $qpools = ilObjQuestionPool::_getAvailableQuestionpools(false, false, false, true, false, "write");
195 
196  if (count($qpools) > 0)
197  {
198  $pool_options = array();
199  foreach ($qpools as $key => $value)
200  {
201  $pool_options[$key] = $value["title"];
202  }
203  $pool_input = new ilSelectInputGUI($lng->txt("cont_question_pool"), "qpool_ref_id");
204  $pool_input->setOptions($pool_options);
205  $pool_input->setRequired(true);
206  $this->form_gui->addItem($pool_input);
207  }
208  else
209  {
210  $pool_input = new ilTextInputGUI($lng->txt("cont_question_pool"), "qpool_title");
211  $pool_input->setRequired(true);
212  $this->form_gui->addItem($pool_input);
213  }
214 */
215  if ($a_mode == "edit_empty")
216  {
217  $this->form_gui->addCommandButton("edit", $lng->txt("save"));
218  }
219  else
220  {
221  $this->form_gui->addCommandButton("create_pcqst", $lng->txt("save"));
222  $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
223  }
224 
225  $this->tpl->setContent($this->form_gui->getHTML());
226  }
227 
228 
232  function create()
233  {
234  global $lng, $ilCtrl, $ilTabs;
235 
236  $ilTabs->setTabActive('question');
237 
238  $this->content_obj = new ilPCQuestion($this->dom);
239  $this->content_obj->create($this->pg_obj, $this->hier_id);
240 
241  $this->updated = $this->pg_obj->update();
242 
243  if ($this->updated)
244  {
245  // create question pool, if necessary
246 /* if ($_POST["qpool_ref_id"] <= 0)
247  {
248  $pool_ref_id = $this->createQuestionPool($_POST["qpool_title"]);
249  }
250  else
251  {
252  $pool_ref_id = $_POST["qpool_ref_id"];
253  }*/
254 
255  $this->pg_obj->stripHierIDs();
256  $this->pg_obj->addHierIDs();
257  $hier_id = $this->content_obj->lookupHierId();
258  $ilCtrl->setParameter($this, "q_type", $_POST["q_type"]);
259 // $ilCtrl->setParameter($this, "qpool_ref_id", $pool_ref_id);
260  //$ilCtrl->setParameter($this, "hier_id", $hier_id);
261  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
262  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
263 
264  $ilCtrl->redirect($this, "edit");
265  }
266 
267  $this->insert();
268  }
269 
273  function setNewQuestionId($a_par)
274  {
275  if ($a_par["new_id"] > 0)
276  {
277  $this->content_obj->setQuestionReference("il__qst_".$a_par["new_id"]);
278  $this->pg_obj->update();
279  }
280  }
281 
285  function edit()
286  {
287  global $ilCtrl, $ilTabs;
288 
289  $ilTabs->setTabActive('question');
290 
291 
292  if ($this->getSelfAssessmentMode()) // behaviour in content pages, e.g. scorm
293  {
294  $q_ref = $this->content_obj->getQuestionReference();
295 
296  if ($q_ref != "")
297  {
298  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
299  if (!($inst_id > 0))
300  {
302  }
303  }
304 
305  $q_type = ($_POST["q_type"] != "")
306  ? $_POST["q_type"]
307  : $_GET["q_type"];
308  $ilCtrl->setParameter($this, "q_type", $q_type);
309 
310  if ($q_id == "" && $q_type == "")
311  {
312  return $this->insert("edit_empty");
313  }
314 
315  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
316  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
317  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
318 
319  $ilCtrl->setCmdClass("ilquestioneditgui");
320  $ilCtrl->setCmd("editQuestion");
321  $edit_gui = new ilQuestionEditGUI();
322 
323  // create question first-hand (needed for uploads)
324  if($q_id < 1 && $q_type)
325  {
326  include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
327  $q_gui =& assQuestionGUI::_getQuestionGUI($q_type);
328  $q_id = $q_gui->object->createNewQuestion(true);
329  unset($q_gui);
330 
331  if ($_GET["qpool_ref_id"] > 0)
332  {
333  $edit_gui->setPoolRefId($_GET["qpool_ref_id"]);
334  $edit_gui->setPoolRefId(0);
335  }
336  //set default tries
337  $edit_gui->setDefaultNrOfTries(ilObjSAHSLearningModule::_getTries($this->scormlmid));
338  }
339 
340  $edit_gui->setPoolObjId(0);
341  $edit_gui->setQuestionId($q_id);
342  $edit_gui->setQuestionType($q_type);
343  $edit_gui->setSelfAssessmentEditingMode(true);
344  $edit_gui->setPageConfig($this->getPageConfig());
345  $ret = $ilCtrl->forwardCommand($edit_gui);
346  $this->tpl->setContent($ret);
347  return $ret;
348  }
349  else // behaviour in question pool
350  {
351  require_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
352  $q_gui =& assQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
353  $this->ctrl->redirectByClass(array("ilobjquestionpoolgui", get_class($q_gui)), "editQuestion");
354  }
355  }
356 
357  function feedback()
358  {
359  global $ilCtrl, $ilTabs;
360 
361 
362 
363  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
364  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
365 
366  $ilTabs->setTabActive('feedback');
367 
368  $q_ref = $this->content_obj->getQuestionReference();
369 
370  if ($q_ref != "")
371  {
372  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
373  if (!($inst_id > 0))
374  {
376  }
377  }
378 
379  $ilCtrl->setCmdClass("ilquestioneditgui");
380  $ilCtrl->setCmd("feedback");
381  $edit_gui = new ilQuestionEditGUI();
382  if ($q_id > 0)
383  {
384  $edit_gui->setQuestionId($q_id);
385  }
386 // $edit_gui->setQuestionType("assSingleChoice");
387  $edit_gui->setSelfAssessmentEditingMode(true);
388  $edit_gui->setPageConfig($this->getPageConfig());
389  $ret = $ilCtrl->forwardCommand($edit_gui);
390  $this->tpl->setContent($ret);
391  return $ret;
392 
393  }
402  function createQuestionPool($name = "Dummy")
403  {
404  global $tree;
405  $parent_ref = $tree->getParentId($_GET["ref_id"]);
406  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
407  $qpl = new ilObjQuestionPool();
408  $qpl->setType("qpl");
409  $qpl->setTitle($name);
410  $qpl->setDescription("");
411  $qpl->create();
412  $qpl->createReference();
413  $qpl->putInTree($parent_ref);
414  $qpl->setPermissions($parent_ref);
415  $qpl->setOnline(1); // must be online to be available
416  $qpl->saveToDb();
417  return $qpl->getRefId();
418  }
419 
423  function setTabs()
424  {
425  global $ilTabs, $ilCtrl, $lng;
426  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
427 
428  if ($this->content_obj!="") {
429  $q_ref = $this->content_obj->getQuestionReference();
430  }
431 
432  if ($q_ref != "")
433  {
434  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
435  if (!($inst_id > 0))
436  {
438  }
439  }
440 
441  $ilTabs->addTarget("question",
442  $ilCtrl->getLinkTarget($this, "edit"), array("editQuestion", "save", "cancel", "addSuggestedSolution",
443  "cancelExplorer", "linkChilds", "removeSuggestedSolution",
444  "addPair", "addTerm", "delete", "deleteTerms", "editMode", "upload",
445  "saveEdit","uploadingImage", "uploadingImagemap", "addArea",
446  "deletearea", "saveShape", "back", "saveEdit", "changeGapType","createGaps","addItem","addYesNo", "addTrueFalse",
447  "toggleGraphicalAnswers", "setMediaMode"),
448  "");
449 
450  if ($q_id > 0)
451  {
452  if (assQuestion::_getQuestionType($q_id)!= "assTextQuestion")
453  {
454  $ilTabs->addTarget("feedback",
455  $ilCtrl->getLinkTarget($this, "feedback"), array("feedback","saveFeedback"),
456  "");
457  }
458  }
459  }
460 
464 
468  function insertFromPool()
469  {
470  global $ilCtrl, $ilAccess, $ilTabs, $tpl, $lng, $ilToolbar;
471 //var_dump($_SESSION["cont_qst_pool"]);
472  if ($_SESSION["cont_qst_pool"] != "" &&
473  $ilAccess->checkAccess("write", "", $_SESSION["cont_qst_pool"])
474  && ilObject::_lookupType(ilObject::_lookupObjId($_SESSION["cont_qst_pool"])) == "qpl")
475  {
476  $this->listPoolQuestions();
477  }
478  else
479  {
480  $this->poolSelection();
481  }
482  }
483 
490  function poolSelection()
491  {
492  global $ilCtrl, $tree, $tpl, $ilTabs;
493 
494  $this->setInsertTabs("copy_question");
495 
496  include_once "./Services/COPage/classes/class.ilPoolSelectorGUI.php";
497 
498  $exp = new ilPoolSelectorGUI($ilCtrl->getLinkTarget($this, "insert"));
499 
500  if ($_GET["expand"] == "")
501  {
502  $expanded = $tree->readRootId();
503  }
504  else
505  {
506  $expanded = $_GET["expand"];
507  }
508  $exp->setExpand($expanded);
509 
510  $exp->setTargetGet("sel_id");
511  $ilCtrl->setParameter($this, "target_type", $a_type);
512  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
513  $exp->setParamsGet($this->ctrl->getParameterArray($this, "insert"));
514 
515  // filter
516  $exp->setFiltered(true);
517  $exp->setFilterMode(IL_FM_POSITIVE);
518  $exp->addFilter("root");
519  $exp->addFilter("cat");
520  $exp->addFilter("grp");
521  $exp->addFilter("fold");
522  $exp->addFilter("crs");
523  $exp->addFilter("qpl");
524  $exp->setContentGUIClass("ilpcquestiongui");
525  $exp->setSelectableTypes(array('qpl'));
526 
527  $exp->setOutput(0);
528 
529  $tpl->setContent($exp->getOutput());
530  }
531 
535  function selectPool()
536  {
537  global $ilCtrl;
538 
539  $_SESSION["cont_qst_pool"] = $_GET["pool_ref_id"];
540  $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
541  $ilCtrl->redirect($this, "insert");
542  }
543 
550  function listPoolQuestions()
551  {
552  global $ilToolbar, $tpl, $ilCtrl, $lng;
553 
554  ilUtil::sendInfo($lng->txt("cont_cp_question_diff_formats_info"));
555 
556  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
557  $ilToolbar->addButton(
558  $lng->txt("cont_select_other_qpool"),
559  $ilCtrl->getLinkTarget($this, "insert"));
560  $ilCtrl->setParameter($this, "subCmd", "");
561 
562  $this->setInsertTabs("copy_question");
563 
564  include_once "./Services/COPage/classes/class.ilCopySelfAssQuestionTableGUI.php";
565 
566  $ilCtrl->setParameter($this, "subCmd", "listPoolQuestions");
567  $table_gui = new ilCopySelfAssQuestionTableGUI($this, 'insert',
568  $_SESSION["cont_qst_pool"]);
569 
570  $tpl->setContent($table_gui->getHTML());
571  }
572 
579  function copyQuestion()
580  {
581  global $ilCtrl;
582 
583  $this->content_obj = new ilPCQuestion($this->dom);
584  $this->content_obj->create($this->pg_obj, $_GET["hier_id"]);
585 
586  $this->content_obj->copyPoolQuestionIntoPage(
587  (int) $_GET["q_id"], $_GET["hier_id"]);
588 
589  $this->updated = $this->pg_obj->update();
590 
591  $ilCtrl->returnToParent($this);
592  }
593 
594 }
595 ?>