ILIAS  Release_4_1_x_branch Revision 61804
 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  $this->setTabs();
96  }
97  $ret = $this->$cmd();
98  }
99 
100 
101 
102  return $ret;
103  }
104 
110  function setSelfAssessmentMode($a_selfassessmentmode)
111  {
112  $this->selfassessmentmode = $a_selfassessmentmode;
113  }
114 
121  {
122  return $this->selfassessmentmode;
123  }
124 
125 
126 
127 
131  function insert($a_mode = "create")
132  {
133  global $ilUser, $lng, $ilCtrl;
134 
135  $this->displayValidationError();
136 
137  // get all question types (@todo: we have to check, whether they are
138  // suitable for self assessment or not)
139  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
141  $options = array();
142  $all_types = ilUtil::sortArray($all_types, "question_type_id", "asc", true, true);
143 
144  foreach ($all_types as $k => $v)
145  {
146  $options[$v["type_tag"]] = $k;
147  }
148 
149  // new table form (input of rows and columns)
150  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
151  $this->form_gui = new ilPropertyFormGUI();
152  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
153  $this->form_gui->setTitle($lng->txt("cont_ed_insert_pcqst"));
154 
155  // Select Question Type
156  $qtype_input = new ilSelectInputGUI($lng->txt("cont_question_type"), "q_type");
157  $qtype_input->setOptions($options);
158  $qtype_input->setRequired(true);
159  $this->form_gui->addItem($qtype_input);
160 
161  // Select Question Pool
162 /*
163  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
164  $qpools = ilObjQuestionPool::_getAvailableQuestionpools(false, false, false, true, false, "write");
165 
166  if (count($qpools) > 0)
167  {
168  $pool_options = array();
169  foreach ($qpools as $key => $value)
170  {
171  $pool_options[$key] = $value["title"];
172  }
173  $pool_input = new ilSelectInputGUI($lng->txt("cont_question_pool"), "qpool_ref_id");
174  $pool_input->setOptions($pool_options);
175  $pool_input->setRequired(true);
176  $this->form_gui->addItem($pool_input);
177  }
178  else
179  {
180  $pool_input = new ilTextInputGUI($lng->txt("cont_question_pool"), "qpool_title");
181  $pool_input->setRequired(true);
182  $this->form_gui->addItem($pool_input);
183  }
184 */
185  if ($a_mode == "edit_empty")
186  {
187  $this->form_gui->addCommandButton("edit", $lng->txt("save"));
188  }
189  else
190  {
191  $this->form_gui->addCommandButton("create_pcqst", $lng->txt("save"));
192  $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
193  }
194 
195  $this->tpl->setContent($this->form_gui->getHTML());
196  }
197 
198 
202  function create()
203  {
204  global $lng, $ilCtrl, $ilTabs;
205 
206  $ilTabs->setTabActive('question');
207 
208  $this->content_obj = new ilPCQuestion($this->dom);
209  $this->content_obj->create($this->pg_obj, $this->hier_id);
210 
211  $this->updated = $this->pg_obj->update();
212 
213  if ($this->updated)
214  {
215  // create question pool, if necessary
216 /* if ($_POST["qpool_ref_id"] <= 0)
217  {
218  $pool_ref_id = $this->createQuestionPool($_POST["qpool_title"]);
219  }
220  else
221  {
222  $pool_ref_id = $_POST["qpool_ref_id"];
223  }*/
224 
225  $this->pg_obj->stripHierIDs();
226  $this->pg_obj->addHierIDs();
227  $hier_id = $this->content_obj->lookupHierId();
228  $ilCtrl->setParameter($this, "q_type", $_POST["q_type"]);
229 // $ilCtrl->setParameter($this, "qpool_ref_id", $pool_ref_id);
230  //$ilCtrl->setParameter($this, "hier_id", $hier_id);
231  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
232  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
233 
234  $ilCtrl->redirect($this, "edit");
235  }
236 
237  $this->insert();
238  }
239 
243  function setNewQuestionId($a_par)
244  {
245  if ($a_par["new_id"] > 0)
246  {
247  $this->content_obj->setQuestionReference("il__qst_".$a_par["new_id"]);
248  $this->pg_obj->update();
249  }
250  }
251 
255  function edit()
256  {
257  global $ilCtrl, $ilTabs;
258 
259  $ilTabs->setTabActive('question');
260 
261 
262  if ($this->getSelfAssessmentMode()) // behaviour in content pages, e.g. scorm
263  {
264  $q_ref = $this->content_obj->getQuestionReference();
265 
266  if ($q_ref != "")
267  {
268  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
269  if (!($inst_id > 0))
270  {
272  }
273  }
274 
275  $q_type = ($_POST["q_type"] != "")
276  ? $_POST["q_type"]
277  : $_GET["q_type"];
278  $ilCtrl->setParameter($this, "q_type", $q_type);
279 
280 // @todo: check access stuff
281 
282  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
283  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
284  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
285 
286  $ilCtrl->setCmdClass("ilquestioneditgui");
287  $ilCtrl->setCmd("editQuestion");
288  $edit_gui = new ilQuestionEditGUI();
289 
290  if ($q_id > 0)
291  {
292  $edit_gui->setQuestionId($q_id);
293 // $edit_gui->setPoolObjId(assQuestion::_lookupQPoolId($q_id));
294 $edit_gui->setPoolObjId(0);
295  }
296  else
297  {
298  if ($_GET["qpool_ref_id"] > 0)
299  {
300  $edit_gui->setPoolRefId($_GET["qpool_ref_id"]);
301 $edit_gui->setPoolRefId(0);
302  }
303  //set default tries
304  $edit_gui->setDefaultNrOfTries(ilObjSAHSLearningModule::_getTries($this->scormlmid));
305  }
306 
307  if ($q_id == "" && $q_type == "")
308  {
309  return $this->insert("edit_empty");
310  }
311 
312  $edit_gui->setQuestionType($q_type);
313  $edit_gui->setSelfAssessmentEditingMode(true);
314  $edit_gui->setPageConfig($this->getPageConfig());
315  $ret = $ilCtrl->forwardCommand($edit_gui);
316  $this->tpl->setContent($ret);
317  return $ret;
318  }
319  else // behaviour in question pool
320  {
321  require_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
322  $q_gui =& assQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
323  $this->ctrl->redirectByClass(array("ilobjquestionpoolgui", get_class($q_gui)), "editQuestion");
324  }
325  }
326 
327  function feedback()
328  {
329  global $ilCtrl, $ilTabs;
330 
331 
332 
333  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
334  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
335 
336  $ilTabs->setTabActive('feedback');
337 
338  $q_ref = $this->content_obj->getQuestionReference();
339 
340  if ($q_ref != "")
341  {
342  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
343  if (!($inst_id > 0))
344  {
346  }
347  }
348 
349  $ilCtrl->setCmdClass("ilquestioneditgui");
350  $ilCtrl->setCmd("feedback");
351  $edit_gui = new ilQuestionEditGUI();
352  if ($q_id > 0)
353  {
354  $edit_gui->setQuestionId($q_id);
355  }
356 // $edit_gui->setQuestionType("assSingleChoice");
357  $edit_gui->setSelfAssessmentEditingMode(true);
358  $edit_gui->setPageConfig($this->getPageConfig());
359  $ret = $ilCtrl->forwardCommand($edit_gui);
360  $this->tpl->setContent($ret);
361  return $ret;
362 
363  }
372  function createQuestionPool($name = "Dummy")
373  {
374  global $tree;
375  $parent_ref = $tree->getParentId($_GET["ref_id"]);
376  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
377  $qpl = new ilObjQuestionPool();
378  $qpl->setType("qpl");
379  $qpl->setTitle($name);
380  $qpl->setDescription("");
381  $qpl->create();
382  $qpl->createReference();
383  $qpl->putInTree($parent_ref);
384  $qpl->setPermissions($parent_ref);
385  $qpl->setOnline(1); // must be online to be available
386  $qpl->saveToDb();
387  return $qpl->getRefId();
388  }
389 
393  function setTabs()
394  {
395  global $ilTabs, $ilCtrl, $lng;
396  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
397 
398  if ($this->content_obj!="") {
399  $q_ref = $this->content_obj->getQuestionReference();
400  }
401 
402  if ($q_ref != "")
403  {
404  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
405  if (!($inst_id > 0))
406  {
408  }
409  }
410 
411  $ilTabs->addTarget("question",
412  $ilCtrl->getLinkTarget($this, "edit"), array("editQuestion", "save", "cancel", "addSuggestedSolution",
413  "cancelExplorer", "linkChilds", "removeSuggestedSolution",
414  "addPair", "addTerm", "delete", "deleteTerms", "editMode", "upload",
415  "saveEdit","uploadingImage", "uploadingImagemap", "addArea",
416  "deletearea", "saveShape", "back", "saveEdit", "changeGapType","createGaps","addItem","addYesNo", "addTrueFalse",
417  "toggleGraphicalAnswers", "setMediaMode"),
418  "");
419 
420  if ($q_id > 0) {
421  $q_obj = new assQuestion();
422 
423  if ($q_obj->_getQuestionType($q_id)!= "assTextQuestion")
424  {
425  $ilTabs->addTarget("feedback",
426  $ilCtrl->getLinkTarget($this, "feedback"), array("feedback","saveFeedback"),
427  "");
428  }
429  }
430  }
431 
432 }
433 ?>