ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.SurveyQuestionGUI.php
Go to the documentation of this file.
1<?php
2 /*
3 +----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +----------------------------------------------------------------------------+
22*/
23
34abstract class SurveyQuestionGUI
35{
39 protected $rbacsystem;
40
44 protected $user;
45
49 protected $access;
50
54 protected $tree;
55
59 protected $toolbar;
60
64 protected $tabs;
65
66 protected $tpl;
67 protected $lng;
68 protected $ctrl;
69 protected $cumulated; // [array]
70 protected $parent_url;
71
75 protected $log;
76
77 public $object;
78
79 public function __construct($a_id = -1)
80 {
81 global $DIC;
82
83 $this->rbacsystem = $DIC->rbac()->system();
84 $this->user = $DIC->user();
85 $this->access = $DIC->access();
86 $this->tree = $DIC->repositoryTree();
87 $this->toolbar = $DIC->toolbar();
88 $lng = $DIC->language();
89 $tpl = $DIC["tpl"];
90 $ilCtrl = $DIC->ctrl();
91
92 $this->lng = $lng;
93 $this->tpl = $tpl;
94 $this->ctrl = $ilCtrl;
95 $this->ctrl->saveParameter($this, "q_id");
96 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
97 $this->cumulated = array();
98 $this->tabs = $DIC->tabs();
99
100 $this->initObject();
101
102 if ($a_id > 0) {
103 $this->object->loadFromDb($a_id);
104 }
105 $this->log = ilLoggerFactory::getLogger('svy');
106 }
107
108 abstract protected function initObject();
109 abstract public function setQuestionTabs();
110
111 public function &executeCommand()
112 {
113 $cmd = $this->ctrl->getCmd();
114 $next_class = $this->ctrl->getNextClass($this);
115 switch ($next_class) {
116 default:
117 $ret =&$this->$cmd();
118 break;
119 }
120 return $ret;
121 }
122
134 public static function _getQuestionGUI($questiontype, $question_id = -1)
135 {
136 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
137 if ((!$questiontype) and ($question_id > 0)) {
138 $questiontype = SurveyQuestion::_getQuestiontype($question_id);
139 }
140 SurveyQuestion::_includeClass($questiontype, 1);
141 $question_type_gui = $questiontype . "GUI";
142 $question = new $question_type_gui($question_id);
143 return $question;
144 }
145
146 public static function _getGUIClassNameForId($a_q_id)
147 {
148 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
149 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
150 $q_type = SurveyQuestion::_getQuestiontype($a_q_id);
151 $class_name = SurveyQuestionGUI::_getClassNameForQType($q_type);
152 return $class_name;
153 }
154
155 public static function _getClassNameForQType($q_type)
156 {
157 return $q_type;
158 }
159
166 public function getQuestionType()
167 {
168 return $this->object->getQuestionType();
169 }
170
171 protected function outQuestionText($template)
172 {
173 $questiontext = $this->object->getQuestiontext();
174 if (preg_match("/^<.[\\>]?>(.*?)<\\/.[\\>]*?>$/", $questiontext, $matches)) {
175 $questiontext = $matches[1];
176 }
177 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
178 if ($this->object->getObligatory($survey_id)) {
179 $template->setVariable("OBLIGATORY_TEXT", ' *');
180 }
181 }
182
183 public function setBackUrl($a_url)
184 {
185 $this->parent_url = $a_url;
186 }
187
188 public function setQuestionTabsForClass($guiclass)
189 {
191 $ilTabs = $this->tabs;
192
193 $this->ctrl->setParameterByClass($guiclass, "sel_question_types", $this->getQuestionType());
194 $this->ctrl->setParameterByClass($guiclass, "q_id", $_GET["q_id"]);
195
196 if ($this->parent_url) {
197 $addurl = "";
198 if (strlen($_GET["new_for_survey"])) {
199 $addurl = "&new_id=" . $_GET["q_id"];
200 }
201 $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $this->parent_url . $addurl);
202 } else {
203 $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
204 $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
205 }
206 if ($_GET["q_id"]) {
207 $ilTabs->addNonTabbedLink(
208 "preview",
209 $this->lng->txt("preview"),
210 $this->ctrl->getLinkTargetByClass($guiclass, "preview")
211 );
212 }
213
214 if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
215 $ilTabs->addTab(
216 "edit_properties",
217 $this->lng->txt("properties"),
218 $this->ctrl->getLinkTargetByClass($guiclass, "editQuestion")
219 );
220
221 if (stristr($guiclass, "matrix")) {
222 $ilTabs->addTab(
223 "layout",
224 $this->lng->txt("layout"),
225 $this->ctrl->getLinkTargetByClass($guiclass, "layout")
226 );
227 }
228 }
229 if ($_GET["q_id"]) {
230 $ilTabs->addTab(
231 "material",
232 $this->lng->txt("material"),
233 $this->ctrl->getLinkTargetByClass($guiclass, "material")
234 );
235 }
236
237 if ($this->object->getId() > 0) {
238 $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
239 } else {
240 $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
241 }
242
243 $this->tpl->setVariable("HEADER", $title);
244 }
245
246
247 //
248 // EDITOR
249 //
250
251 protected function initEditForm()
252 {
253 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
254 $form = new ilPropertyFormGUI();
255 $form->setFormAction($this->ctrl->getFormAction($this, "save"));
256 $form->setTitle($this->lng->txt($this->getQuestionType()));
257 $form->setMultipart(false);
258 $form->setTableWidth("100%");
259 // $form->setId("essay");
260
261 // title
262 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
263 $title->setRequired(true);
264 $form->addItem($title);
265
266 // label
267 $label = new ilTextInputGUI($this->lng->txt("label"), "label");
268 $label->setInfo($this->lng->txt("label_info"));
269 $label->setRequired(false);
270 $form->addItem($label);
271
272 // author
273 $author = new ilTextInputGUI($this->lng->txt("author"), "author");
274 $author->setRequired(true);
275 $form->addItem($author);
276
277 // description
278 $description = new ilTextInputGUI($this->lng->txt("description"), "description");
279 $description->setRequired(false);
280 $form->addItem($description);
281
282 // questiontext
283 $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
284 $question->setRequired(true);
285 $question->setRows(10);
286 $question->setCols(80);
287 $question->setUseRte(true);
288 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
289 $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
290 $question->addPlugin("latex");
291 $question->addButton("latex");
292 $question->addButton("pastelatex");
293 $question->setRTESupport($this->object->getId(), "spl", "survey");
294 $form->addItem($question);
295
296 // obligatory
297 $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
298 $shuffle->setValue(1);
299 $shuffle->setRequired(false);
300 $form->addItem($shuffle);
301
303
304 $this->addCommandButtons($form);
305
306 // values
307 $title->setValue($this->object->getTitle());
308 $label->setValue($this->object->label);
309 $author->setValue($this->object->getAuthor());
310 $description->setValue($this->object->getDescription());
311 $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
312 $shuffle->setChecked($this->object->getObligatory());
313
314 return $form;
315 }
316
317 protected function addCommandButtons($a_form)
318 {
319 $a_form->addCommandButton("saveReturn", $this->lng->txt("save_return"));
320 $a_form->addCommandButton("save", $this->lng->txt("save"));
321
322 // pool question?
323 if (ilObject::_lookupType($this->object->getObjId()) == "spl") {
324 if ($this->object->hasCopies()) {
325 $a_form->addCommandButton("saveSync", $this->lng->txt("svy_save_sync"));
326 }
327 }
328 }
329
330 protected function editQuestion(ilPropertyFormGUI $a_form = null)
331 {
332 $ilTabs = $this->tabs;
333
334 $ilTabs->activateTab("edit_properties");
335
336 if (!$a_form) {
337 $a_form = $this->initEditForm();
338 }
339 $this->tpl->setContent($a_form->getHTML());
340 }
341
342 protected function saveSync()
343 {
344 $this->save($_REQUEST["rtrn"], true);
345 }
346
347 protected function saveReturn()
348 {
349 $this->save(true);
350 }
351
352 protected function saveForm()
353 {
354 $form = $this->initEditForm();
355 if ($form->checkInput()) {
356 if ($this->validateEditForm($form)) {
357 $this->object->setTitle($form->getInput("title"));
358 $this->object->label = ($form->getInput("label"));
359 $this->object->setAuthor($form->getInput("author"));
360 $this->object->setDescription($form->getInput("description"));
361 $this->object->setQuestiontext($form->getInput("question"));
362 $this->object->setObligatory($form->getInput("obligatory"));
363
365
366 // will save both core and extended data
367 $this->object->saveToDb();
368
369 return true;
370 }
371 }
372
373 $form->setValuesByPost();
374 $this->editQuestion($form);
375 return false;
376 }
377
378 protected function save($a_return = false, $a_sync = false)
379 {
381
382 if ($this->saveForm()) {
383 // #13784
384 if ($a_return &&
385 !SurveyQuestion::_isComplete($this->object->getId())) {
386 ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
387 return $this->editQuestion();
388 }
389
390 $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType());
391 $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType());
392
393 $originalexists = SurveyQuestion::_questionExists($this->object->original_id);
394 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
395 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
396
397 // pool question?
398 if ($a_sync) {
399 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
400 $this->ctrl->redirect($this, 'copySyncForm');
401 } else {
402 // form: update original pool question, too?
403 if ($originalexists &&
404 SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId())) {
405 if ($a_return) {
406 $this->ctrl->setParameter($this, 'rtrn', 1);
407 }
408 $this->ctrl->redirect($this, 'originalSyncForm');
409 }
410 }
411
412 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
413 $this->redirectAfterSaving($a_return);
414 }
415 }
416
417 protected function copySyncForm()
418 {
419 $ilTabs = $this->tabs;
420
421 $ilTabs->activateTab("edit_properties");
422
423 include_once "Modules/SurveyQuestionPool/classes/class.ilSurveySyncTableGUI.php";
424 $tbl = new ilSurveySyncTableGUI($this, "copySyncForm", $this->object);
425
426 $this->tpl->setContent($tbl->getHTML());
427 }
428
429 protected function syncCopies()
430 {
432 $ilAccess = $this->access;
433
434 if (!sizeof($_POST["qid"])) {
435 ilUtil::sendFailure($lng->txt("select_one"));
436 return $this->copySyncForm();
437 }
438
439 foreach ($this->object->getCopyIds(true) as $survey_id => $questions) {
440 // check permissions for "parent" survey
441 $can_write = false;
442 $ref_ids = ilObject::_getAllReferences($survey_id);
443 foreach ($ref_ids as $ref_id) {
444 if ($ilAccess->checkAccess("edit", "", $ref_id)) {
445 $can_write = true;
446 break;
447 }
448 }
449
450 if ($can_write) {
451 foreach ($questions as $qid) {
452 if (in_array($qid, $_POST["qid"])) {
453 $id = $this->object->getId();
454
455 $this->object->setId($qid);
456 $this->object->setOriginalId($id);
457 $this->object->saveToDb();
458
459 $this->object->setId($id);
460 $this->object->setOriginalId(null);
461
462 // see: SurveyQuestion::syncWithOriginal()
463 // what about material?
464 }
465 }
466 }
467 }
468
469 ilUtil::sendSuccess($lng->txt("survey_sync_success"), true);
470 $this->redirectAfterSaving($_REQUEST["rtrn"]);
471 }
472
473 protected function originalSyncForm()
474 {
475 $ilTabs = $this->tabs;
476
477 $ilTabs->activateTab("edit_properties");
478
479 $this->ctrl->saveParameter($this, "rtrn");
480
481 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
482 $cgui = new ilConfirmationGUI();
483 $cgui->setHeaderText($this->lng->txt("confirm_sync_questions"));
484
485 $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
486 $cgui->setCancel($this->lng->txt("no"), "cancelSync");
487 $cgui->setConfirm($this->lng->txt("yes"), "sync");
488
489 $this->tpl->setContent($cgui->getHTML());
490 }
491
492 protected function sync()
493 {
494 $original_id = $this->object->original_id;
495 if ($original_id) {
496 $this->object->syncWithOriginal();
497 }
498
499 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
500 $this->redirectAfterSaving($_REQUEST["rtrn"]);
501 }
502
503 protected function cancelSync()
504 {
505 ilUtil::sendInfo($this->lng->txt("question_changed_in_survey_only"), true);
506 $this->redirectAfterSaving($_REQUEST["rtrn"]);
507 }
508
514 protected function redirectAfterSaving($a_return = false)
515 {
516 // return?
517 if ($a_return) {
518 // to calling survey
519 if ($this->parent_url) {
520 $addurl = "";
521 if (strlen($_GET["new_for_survey"])) {
522 $addurl = "&new_id=" . $_GET["q_id"];
523 }
524 ilUtil::redirect(str_replace("&amp;", "&", $this->parent_url) . $addurl);
525 }
526 // to pool
527 else {
528 $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
529 $this->ctrl->redirectByClass("ilObjSurveyQuestionPoolGUI", "questions");
530 }
531 }
532 // stay in form
533 else {
534 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
535 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
536 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
537 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
538 }
539 }
540
541 protected function cancel()
542 {
543 if ($this->parent_url) {
544 ilUtil::redirect($this->parent_url);
545 } else {
546 $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
547 }
548 }
549
550 protected function validateEditForm(ilPropertyFormGUI $a_form)
551 {
552 return true;
553 }
554
555 abstract protected function addFieldsToEditForm(ilPropertyFormGUI $a_form);
556 abstract protected function importEditFormValues(ilPropertyFormGUI $a_form);
557
558 abstract public function getPrintView($question_title = 1, $show_questiontext = 1);
559
560 protected function getPrintViewQuestionTitle($question_title = 1)
561 {
562 switch ($question_title) {
564 $title = ilUtil::prepareFormOutput($this->object->getTitle());
565 break;
566
567 #19448 get rid of showing only the label without title
568 //case 2:
569 // $title = ilUtil::prepareFormOutput($this->object->getLabel());
570 // break;
571
573 $title = ilUtil::prepareFormOutput($this->object->getTitle());
574 if (trim($this->object->getLabel())) {
575 $title .= ' <span class="questionLabel">(' . ilUtil::prepareFormOutput($this->object->getLabel()) . ')</span>';
576 }
577 break;
578 }
579 return $title;
580 }
581
587 public function preview()
588 {
589 $ilTabs = $this->tabs;
590
591 $ilTabs->activateTab("preview");
592
593 $tpl = new ilTemplate("tpl.il_svy_qpl_preview.html", true, true, "Modules/SurveyQuestionPool");
594
595 if ($this->object->getObligatory()) {
596 $tpl->setCurrentBlock("required");
597 $tpl->setVariable("TEXT_REQUIRED", $this->lng->txt("required_field"));
598 $tpl->parseCurrentBlock();
599 }
600
601 $tpl->setVariable("QUESTION_OUTPUT", $this->getWorkingForm());
602
603 include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
604 $panel = ilPanelGUI::getInstance();
605 $panel->setBody($tpl->get());
606
607 $this->tpl->setContent($panel->getHTML());
608 }
609
610
611 //
612 // EXECUTION
613 //
614
615 abstract public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null);
616
620 protected function getMaterialOutput()
621 {
622 if (count($this->object->getMaterial())) {
623 $template = new ilTemplate("tpl.il_svy_qpl_material.html", true, true, "Modules/SurveyQuestionPool");
624 foreach ($this->object->getMaterial() as $material) {
625 $template->setCurrentBlock('material');
626 switch ($material->type) {
627 case 0:
628 $href = SurveyQuestion::_getInternalLinkHref($material->internal_link, $_GET['ref_id']);
629 $template->setVariable('MATERIAL_TYPE', 'internallink');
630 $template->setVariable('MATERIAL_HREF', $href);
631 break;
632 }
633 $template->setVariable('MATERIAL_TITLE', (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material'));
634 $template->setVariable('TEXT_AVAILABLE_MATERIALS', $this->lng->txt('material'));
635 $template->parseCurrentBlock();
636 }
637 return $template->get();
638 }
639 return "";
640 }
641
642 //
643 // MATERIAL
644 //
645
649 public function material($checkonly = false)
650 {
652 $ilTabs = $this->tabs;
653
654 $ilTabs->activateTab("material");
655
656 $add_html = '';
657 if ($rbacsystem->checkAccess('write', $_GET['ref_id'])) {
658 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
659 $form = new ilPropertyFormGUI();
660 $form->setFormAction($this->ctrl->getFormAction($this));
661 $form->setTitle($this->lng->txt('add_material'));
662 $form->setMultipart(false);
663 $form->setTableWidth("100%");
664 $form->setId("material");
665
666 // material
667 $material = new ilRadioGroupInputGUI($this->lng->txt("material"), "internalLinkType");
668 $material->setRequired(true);
669 $material->addOption(new ilRadioOption($this->lng->txt('obj_lm'), "lm"));
670 $material->addOption(new ilRadioOption($this->lng->txt('obj_st'), "st"));
671 $material->addOption(new ilRadioOption($this->lng->txt('obj_pg'), "pg"));
672 $material->addOption(new ilRadioOption($this->lng->txt('glossary_term'), "glo"));
673 $form->addItem($material);
674
675 $form->addCommandButton("addMaterial", $this->lng->txt("add"));
676
677 $errors = false;
678
679 if ($checkonly) {
680 $form->setValuesByPost();
681 $errors = !$form->checkInput();
682 if ($errors) {
683 $checkonly = false;
684 }
685 }
686 $add_html = $form->getHTML();
687 }
688
689
690 $mat_html = "";
691 if (count($this->object->getMaterial())) {
692 include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyMaterialsTableGUI.php";
693 $table_gui = new ilSurveyMaterialsTableGUI($this, 'material', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
694 $data = array();
695 foreach ($this->object->getMaterial() as $material) {
696 switch ($material->type) {
697 case 0:
698 $href = SurveyQuestion::_getInternalLinkHref($material->internal_link, $_GET['ref_id']);
699 $type = $this->lng->txt('internal_link');
700 break;
701 }
702 $title = (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material');
703 array_push($data, array('href' => $href, 'title' => $title, 'type' => $type));
704 }
705 $table_gui->setData($data);
706 $mat_html = $table_gui->getHTML();
707 }
708
709 if (!$checkonly) {
710 $this->tpl->setVariable("ADM_CONTENT", $add_html . $mat_html);
711 }
712 return $errors;
713 }
714
715 public function deleteMaterial()
716 {
717 if (is_array($_POST['idx'])) {
718 $this->object->deleteMaterials($_POST['idx']);
719 ilUtil::sendSuccess($this->lng->txt('materials_deleted'), true);
720 } else {
721 ilUtil::sendFailure($this->lng->txt('no_checkbox'), true);
722 }
723 $this->ctrl->redirect($this, 'material');
724 }
725
729 public function addMaterial()
730 {
732 $ilTabs = $this->tabs;
733 $ilToolbar = $this->toolbar;
734
735 $ilTabs->activateTab("material");
736
737 $ilToolbar->addButton(
738 $this->lng->txt("cancel"),
739 $this->ctrl->getLinkTarget($this, "material")
740 );
741
742 if (strlen($_SESSION["link_new_type"]) || !$this->material(true)) {
743 include_once("./Modules/SurveyQuestionPool/classes/class.ilMaterialExplorer.php");
744 switch ($_POST["internalLinkType"]) {
745 case "lm":
746 $_SESSION["link_new_type"] = "lm";
747 $_SESSION["search_link_type"] = "lm";
748 break;
749 case "glo":
750 $_SESSION["link_new_type"] = "glo";
751 $_SESSION["search_link_type"] = "glo";
752 break;
753 case "st":
754 $_SESSION["link_new_type"] = "lm";
755 $_SESSION["search_link_type"] = "st";
756 break;
757 case "pg":
758 $_SESSION["link_new_type"] = "lm";
759 $_SESSION["search_link_type"] = "pg";
760 break;
761 }
762
763 $exp = new ilMaterialExplorer($this, 'addMaterial', $_SESSION["link_new_type"]);
764 $exp->setPathOpen((int) $_GET["ref_id"]);
765 if (!$exp->handleCommand()) {
766 include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
767 $panel = ilPanelGUI::getInstance();
768 $panel->setHeading($this->lng->txt("select_object_to_link"));
769 $panel->setBody($exp->getHTML());
770
771 $this->tpl->setContent($panel->getHTML());
772 }
773 }
774 }
775
776 public function removeMaterial()
777 {
778 $this->object->material = array();
779 $this->object->saveToDb();
780 $this->editQuestion();
781 }
782
783 public function cancelExplorer()
784 {
785 unset($_SESSION["link_new_type"]);
786 ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
787 $this->ctrl->redirect($this, 'material');
788 }
789
790 public function addPG()
791 {
792 $this->object->addInternalLink("il__pg_" . $_GET["pg"]);
793 unset($_SESSION["link_new_type"]);
794 unset($_SESSION["search_link_type"]);
795 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
796 $this->ctrl->redirect($this, "material");
797 }
798
799 public function addST()
800 {
801 $this->object->addInternalLink("il__st_" . $_GET["st"]);
802 unset($_SESSION["link_new_type"]);
803 unset($_SESSION["search_link_type"]);
804 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
805 $this->ctrl->redirect($this, "material");
806 }
807
808 public function addGIT()
809 {
810 $this->object->addInternalLink("il__git_" . $_GET["git"]);
811 unset($_SESSION["link_new_type"]);
812 unset($_SESSION["search_link_type"]);
813 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
814 $this->ctrl->redirect($this, "material");
815 }
816
817 public function linkChilds()
818 {
819 $ilTabs = $this->tabs;
820
821 $selectable_items = array();
822
823 $source_id = $_GET["source_id"];
824
825 switch ($_SESSION["search_link_type"]) {
826 case "pg":
827 include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
828 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
829 $cont_obj_gui = new ilObjContentObjectGUI("", $source_id, true);
830 $cont_obj = $cont_obj_gui->object;
831 $pages = ilLMPageObject::getPageList($cont_obj->getId());
832 foreach ($pages as $page) {
833 if ($page["type"] == $_SESSION["search_link_type"]) {
834 $selectable_items[] = array(
835 "item_type" => $page["type"]
836 ,"item_id" => $page["obj_id"]
837 ,"title" => $page["title"]
838 );
839 }
840 }
841 break;
842
843 case "st":
844 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
845 $cont_obj_gui = new ilObjContentObjectGUI("", $source_id, true);
846 $cont_obj = $cont_obj_gui->object;
847 // get all chapters
848 $ctree =&$cont_obj->getLMTree();
849 $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
850 foreach ($nodes as $node) {
851 if ($node["type"] == $_SESSION["search_link_type"]) {
852 $selectable_items[] = array(
853 "item_type" => $node["type"]
854 ,"item_id" => $node["obj_id"]
855 ,"title" => $node["title"]
856 );
857 }
858 }
859 break;
860
861 case "glo":
862 include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
863 $glossary = new ilObjGlossary($source_id, true);
864 // get all glossary items
865 $terms = $glossary->getTermList();
866 foreach ($terms as $term) {
867 $selectable_items[] = array(
868 "item_type" => "GIT"
869 ,"item_id" => $term["id"]
870 ,"title" => $term["term"]
871 );
872 }
873 break;
874
875 case "lm":
876 $this->object->addInternalLink("il__lm_" . $source_id);
877 break;
878 }
879
880 if (sizeof($selectable_items)) {
881 $ilTabs->activateTab("material");
882 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
883 $this->ctrl->setParameter($this, "source_id", $source_id);
884
885 include_once "Modules/SurveyQuestionPool/classes/tables/class.SurveyMaterialsSourceTableGUI.php";
886 $tbl = new SurveyMaterialsSourceTableGUI($this, "linkChilds", "addMaterial");
887 $tbl->setData($selectable_items);
888 $this->tpl->setContent($tbl->getHTML());
889 } else {
890 if ($_SESSION["search_link_type"] == "lm") {
891 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
892
893 unset($_SESSION["link_new_type"]);
894 unset($_SESSION["search_link_type"]);
895 $this->ctrl->redirect($this, "material");
896 } else {
897 ilUtil::sendFailure($this->lng->txt("material_added_empty"), true);
898 $this->ctrl->redirect($this, "addMaterial");
899 }
900 }
901 }
902
903
904 //
905 // PHRASES (see SurveyMatrixQuestionGUI)
906 //
907
908 protected function initPhrasesForm()
909 {
910 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
911 $form = new ilPropertyFormGUI();
912 $form->setFormAction($this->ctrl->getFormAction($this, "addSelectedPhrase"));
913 $form->setTitle($this->lng->txt("add_phrase"));
914 // $form->setDescription($this->lng->txt("add_phrase_introduction"));
915
916 $group = new ilRadioGroupInputGUI($this->lng->txt("phrase"), "phrases");
917 $group->setRequired(true);
918 $form->addItem($group);
919
920 include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
921 foreach (ilSurveyPhrases::_getAvailablePhrases() as $phrase_id => $phrase_array) {
922 $categories = ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
923
924 $opt = new ilRadioOption($phrase_array["title"], $phrase_id);
925 $opt->setInfo(join($categories, ","));
926 $group->addOption($opt);
927
928 if ($phrase_array["org_title"] == "dp_standard_numbers") {
929 $min = new ilNumberInputGUI($this->lng->txt("lower_limit"), "lower_limit");
930 $min->setRequired(true);
931 $min->setSize(5);
932 $opt->addSubItem($min);
933
934 $max = new ilNumberInputGUI($this->lng->txt("upper_limit"), "upper_limit");
935 $max->setRequired(true);
936 $max->setSize(5);
937 $opt->addSubItem($max);
938 }
939 }
940
941 $form->addCommandButton("addSelectedPhrase", $this->lng->txt("add_phrase"));
942 $form->addCommandButton("editQuestion", $this->lng->txt("cancel"));
943
944 return $form;
945 }
946
950 protected function addPhrase(ilPropertyFormGUI $a_form = null)
951 {
952 $ilTabs = $this->tabs;
953
954 $ilTabs->activateTab("edit_properties");
955
956 if (!$a_form) {
957 $result = $this->saveForm();
958 if ($result) {
959 $this->object->saveToDb();
960 }
961
962 $a_form = $this->initPhrasesForm();
963 }
964
965 $this->tpl->setContent($a_form->getHTML());
966 }
967
968 protected function addSelectedPhrase()
969 {
970 $form = $this->initPhrasesForm();
971 if ($form->checkInput()) {
972 $phrase_id = $form->getInput("phrases");
973
974 $valid = true;
975 if (strcmp($this->object->getPhrase($phrase_id), "dp_standard_numbers") != 0) {
976 $this->object->addPhrase($phrase_id);
977 } else {
978 $min = $form->getInput("lower_limit");
979 $max = $form->getInput("upper_limit");
980
981 if ($max <= $min) {
982 $max_field = $form->getItemByPostVar("upper_limit");
983 $max_field->setAlert($this->lng->txt("upper_limit_must_be_greater"));
984 $valid = false;
985 } else {
986 $this->object->addStandardNumbers($min, $max);
987 }
988 }
989
990 if ($valid) {
991 $this->object->saveToDb();
992
993 ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
994 $this->ctrl->redirect($this, 'editQuestion');
995 }
996 }
997
998 $form->setValuesByPost();
999 $this->addPhrase($form);
1000 }
1001
1007 public function savePhrase($a_reload = false)
1008 {
1009 $ilTabs = $this->tabs;
1010 $ilToolbar = $this->toolbar;
1011
1012 $ilTabs->activateTab("edit_properties");
1013
1014 if (!$a_reload) {
1015 $result = $this->saveForm();
1016 if ($result) {
1017 $this->object->saveToDb();
1018 }
1019 }
1020
1021 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
1022 $txt = new ilTextInputGUI($this->lng->txt("enter_phrase_title"), "phrase_title");
1023 $ilToolbar->addInputItem($txt, true);
1024 $ilToolbar->addFormButton($this->lng->txt("confirm"), "confirmSavePhrase");
1025 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
1026
1027 include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveySavePhraseTableGUI.php";
1028 $table_gui = new ilSurveySavePhraseTableGUI($this, 'editQuestion');
1029 $table_gui->setDescription($this->lng->txt("save_phrase_introduction"));
1030
1031 // matrix?
1032 if (method_exists($this->object, "getCategories")) {
1033 $categories = $this->object->getCategories();
1034 } else {
1035 $categories = $this->object->getColumns();
1036 }
1037
1038 $data = array();
1039 for ($i = 0; $i < $categories->getCategoryCount(); $i++) {
1040 $cat = $categories->getCategory($i);
1041
1042 $data[] = array(
1043 "answer" => $cat->title,
1044 "other" => $cat->other,
1045 "scale" => $cat->scale,
1046 "neutral" => $cat->neutral
1047 );
1048 }
1049 $table_gui->setData($data);
1050 $_SESSION['save_phrase_data'] = $data; // :TODO: see savePhrase()
1051
1052 $this->tpl->setContent($table_gui->getHTML());
1053 }
1054
1060 public function confirmSavePhrase()
1061 {
1062 $title = $_POST["phrase_title"];
1063
1064 $valid = true;
1065 if (!trim($title)) {
1066 ilUtil::sendFailure($this->lng->txt("qpl_savephrase_empty"));
1067 $valid = false;
1068 } elseif ($this->object->phraseExists($title)) {
1069 ilUtil::sendFailure($this->lng->txt("qpl_savephrase_exists"));
1070 $valid = false;
1071 }
1072
1073 if ($valid) {
1074 $this->object->savePhrase($title);
1075
1076 ilUtil::sendSuccess($this->lng->txt("phrase_saved"), true);
1077 $this->ctrl->redirect($this, "editQuestion");
1078 }
1079
1080 $this->savePhrase(true);
1081 }
1082
1083 protected function renderStatisticsDetailsTable(array $a_head, array $a_rows, array $a_foot = null)
1084 {
1085 $html = array();
1086 $html[] = '<div class="ilTableOuter table-responsive">';
1087 $html[] = '<table class="table table-striped">';
1088
1089 $html[] = "<thead>";
1090 $html[] = "<tr>";
1091 foreach ($a_head as $col) {
1092 $col = trim($col);
1093 $html[] = "<th>";
1094 $html[] = ($col != "") ? $col : "&nbsp;";
1095 $html[] = "</th>";
1096 }
1097 $html[] = "</tr>";
1098 $html[] = "</thead>";
1099
1100 $html[] = "<tbody>";
1101 foreach ($a_rows as $row) {
1102 $html[] = "<tr>";
1103 foreach ($row as $col) {
1104 $col = trim($col);
1105 $html[] = "<td>";
1106 $html[] = ($col != "") ? $col : "&nbsp;";
1107 $html[] = "</td>";
1108 }
1109 $html[] = "</tr>";
1110 }
1111 $html[] = "</tbody>";
1112
1113 if ($a_foot) {
1114 $html[] = "<tfoot>";
1115 $html[] = "<tr>";
1116 foreach ($a_foot as $col) {
1117 $col = trim($col);
1118 $html[] = "<td>";
1119 $html[] = ($col != "") ? $col : "&nbsp;";
1120 $html[] = "</td>";
1121 }
1122 $html[] = "</tr>";
1123 $html[] = "</tfoot>";
1124 }
1125
1126 $html[] = "</table>";
1127 $html[] = "</div>";
1128 return implode("\n", $html);
1129 }
1130}
$result
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
TableGUI class for survey question source materials.
Basic class for all survey question types.
getPrintViewQuestionTitle($question_title=1)
addPhrase(ilPropertyFormGUI $a_form=null)
Creates an output for the addition of phrases.
savePhrase($a_reload=false)
Creates an output to save the current answers as a phrase.
addFieldsToEditForm(ilPropertyFormGUI $a_form)
confirmSavePhrase()
Save a new phrase to the database.
static _getQuestionGUI($questiontype, $question_id=-1)
Creates a question gui representation.
getMaterialOutput()
Creates the HTML output of the question material(s)
addMaterial()
Add materials to a question.
static _getGUIClassNameForId($a_q_id)
getPrintView($question_title=1, $show_questiontext=1)
getQuestionType()
Returns the question type string.
renderStatisticsDetailsTable(array $a_head, array $a_rows, array $a_foot=null)
validateEditForm(ilPropertyFormGUI $a_form)
editQuestion(ilPropertyFormGUI $a_form=null)
getWorkingForm($working_data="", $question_title=1, $show_questiontext=1, $error_message="", $survey_id=null)
redirectAfterSaving($a_return=false)
Redirect to calling survey or to edit form.
preview()
Creates a preview of the question.
save($a_return=false, $a_sync=false)
material($checkonly=false)
Material tab of the survey questions.
static _getClassNameForQType($q_type)
importEditFormValues(ilPropertyFormGUI $a_form)
static _questionExists($question_id)
Returns true if the question already exists in the database.
static _getInternalLinkHref($target="", $a_parent_ref_id=null)
static _isWriteable($question_id, $user_id)
Returns true if the question is writeable by a certain user.
static _isComplete($question_id)
Checks whether the question is complete or not.
static _includeClass($question_type, $gui=0)
Include the php class file for a given question type.
This class represents a checkbox property in a property form.
Confirmation screen class.
static getPageList($lm_id)
static
static getLogger($a_component_id)
Get component logger.
This class represents a number property in a property form.
static _getUsedHTMLTags($a_module="")
Returns an array of all allowed HTML tags for text editing.
Class ilObjContentObjectGUI.
Class ilObjGlossary.
static _getAllReferences($a_id)
get all reference ids of object
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstance()
Get instance.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
TableGUI class for survey question materials.
static _getAvailablePhrases($useronly=0)
Gets the available phrases from the database.
static _getCategoriesForPhrase($phrase_id)
Gets the available categories for a given phrase.
Survey sync table GUI class.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static redirect($a_script)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$template
$i
Definition: disco.tpl.php:19
$valid
$txt
Definition: error.php:11
$html
Definition: example_001.php:87
$tbl
Definition: example_048.php:81
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
$errors
Definition: index.php:6
$ret
Definition: parser.php:6
$type
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18