ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 __construct(&$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::__construct($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  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
506  $exp = new ilPoolSelectorGUI($this, "insert");
507 
508  // filter
509  $exp->setTypeWhiteList(array("root", "cat", "grp", "fold", "crs", "qpl"));
510  $exp->setClickableTypes(array('qpl'));
511 
512  if (!$exp->handleCommand())
513  {
514  $tpl->setContent($exp->getHTML());
515  }
516 
517  }
518 
522  function selectPool()
523  {
524  global $ilCtrl;
525 
526  $_SESSION["cont_qst_pool"] = $_GET["pool_ref_id"];
527  $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
528  $ilCtrl->redirect($this, "insert");
529  }
530 
537  function listPoolQuestions()
538  {
539  global $ilToolbar, $tpl, $ilCtrl, $lng;
540 
541  ilUtil::sendInfo($lng->txt("cont_cp_question_diff_formats_info"));
542 
543  $ilCtrl->setParameter($this, "subCmd", "poolSelection");
544  $ilToolbar->addButton(
545  $lng->txt("cont_select_other_qpool"),
546  $ilCtrl->getLinkTarget($this, "insert"));
547  $ilCtrl->setParameter($this, "subCmd", "");
548 
549  $this->setInsertTabs("copy_question");
550 
551  include_once "./Services/COPage/classes/class.ilCopySelfAssQuestionTableGUI.php";
552 
553  $ilCtrl->setParameter($this, "subCmd", "listPoolQuestions");
554  $table_gui = new ilCopySelfAssQuestionTableGUI($this, 'insert',
555  $_SESSION["cont_qst_pool"]);
556 
557  $tpl->setContent($table_gui->getHTML());
558  }
559 
566  function copyQuestion()
567  {
568  global $ilCtrl;
569 
570  $this->content_obj = new ilPCQuestion($this->getPage());
571  $this->content_obj->create($this->pg_obj, $_GET["hier_id"]);
572 
573  $this->content_obj->copyPoolQuestionIntoPage(
574  (int) $_GET["q_id"], $_GET["hier_id"]);
575 
576  $this->updated = $this->pg_obj->update();
577 
578  $ilCtrl->returnToParent($this);
579  }
580 
581 }
582 ?>
This class represents an option in a radio group.
setInsertTabs($a_active)
Set insert tabs.
Class ilQuestionEditGUI.
$_SESSION["AccountId"]
static _getQuestionType($question_id)
Returns the question type of a question with a given id.
This class represents a selection list property in a property form.
This class represents a property form user interface.
const ADDITIONAL_CONTENT_EDITING_MODE_PAGE_OBJECT
constant for additional content editing mode "pageobject"
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
setSelfAssessmentMode($a_selfassessmentmode)
Set Self Assessment Mode.
create()
Create new question.
getPageConfig()
Get Page Config.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
setNewQuestionId($a_par)
Set new question id.
poolSelection()
Pool selection.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class ilPCQuestionGUI.
static getCommandsFromClassConstants($guiClassName, $cmdConstantNameBegin='CMD_')
extracts values of all constants of given class with given prefix as array can be used to get all pos...
This class represents a hidden form property in a property form.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
This class represents a property in a property form.
addOption($a_option)
Add Option.
createQuestionPool($name="Dummy")
Creates a new questionpool and returns the reference id.
if(!is_array($argv)) $options
Class ilPCQuestion.
static _getQuestionGUI($question_type, $question_id=-1)
Creates a question gui representation and returns the alias to the question gui note: please do not u...
static _lookupObjId($a_id)
displayValidationError()
display validation errors
$ilUser
Definition: imgupload.php:18
insert($a_mode="create")
Insert new question form.
selectPool()
Select concrete question pool.
executeCommand()
execute command
setOptions($a_options)
Set Options.
Table to select self assessment questions for copying into learning resources.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
const ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT
constant for additional content editing mode "default"
listPoolQuestions()
List questions of pool.
insertFromPool()
Insert question from ppol.
getSelfAssessmentMode()
Get Self Assessment Mode.
Select media pool for adding objects into pages.
static & _getSelfAssessmentQuestionTypes($all_tags=FALSE)
Get all self assessment question types.
$ret
Definition: parser.php:6
static isAdditionalQuestionContentEditingModePageObjectEnabled()
returns the fact wether content editing with ilias page editor is enabled for questions or not ...
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor public.
$_POST["username"]
copyQuestion()
Copy question into page.