ILIAS  Release_4_2_x_branch Revision 61807
 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  $q_obj = new assQuestion();
452 
453  if ($q_obj->_getQuestionType($q_id)!= "assTextQuestion")
454  {
455  $ilTabs->addTarget("feedback",
456  $ilCtrl->getLinkTarget($this, "feedback"), array("feedback","saveFeedback"),
457  "");
458  }
459  }
460  }
461 
465 
469  function insertFromPool()
470  {
471  global $ilCtrl, $ilAccess, $ilTabs, $tpl, $lng, $ilToolbar;
472 //var_dump($_SESSION["cont_qst_pool"]);
473  if ($_SESSION["cont_qst_pool"] != "" &&
474  $ilAccess->checkAccess("write", "", $_SESSION["cont_qst_pool"])
475  && ilObject::_lookupType(ilObject::_lookupObjId($_SESSION["cont_qst_pool"])) == "qpl")
476  {
477  $this->listPoolQuestions();
478  }
479  else
480  {
481  $this->poolSelection();
482  }
483  }
484 
491  function poolSelection()
492  {
493  global $ilCtrl, $tree, $tpl, $ilTabs;
494 
495  $this->setInsertTabs("copy_question");
496 
497  include_once "./Services/COPage/classes/class.ilPoolSelectorGUI.php";
498 
499  $exp = new ilPoolSelectorGUI($ilCtrl->getLinkTarget($this, "insert"));
500 
501  if ($_GET["expand"] == "")
502  {
503  $expanded = $tree->readRootId();
504  }
505  else
506  {
507  $expanded = $_GET["expand"];
508  }
509  $exp->setExpand($expanded);
510 
511  $exp->setTargetGet("sel_id");
512  $ilCtrl->setParameter($this, "target_type", $a_type);
513  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
514  $exp->setParamsGet($this->ctrl->getParameterArray($this, "insert"));
515 
516  // filter
517  $exp->setFiltered(true);
518  $exp->setFilterMode(IL_FM_POSITIVE);
519  $exp->addFilter("root");
520  $exp->addFilter("cat");
521  $exp->addFilter("grp");
522  $exp->addFilter("fold");
523  $exp->addFilter("crs");
524  $exp->addFilter("qpl");
525  $exp->setContentGUIClass("ilpcquestiongui");
526  $exp->setSelectableTypes(array('qpl'));
527 
528  $exp->setOutput(0);
529 
530  $tpl->setContent($exp->getOutput());
531  }
532 
536  function selectPool()
537  {
538  global $ilCtrl;
539 
540  $_SESSION["cont_qst_pool"] = $_GET["pool_ref_id"];
541  $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
542  $ilCtrl->redirect($this, "insert");
543  }
544 
551  function listPoolQuestions()
552  {
553  global $ilToolbar, $tpl, $ilCtrl, $lng;
554 
555  ilUtil::sendInfo($lng->txt("cont_cp_question_diff_formats_info"));
556 
557  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
558  $ilToolbar->addButton(
559  $lng->txt("cont_select_other_qpool"),
560  $ilCtrl->getLinkTarget($this, "insert"));
561  $ilCtrl->setParameter($this, "subCmd", "");
562 
563  $this->setInsertTabs("copy_question");
564 
565  include_once "./Services/COPage/classes/class.ilCopySelfAssQuestionTableGUI.php";
566 
567  $ilCtrl->setParameter($this, "subCmd", "listPoolQuestions");
568  $table_gui = new ilCopySelfAssQuestionTableGUI($this, 'insert',
569  $_SESSION["cont_qst_pool"]);
570 
571  $tpl->setContent($table_gui->getHTML());
572  }
573 
580  function copyQuestion()
581  {
582  global $ilCtrl;
583 
584  $this->content_obj = new ilPCQuestion($this->dom);
585  $this->content_obj->create($this->pg_obj, $_GET["hier_id"]);
586 
587  $this->content_obj->copyPoolQuestionIntoPage(
588  (int) $_GET["q_id"], $_GET["hier_id"]);
589 
590  $this->updated = $this->pg_obj->update();
591 
592  $ilCtrl->returnToParent($this);
593  }
594 
595 }
596 ?>