ILIAS  release_7 Revision v7.30-3-g800a261c036
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
4include_once "./Services/COPage/classes/class.ilPageContentGUI.php";
5include_once "./Services/COPage/classes/class.ilPCQuestion.php";
6
19{
23 protected $access;
24
28 protected $tabs;
29
33 protected $user;
34
38 protected $tree;
39
43 protected $toolbar;
44
49 public function __construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id = "")
50 {
51 global $DIC;
52
53 $this->ctrl = $DIC->ctrl();
54 $this->access = $DIC->access();
55 $this->tpl = $DIC["tpl"];
56 $this->tabs = $DIC->tabs();
57 $this->lng = $DIC->language();
58 $this->user = $DIC->user();
59 $this->tree = $DIC->repositoryTree();
60 $this->toolbar = $DIC->toolbar();
61 $ilCtrl = $DIC->ctrl();
62 $this->scormlmid = $a_pg_obj->parent_id;
63 parent::__construct($a_pg_obj, $a_content_obj, $a_hier_id, $a_pc_id);
64 $ilCtrl->saveParameter($this, array("qpool_ref_id"));
65 }
66
70 public function executeCommand()
71 {
72 $ilCtrl = $this->ctrl;
73 $ilAccess = $this->access;
75 $ilTabs = $this->tabs;
77
78 // get current command
79 $cmd = $ilCtrl->getCmd();
80 $next_class = $ilCtrl->getNextClass($this);
81
82 $q_type = ($_POST["q_type"] != "")
83 ? $_POST["q_type"]
84 : $_GET["q_type"];
85
86 switch ($next_class) {
87 default:
88 //set tabs
89 if ($cmd != "insert") {
90 $this->setTabs();
91 } elseif ($_GET["subCmd"] != "") {
92 $cmd = $_GET["subCmd"];
93 }
94
95 $ret = $this->$cmd();
96 }
97
98
99
100 return $ret;
101 }
102
108 public function setSelfAssessmentMode($a_selfassessmentmode)
109 {
110 $this->selfassessmentmode = $a_selfassessmentmode;
111 }
112
118 public function getSelfAssessmentMode()
119 {
120 return $this->selfassessmentmode;
121 }
122
128 public function setInsertTabs($a_active)
129 {
130 $ilTabs = $this->tabs;
131 $ilCtrl = $this->ctrl;
133
134 // new question
135 $ilTabs->addSubTab(
136 "new_question",
137 $lng->txt("cont_new_question"),
138 $ilCtrl->getLinkTarget($this, "insert")
139 );
140
141 // copy from pool
142 $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
143 $ilTabs->addSubTab(
144 "copy_question",
145 $lng->txt("cont_copy_question_from_pool"),
146 $ilCtrl->getLinkTarget($this, "insert")
147 );
148
149 $ilTabs->activateSubTab($a_active);
150
151 $ilCtrl->setParameter($this, "subCmd", "");
152 }
153
157 public function insert($a_mode = "create")
158 {
161 $ilCtrl = $this->ctrl;
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 $options[$v["type_tag"]] = $k;
176 }
177
178 // new table form (input of rows and columns)
179 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
180 $this->form_gui = new ilPropertyFormGUI();
181 $this->form_gui->setFormAction($ilCtrl->getFormAction($this));
182 $this->form_gui->setTitle($lng->txt("cont_ed_insert_pcqst"));
183
184 // Select Question Type
185 $qtype_input = new ilSelectInputGUI($lng->txt("cont_question_type"), "q_type");
186 $qtype_input->setOptions($options);
187 $qtype_input->setRequired(true);
188 $this->form_gui->addItem($qtype_input);
189
190 // additional content editor
191 // assessment
192 include_once("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
194 $ri = new ilRadioGroupInputGUI($this->lng->txt("tst_add_quest_cont_edit_mode"), "add_quest_cont_edit_mode");
195
196 $option_rte = new ilRadioOption(
197 $this->lng->txt('tst_add_quest_cont_edit_mode_RTE'),
199 );
200 $option_rte->setInfo($this->lng->txt('tst_add_quest_cont_edit_mode_RTE_info'));
201 $ri->addOption($option_rte);
202
203 $option_ipe = new ilRadioOption(
204 $this->lng->txt('tst_add_quest_cont_edit_mode_IPE'),
206 );
207 $option_ipe->setInfo($this->lng->txt('tst_add_quest_cont_edit_mode_IPE_info'));
208 $ri->addOption($option_ipe);
209
211
212 $this->form_gui->addItem($ri, true);
213 } else {
214 $hi = new ilHiddenInputGUI("question_content_editing_type");
216 $this->form_gui->addItem($hi);
217 }
218
219
220 // Select Question Pool
221 /*
222 include_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php");
223 $qpools = ilObjQuestionPool::_getAvailableQuestionpools(false, false, false, true, false, "write");
224
225 if (count($qpools) > 0)
226 {
227 $pool_options = array();
228 foreach ($qpools as $key => $value)
229 {
230 $pool_options[$key] = $value["title"];
231 }
232 $pool_input = new ilSelectInputGUI($lng->txt("cont_question_pool"), "qpool_ref_id");
233 $pool_input->setOptions($pool_options);
234 $pool_input->setRequired(true);
235 $this->form_gui->addItem($pool_input);
236 }
237 else
238 {
239 $pool_input = new ilTextInputGUI($lng->txt("cont_question_pool"), "qpool_title");
240 $pool_input->setRequired(true);
241 $this->form_gui->addItem($pool_input);
242 }
243 */
244 if ($a_mode == "edit_empty") {
245 $this->form_gui->addCommandButton("edit", $lng->txt("save"));
246 } else {
247 $this->form_gui->addCommandButton("create_pcqst", $lng->txt("save"));
248 $this->form_gui->addCommandButton("cancelCreate", $lng->txt("cancel"));
249 }
250
251 $this->tpl->setContent($this->form_gui->getHTML());
252 }
253
254
258 public function create()
259 {
260 global $lng, $ilCtrl, $ilTabs;
261
262 $ilTabs->setTabActive('question');
263
264 $this->content_obj = new ilPCQuestion($this->getPage());
265 $this->content_obj->create($this->pg_obj, $this->hier_id);
266
267 $this->updated = $this->pg_obj->update();
268
269 if ($this->updated) {
270 // create question pool, if necessary
271 /* if ($_POST["qpool_ref_id"] <= 0)
272 {
273 $pool_ref_id = $this->createQuestionPool($_POST["qpool_title"]);
274 }
275 else
276 {
277 $pool_ref_id = $_POST["qpool_ref_id"];
278 }*/
279
280 $this->pg_obj->stripHierIDs();
281 $this->pg_obj->addHierIDs();
282 $hier_id = $this->content_obj->lookupHierId();
283 $ilCtrl->setParameter($this, "q_type", $_POST["q_type"]);
284 $ilCtrl->setParameter($this, "add_quest_cont_edit_mode", $_POST["add_quest_cont_edit_mode"]);
285 // $ilCtrl->setParameter($this, "qpool_ref_id", $pool_ref_id);
286 //$ilCtrl->setParameter($this, "hier_id", $hier_id);
287 $ilCtrl->setParameter($this, "hier_id", $this->content_obj->readHierId());
288 $ilCtrl->setParameter($this, "pc_id", $this->content_obj->readPCId());
289
290 $ilCtrl->redirect($this, "edit");
291 }
292
293 $this->insert();
294 }
295
299 public function setNewQuestionId($a_par)
300 {
301 if ($a_par["new_id"] > 0) {
302 $this->content_obj->setQuestionReference("il__qst_" . $a_par["new_id"]);
303 $this->pg_obj->update();
304 }
305 }
306
310 public function edit()
311 {
312 $ilCtrl = $this->ctrl;
313 $ilTabs = $this->tabs;
314
315 $ilTabs->setTabActive('question');
316
317
318 if ($this->getSelfAssessmentMode()) { // behaviour in content pages, e.g. scorm
319 $q_ref = $this->content_obj->getQuestionReference();
320
321 if ($q_ref != "") {
322 $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
323 if (!($inst_id > 0)) {
325 }
326 }
327
328 $q_type = ($_POST["q_type"] != "")
329 ? $_POST["q_type"]
330 : $_GET["q_type"];
331 $ilCtrl->setParameter($this, "q_type", $q_type);
332
333 if ($q_id == "" && $q_type == "") {
334 return $this->insert("edit_empty");
335 }
336
337 include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
338 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
339 include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
340
341 /* $ilCtrl->setCmdClass("ilquestioneditgui");
342 $ilCtrl->setCmd("editQuestion");
343 $edit_gui = new ilQuestionEditGUI();*/
344
345 // create question first-hand (needed for uploads)
346 if ($q_id < 1 && $q_type) {
347 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
348 $q_gui = assQuestionGUI::_getQuestionGUI($q_type);
349
350 // feedback editing mode
351 include_once("./Modules/Test/classes/class.ilObjAssessmentFolder.php");
353 && $_REQUEST['add_quest_cont_edit_mode'] != "") {
354 $addContEditMode = $_GET['add_quest_cont_edit_mode'];
355 } else {
357 }
358 $q_gui->object->setAdditionalContentEditingMode($addContEditMode);
359
360 //set default tries
361 $q_gui->object->setDefaultNrOfTries(ilObjSAHSLearningModule::_getTries($this->scormlmid));
362 $q_id = $q_gui->object->createNewQuestion(true);
363 $this->content_obj->setQuestionReference("il__qst_" . $q_id);
364 $this->pg_obj->update();
365 unset($q_gui);
366 }
367 $ilCtrl->setParameterByClass("ilQuestionEditGUI", "q_id", $q_id);
368 $ilCtrl->redirectByClass(array(get_class($this->pg_obj) . "GUI", "ilQuestionEditGUI"), "editQuestion");
369
370 /* $edit_gui->setPoolObjId(0);
371 $edit_gui->setQuestionId($q_id);
372 $edit_gui->setQuestionType($q_type);
373 $edit_gui->setSelfAssessmentEditingMode(true);
374 $edit_gui->setPageConfig($this->getPageConfig());
375 $ret = $ilCtrl->forwardCommand($edit_gui);
376 $this->tpl->setContent($ret);*/
377 return $ret;
378 } else { // behaviour in question pool
379 require_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
380 $q_gui = assQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
381 $this->ctrl->redirectByClass(array("ilobjquestionpoolgui", get_class($q_gui)), "editQuestion");
382 }
383 }
384
385 public function feedback()
386 {
387 $ilCtrl = $this->ctrl;
388 $ilTabs = $this->tabs;
389
390 include_once("./Modules/TestQuestionPool/classes/class.ilQuestionEditGUI.php");
391 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
392
393 $ilTabs->setTabActive('feedback');
394
395 $q_ref = $this->content_obj->getQuestionReference();
396
397 if ($q_ref != "") {
398 $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
399 if (!($inst_id > 0)) {
401 }
402 }
403
404 $ilCtrl->setCmdClass("ilquestioneditgui");
405 $ilCtrl->setCmd("feedback");
406 $edit_gui = new ilQuestionEditGUI();
407 if ($q_id > 0) {
408 $edit_gui->setQuestionId($q_id);
409 }
410 // $edit_gui->setQuestionType("assSingleChoice");
411 $edit_gui->setSelfAssessmentEditingMode(true);
412 $edit_gui->setPageConfig($this->getPageConfig());
413 $ret = $ilCtrl->forwardCommand($edit_gui);
414 $this->tpl->setContent($ret);
415 return $ret;
416 }
425 public function createQuestionPool($name = "Dummy")
426 {
428 $parent_ref = $tree->getParentId($_GET["ref_id"]);
429 include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php";
430 $qpl = new ilObjQuestionPool();
431 $qpl->setType("qpl");
432 $qpl->setTitle($name);
433 $qpl->setDescription("");
434 $qpl->create();
435 $qpl->createReference();
436 $qpl->putInTree($parent_ref);
437 $qpl->setPermissions($parent_ref);
438 $qpl->setOnline(1); // must be online to be available
439 $qpl->saveToDb();
440 return $qpl->getRefId();
441 }
442
446 public function setTabs()
447 {
448 if ($this->getSelfAssessmentMode()) {
449 return;
450 }
451
452 $ilTabs = $this->tabs;
453 $ilCtrl = $this->ctrl;
455 include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
456
457 if ($this->content_obj != "") {
458 $q_ref = $this->content_obj->getQuestionReference();
459 }
460
461 if ($q_ref != "") {
462 $inst_id = ilInternalLink::_extractInstOfTarget($q_ref);
463 if (!($inst_id > 0)) {
465 }
466 }
467
468 $ilTabs->addTarget(
469 "question",
470 $ilCtrl->getLinkTarget($this, "edit"),
471 array("editQuestion", "save", "cancel", "addSuggestedSolution",
472 "cancelExplorer", "linkChilds", "removeSuggestedSolution",
473 "addPair", "addTerm", "delete", "deleteTerms", "editMode", "upload",
474 "saveEdit","uploadingImage", "uploadingImagemap", "addArea",
475 "deletearea", "saveShape", "back", "saveEdit", "changeGapType","createGaps","addItem","addYesNo", "addTrueFalse",
476 "toggleGraphicalAnswers", "setMediaMode"),
477 ""
478 );
479
480 if ($q_id > 0) {
481 if (assQuestion::_getQuestionType($q_id) != "assTextQuestion") {
482 require_once 'Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
483 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackEditingGUI.php';
484 $tabCommands = assQuestionGUI::getCommandsFromClassConstants('ilAssQuestionFeedbackEditingGUI');
486 $ilCtrl->getLinkTargetByClass('ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW),
487 "q_id=" . (int) $q_id
488 );
489 $ilTabs->addTarget('feedback', $tabLink, $tabCommands, $ilCtrl->getCmdClass(), '');
490 }
491 }
492 }
493
497
501 public function insertFromPool()
502 {
503 $ilCtrl = $this->ctrl;
504 $ilAccess = $this->access;
505 $ilTabs = $this->tabs;
508 $ilToolbar = $this->toolbar;
509 //var_dump($_SESSION["cont_qst_pool"]);
510 if ($_SESSION["cont_qst_pool"] != "" &&
511 $ilAccess->checkAccess("write", "", $_SESSION["cont_qst_pool"])
512 && ilObject::_lookupType(ilObject::_lookupObjId($_SESSION["cont_qst_pool"])) == "qpl") {
513 $this->listPoolQuestions();
514 } else {
515 $this->poolSelection();
516 }
517 }
518
525 public function poolSelection()
526 {
527 $ilCtrl = $this->ctrl;
530 $ilTabs = $this->tabs;
531
532 $this->setInsertTabs("copy_question");
533
534 include_once "./Services/COPage/classes/class.ilPoolSelectorGUI.php";
535
536 $ilCtrl->setParameter($this, "subCmd", "poolSelection");
537 $exp = new ilPoolSelectorGUI($this, "insert");
538
539 // filter
540 $exp->setTypeWhiteList(array("root", "cat", "grp", "fold", "crs", "qpl"));
541 $exp->setClickableTypes(array('qpl'));
542
543 if (!$exp->handleCommand()) {
544 $tpl->setContent($exp->getHTML());
545 }
546 }
547
551 public function selectPool()
552 {
553 $ilCtrl = $this->ctrl;
554
555 $_SESSION["cont_qst_pool"] = $_GET["pool_ref_id"];
556 $ilCtrl->setParameter($this, "subCmd", "insertFromPool");
557 $ilCtrl->redirect($this, "insert");
558 }
559
566 public function listPoolQuestions()
567 {
568 $ilToolbar = $this->toolbar;
570 $ilCtrl = $this->ctrl;
572
573 ilUtil::sendInfo($lng->txt("cont_cp_question_diff_formats_info"));
574
575 $ilCtrl->setParameter($this, "subCmd", "poolSelection");
576 $ilToolbar->addButton(
577 $lng->txt("cont_select_other_qpool"),
578 $ilCtrl->getLinkTarget($this, "insert")
579 );
580 $ilCtrl->setParameter($this, "subCmd", "");
581
582 $this->setInsertTabs("copy_question");
583
584 include_once "./Services/COPage/classes/class.ilCopySelfAssQuestionTableGUI.php";
585
586 $ilCtrl->setParameter($this, "subCmd", "listPoolQuestions");
587 $table_gui = new ilCopySelfAssQuestionTableGUI(
588 $this,
589 'insert',
590 $_SESSION["cont_qst_pool"]
591 );
592
593 $tpl->setContent($table_gui->getHTML());
594 }
595
602 public function copyQuestion()
603 {
604 $ilCtrl = $this->ctrl;
605
606 $this->content_obj = new ilPCQuestion($this->getPage());
607 $this->content_obj->create($this->pg_obj, $_GET["hier_id"]);
608
609 $this->content_obj->copyPoolQuestionIntoPage(
610 (int) $_GET["q_id"],
611 $_GET["hier_id"]
612 );
613
614 $this->updated = $this->pg_obj->update();
615
616 $ilCtrl->returnToParent($this);
617 }
618}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
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 getCommandsFromClassConstants($guiClassName, $cmdConstantNameBegin='CMD_')
extracts values of all constants of given class with given prefix as array can be used to get all pos...
const ADDITIONAL_CONTENT_EDITING_MODE_RTE
constant for additional content editing mode "default"
const ADDITIONAL_CONTENT_EDITING_MODE_IPE
constant for additional content editing mode "pageobject"
static _getQuestionType($question_id)
Returns the question type of a question with a given id.
Table to select self assessment questions for copying into learning resources.
This class represents a hidden form property in a property form.
static isAdditionalQuestionContentEditingModePageObjectEnabled()
returns the fact wether content editing with ilias page editor is enabled for questions or not
static & _getSelfAssessmentQuestionTypes($all_tags=false)
Get all self assessment question types.
static _lookupObjId($a_id)
static _lookupType($a_id, $a_reference=false)
lookup object type
Class ilPCQuestionGUI.
setSelfAssessmentMode($a_selfassessmentmode)
Set Self Assessment Mode.
create()
Create new question.
listPoolQuestions()
List questions of pool.
copyQuestion()
Copy question into page.
setInsertTabs($a_active)
Set insert tabs.
executeCommand()
execute command
insertFromPool()
Insert question from ppol.
createQuestionPool($name="Dummy")
Creates a new questionpool and returns the reference id.
getSelfAssessmentMode()
Get Self Assessment Mode.
setNewQuestionId($a_par)
Set new question id.
selectPool()
Select concrete question pool.
poolSelection()
Pool selection.
insert($a_mode="create")
Insert new question form.
__construct(&$a_pg_obj, &$a_content_obj, $a_hier_id, $a_pc_id="")
Constructor @access public.
Class ilPCQuestion.
User Interface for Editing of Page Content Objects (Paragraphs, Tables, ...)
getPageConfig()
Get Page Config.
displayValidationError()
display validation errors
Select media pool for adding objects into pages.
This class represents a property form user interface.
Class ilQuestionEditGUI.
This class represents a property in a property form.
This class represents an option in a radio group.
This class represents a selection list property in a property form.
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$ret
Definition: parser.php:6