ILIAS  Release_4_0_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 
20 {
25  function ilPCQuestionGUI(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
26  {
27  global $ilCtrl;
28  $this->scormlmid = $a_pg_obj->parent_id;
29  parent::ilPageContentGUI($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
30  $ilCtrl->saveParameter($this, array("qpool_ref_id"));
31  }
32 
36  function &executeCommand()
37  {
38  global $ilCtrl;
39 
40  // get current command
41  $cmd = $ilCtrl->getCmd();
42  $next_class = $ilCtrl->getNextClass($this);
43 
44  $q_type = ($_POST["q_type"] != "")
45  ? $_POST["q_type"]
46  : $_GET["q_type"];
47 
48 
49 
50  switch($next_class)
51  {
52 
53  case "ilquestioneditgui":
54  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
55 
56  $edit_gui = new ilQuestionEditGUI();
57  if ($q_type != "")
58  {
59  $edit_gui->setQuestionType($q_type);
60  }
61  //$edit_gui->setPoolRefId($qpool_ref_id);
62  $this->setTabs();
63  $edit_gui->addNewIdListener($this, "setNewQuestionId");
64  $edit_gui->setSelfAssessmentEditingMode(true);
65  $ret = $ilCtrl->forwardCommand($edit_gui);
66  $this->tpl->setContent($ret);
67  break;
68 
69  default:
70  //set tabs
71  if ($cmd != "insert") {
72  $this->setTabs();
73  }
74  $ret = $this->$cmd();
75  }
76 
77 
78 
79  return $ret;
80  }
81 
87  function setSelfAssessmentMode($a_selfassessmentmode)
88  {
89  $this->selfassessmentmode = $a_selfassessmentmode;
90  }
91 
98  {
99  return $this->selfassessmentmode;
100  }
101 
102 
103 
104 
108  function insert($a_mode = "create")
109  {
110  global $ilUser, $lng, $ilCtrl;
111 
112  $this->displayValidationError();
113 
114  // get all question types (@todo: we have to check, whether they are
115  // suitable for self assessment or not)
116  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
118  $options = array();
119  $all_types = ilUtil::sortArray($all_types, "question_type_id", "asc", true, true);
120 
121  foreach ($all_types as $k => $v)
122  {
123  $options[$v["type_tag"]] = $k;
124  }
125 
126  // new table form (input of rows and columns)
127  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
128  $this->form_gui = new ilPropertyFormGUI();
129  $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
130  $this->form_gui->setTitle($lng->txt("cont_ed_insert_pcqst"));
131 
132  // Select Question Type
133  $qtype_input = new ilSelectInputGUI($lng->txt("cont_question_type"), "q_type");
134  $qtype_input->setOptions($options);
135  $qtype_input->setRequired(true);
136  $this->form_gui->addItem($qtype_input);
137 
138  // Select Question Pool
139 /*
140  include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
141  $qpools = ilObjQuestionPool::_getAvailableQuestionpools(false, false, false, true, false, "write");
142 
143  if (count($qpools) > 0)
144  {
145  $pool_options = array();
146  foreach ($qpools as $key => $value)
147  {
148  $pool_options[$key] = $value["title"];
149  }
150  $pool_input = new ilSelectInputGUI($lng->txt("cont_question_pool"), "qpool_ref_id");
151  $pool_input->setOptions($pool_options);
152  $pool_input->setRequired(true);
153  $this->form_gui->addItem($pool_input);
154  }
155  else
156  {
157  $pool_input = new ilTextInputGUI($lng->txt("cont_question_pool"), "qpool_title");
158  $pool_input->setRequired(true);
159  $this->form_gui->addItem($pool_input);
160  }
161 */
162  if ($a_mode == "edit_empty")
163  {
164  $this->form_gui->addCommandButton("edit", $lng->txt("save"));
165  }
166  else
167  {
168  $this->form_gui->addCommandButton("create_pcqst", $lng->txt("save"));
169  $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
170  }
171 
172  $this->tpl->setContent($this->form_gui->getHTML());
173  }
174 
175 
179  function create()
180  {
181  global $lng, $ilCtrl, $ilTabs;
182 
183  $ilTabs->setTabActive('question');
184 
185  $this->content_obj = new ilPCQuestion($this->dom);
186  $this->content_obj->create($this->pg_obj, $this->hier_id);
187 
188  $this->updated = $this->pg_obj->update();
189 
190  if ($this->updated)
191  {
192  // create question pool, if necessary
193 /* if ($_POST["qpool_ref_id"] <= 0)
194  {
195  $pool_ref_id = $this->createQuestionPool($_POST["qpool_title"]);
196  }
197  else
198  {
199  $pool_ref_id = $_POST["qpool_ref_id"];
200  }*/
201 
202  $this->pg_obj->stripHierIDs();
203  $this->pg_obj->addHierIDs();
204  $hier_id = $this->content_obj->lookupHierId();
205  $ilCtrl->setParameter($this, "q_type", $_POST["q_type"]);
206 // $ilCtrl->setParameter($this, "qpool_ref_id", $pool_ref_id);
207  //$ilCtrl->setParameter($this, "hier_id", $hier_id);
208  $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
209  $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
210 
211  $ilCtrl->redirect($this, "edit");
212  }
213 
214  $this->insert();
215  }
216 
220  function setNewQuestionId($a_par)
221  {
222  if ($a_par["new_id"] > 0)
223  {
224  $this->content_obj->setQuestionReference("il__qst_".$a_par["new_id"]);
225  $this->pg_obj->update();
226  }
227  }
228 
232  function edit()
233  {
234  global $ilCtrl, $ilTabs;
235 
236  $ilTabs->setTabActive('question');
237 
238 
239  if ($this->getSelfAssessmentMode()) // behaviour in content pages, e.g. scorm
240  {
241  $q_ref = $this->content_obj->getQuestionReference();
242 
243  if ($q_ref != "")
244  {
245  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
246  if (!($inst_id > 0))
247  {
249  }
250  }
251 
252  $q_type = ($_POST["q_type"] != "")
253  ? $_POST["q_type"]
254  : $_GET["q_type"];
255  $ilCtrl->setParameter($this, "q_type", $q_type);
256 
257 // @todo: check access stuff
258 
259  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
260  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
261  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
262 
263  $ilCtrl->setCmdClass("ilquestioneditgui");
264  $ilCtrl->setCmd("editQuestion");
265  $edit_gui = new ilQuestionEditGUI();
266 
267  if ($q_id > 0)
268  {
269  $edit_gui->setQuestionId($q_id);
270 // $edit_gui->setPoolObjId(assQuestion::_lookupQPoolId($q_id));
271 $edit_gui->setPoolObjId(0);
272  }
273  else
274  {
275  if ($_GET["qpool_ref_id"] > 0)
276  {
277  $edit_gui->setPoolRefId($_GET["qpool_ref_id"]);
278 $edit_gui->setPoolRefId(0);
279  }
280  //set default tries
281  $edit_gui->setDefaultNrOfTries(ilObjSAHSLearningModule::_getTries($this->scormlmid));
282  }
283 
284  if ($q_id == "" && $q_type == "")
285  {
286  return $this->insert("edit_empty");
287  }
288 
289  $edit_gui->setQuestionType($q_type);
290  $edit_gui->setSelfAssessmentEditingMode(true);
291  $ret = $ilCtrl->forwardCommand($edit_gui);
292  $this->tpl->setContent($ret);
293  return $ret;
294  }
295  else // behaviour in question pool
296  {
297  require_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
298  $q_gui =& assQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
299  $this->ctrl->redirectByClass(array("ilobjquestionpoolgui", get_class($q_gui)), "editQuestion");
300  }
301  }
302 
303  function feedback()
304  {
305  global $ilCtrl, $ilTabs;
306 
307 
308 
309  include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
310  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
311 
312  $ilTabs->setTabActive('feedback');
313 
314  $q_ref = $this->content_obj->getQuestionReference();
315 
316  if ($q_ref != "")
317  {
318  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
319  if (!($inst_id > 0))
320  {
322  }
323  }
324 
325  $ilCtrl->setCmdClass("ilquestioneditgui");
326  $ilCtrl->setCmd("feedback");
327  $edit_gui = new ilQuestionEditGUI();
328  if ($q_id > 0)
329  {
330  $edit_gui->setQuestionId($q_id);
331  }
332 // $edit_gui->setQuestionType("assSingleChoice");
333  $edit_gui->setSelfAssessmentEditingMode(true);
334  $ret = $ilCtrl->forwardCommand($edit_gui);
335  $this->tpl->setContent($ret);
336  return $ret;
337 
338  }
347  function createQuestionPool($name = "Dummy")
348  {
349  global $tree;
350  $parent_ref = $tree->getParentId($_GET["ref_id"]);
351  include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
352  $qpl = new ilObjQuestionPool();
353  $qpl->setType("qpl");
354  $qpl->setTitle($name);
355  $qpl->setDescription("");
356  $qpl->create();
357  $qpl->createReference();
358  $qpl->putInTree($parent_ref);
359  $qpl->setPermissions($parent_ref);
360  $qpl->setOnline(1); // must be online to be available
361  $qpl->saveToDb();
362  return $qpl->getRefId();
363  }
364 
368  function setTabs()
369  {
370  global $ilTabs, $ilCtrl, $lng;
371  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
372 
373  if ($this->content_obj!="") {
374  $q_ref = $this->content_obj->getQuestionReference();
375  }
376 
377  if ($q_ref != "")
378  {
379  $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
380  if (!($inst_id > 0))
381  {
383  }
384  }
385 
386  $ilTabs->addTarget("question",
387  $ilCtrl->getLinkTarget($this, "edit"), array("editQuestion", "save", "cancel", "addSuggestedSolution",
388  "cancelExplorer", "linkChilds", "removeSuggestedSolution",
389  "addPair", "addTerm", "delete", "deleteTerms", "editMode", "upload",
390  "saveEdit","uploadingImage", "uploadingImagemap", "addArea",
391  "deletearea", "saveShape", "back", "saveEdit", "changeGapType","createGaps","addItem","addYesNo", "addTrueFalse",
392  "toggleGraphicalAnswers", "setMediaMode"),
393  "");
394 
395  if ($q_id > 0) {
396  $q_obj = new assQuestion();
397 
398  if ($q_obj->_getQuestionType($q_id)!= "assTextQuestion")
399  {
400  $ilTabs->addTarget("feedback",
401  $ilCtrl->getLinkTarget($this, "feedback"), array("feedback","saveFeedback"),
402  "");
403  }
404  }
405  }
406 
407 }
408 ?>