ILIAS  release_7 Revision v7.30-3-g800a261c036
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 if ((!$questiontype) and ($question_id > 0)) {
137 $questiontype = SurveyQuestion::_getQuestiontype($question_id);
138 }
139 SurveyQuestion::_includeClass($questiontype, 1);
140 $question_type_gui = $questiontype . "GUI";
141 $question = new $question_type_gui($question_id);
142 return $question;
143 }
144
145 public static function _getGUIClassNameForId($a_q_id)
146 {
147 $q_type = SurveyQuestion::_getQuestiontype($a_q_id);
148 $class_name = SurveyQuestionGUI::_getClassNameForQType($q_type);
149 return $class_name;
150 }
151
152 public static function _getClassNameForQType($q_type)
153 {
154 return $q_type;
155 }
156
163 public function getQuestionType()
164 {
165 return $this->object->getQuestionType();
166 }
167
168 protected function outQuestionText($template)
169 {
170 $questiontext = $this->object->getQuestiontext();
171 if (preg_match("/^<.[\\>]?>(.*?)<\\/.[\\>]*?>$/", $questiontext, $matches)) {
172 $questiontext = $matches[1];
173 }
174 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, true));
175 if ($this->object->getObligatory($survey_id)) {
176 $template->setVariable("OBLIGATORY_TEXT", ' *');
177 }
178 }
179
180 public function setBackUrl($a_url)
181 {
182 $this->parent_url = $a_url;
183 }
184
185 public function setQuestionTabsForClass($guiclass)
186 {
188 $ilTabs = $this->tabs;
189
190 $this->ctrl->setParameterByClass($guiclass, "sel_question_types", $this->getQuestionType());
191 $this->ctrl->setParameterByClass($guiclass, "q_id", $_GET["q_id"]);
192
193 if ($this->parent_url) {
194 $addurl = "";
195 if (strlen($_GET["new_for_survey"])) {
196 $addurl = "&new_id=" . $_GET["q_id"];
197 }
198 $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $this->parent_url . $addurl);
199 } else {
200 $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
201 $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
202 }
203 if ($_GET["q_id"]) {
204 $ilTabs->addNonTabbedLink(
205 "preview",
206 $this->lng->txt("preview"),
207 $this->ctrl->getLinkTargetByClass($guiclass, "preview")
208 );
209 }
210
211 if ($rbacsystem->checkAccess('edit', $_GET["ref_id"])) {
212 $ilTabs->addTab(
213 "edit_properties",
214 $this->lng->txt("properties"),
215 $this->ctrl->getLinkTargetByClass($guiclass, "editQuestion")
216 );
217
218 if (stristr($guiclass, "matrix")) {
219 $ilTabs->addTab(
220 "layout",
221 $this->lng->txt("layout"),
222 $this->ctrl->getLinkTargetByClass($guiclass, "layout")
223 );
224 }
225 }
226 if ($_GET["q_id"]) {
227 $ilTabs->addTab(
228 "material",
229 $this->lng->txt("material"),
230 $this->ctrl->getLinkTargetByClass($guiclass, "material")
231 );
232 }
233
234 if ($this->object->getId() > 0) {
235 $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
236 } else {
237 $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
238 }
239
240 $this->tpl->setVariable("HEADER", $title);
241 }
242
243
244 //
245 // EDITOR
246 //
247
248 protected function initEditForm()
249 {
250 $form = new ilPropertyFormGUI();
251 $form->setFormAction($this->ctrl->getFormAction($this, "save"));
252 $form->setTitle($this->lng->txt($this->getQuestionType()));
253 $form->setMultipart(false);
254 $form->setTableWidth("100%");
255 // $form->setId("essay");
256
257 // title
258 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
259 $title->setRequired(true);
260 $form->addItem($title);
261
262 // label
263 $label = new ilTextInputGUI($this->lng->txt("label"), "label");
264 $label->setInfo($this->lng->txt("label_info"));
265 $label->setRequired(false);
266 $form->addItem($label);
267
268 // author
269 $author = new ilTextInputGUI($this->lng->txt("author"), "author");
270 $author->setRequired(true);
271 $form->addItem($author);
272
273 // description
274 $description = new ilTextInputGUI($this->lng->txt("description"), "description");
275 $description->setRequired(false);
276 $form->addItem($description);
277
278 // questiontext
279 $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
280 $question->setRequired(true);
281 $question->setRows(10);
282 $question->setCols(80);
283 if (ilObjAdvancedEditing::_getRichTextEditor() === "tinymce") {
284 $question->setUseRte(true);
285 $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
286 $question->addPlugin("latex");
287 $question->addButton("latex");
288 $question->addButton("pastelatex");
289 $question->setRTESupport($this->object->getId(), "spl", "survey");
290 }
291 $form->addItem($question);
292
293 // obligatory
294 $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
295 $shuffle->setValue(1);
296 $shuffle->setRequired(false);
297 $form->addItem($shuffle);
298
299 $this->addFieldsToEditForm($form);
300
301 $this->addCommandButtons($form);
302
303 // values
304 $title->setValue($this->object->getTitle());
305 $label->setValue($this->object->label);
306 $author->setValue($this->object->getAuthor());
307 $description->setValue($this->object->getDescription());
308 $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
309 $shuffle->setChecked($this->object->getObligatory());
310
311 return $form;
312 }
313
314 protected function addCommandButtons($a_form)
315 {
316 $a_form->addCommandButton("saveReturn", $this->lng->txt("save_return"));
317 $a_form->addCommandButton("save", $this->lng->txt("save"));
318
319 // pool question?
320 if (ilObject::_lookupType($this->object->getObjId()) == "spl") {
321 if ($this->object->hasCopies()) {
322 $a_form->addCommandButton("saveSync", $this->lng->txt("svy_save_sync"));
323 }
324 }
325 }
326
327 protected function editQuestion(ilPropertyFormGUI $a_form = null)
328 {
329 $ilTabs = $this->tabs;
330
331 $ilTabs->activateTab("edit_properties");
332
333 if (!$a_form) {
334 $a_form = $this->initEditForm();
335 }
336 $this->tpl->setContent($a_form->getHTML());
337 }
338
339 protected function saveSync()
340 {
341 $this->save($_REQUEST["rtrn"], true);
342 }
343
344 protected function saveReturn()
345 {
346 $this->save(true);
347 }
348
349 protected function saveForm()
350 {
351 $form = $this->initEditForm();
352 if ($form->checkInput()) {
353 if ($this->validateEditForm($form)) {
354 $this->object->setTitle($form->getInput("title"));
355 $this->object->label = ($form->getInput("label"));
356 $this->object->setAuthor($form->getInput("author"));
357 $this->object->setDescription($form->getInput("description"));
358 $this->object->setQuestiontext($form->getInput("question"));
359 $this->object->setObligatory($form->getInput("obligatory"));
360
361 $this->importEditFormValues($form);
362
363 // will save both core and extended data
364 $this->object->saveToDb();
365
366 return true;
367 }
368 }
369
370 $form->setValuesByPost();
371 $this->editQuestion($form);
372 return false;
373 }
374
375 protected function save($a_return = false, $a_sync = false)
376 {
378
379 if ($this->saveForm()) {
380 // #13784
381 if ($a_return &&
382 !SurveyQuestion::_isComplete($this->object->getId())) {
383 ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
384 return $this->editQuestion();
385 }
386
387 $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType());
388 $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType());
389
390 $originalexists = SurveyQuestion::_questionExists($this->object->original_id);
391 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
392
393 // pool question?
394 if ($a_sync) {
395 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
396 $this->ctrl->redirect($this, 'copySyncForm');
397 } else {
398 // form: update original pool question, too?
399 if ($originalexists &&
400 SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId())) {
401 if ($a_return) {
402 $this->ctrl->setParameter($this, 'rtrn', 1);
403 }
404 $this->ctrl->redirect($this, 'originalSyncForm');
405 }
406 }
407
408 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
409 $this->redirectAfterSaving($a_return);
410 }
411 }
412
413 protected function copySyncForm()
414 {
415 $ilTabs = $this->tabs;
416
417 $ilTabs->activateTab("edit_properties");
418
419 $tbl = new ilSurveySyncTableGUI($this, "copySyncForm", $this->object);
420
421 $this->tpl->setContent($tbl->getHTML());
422 }
423
424 protected function syncCopies()
425 {
427 $ilAccess = $this->access;
428
429 if (!sizeof($_POST["qid"])) {
430 ilUtil::sendFailure($lng->txt("select_one"));
431 return $this->copySyncForm();
432 }
433
434 foreach ($this->object->getCopyIds(true) as $survey_id => $questions) {
435 // check permissions for "parent" survey
436 $can_write = false;
437 $ref_ids = ilObject::_getAllReferences($survey_id);
438 foreach ($ref_ids as $ref_id) {
439 if ($ilAccess->checkAccess("edit", "", $ref_id)) {
440 $can_write = true;
441 break;
442 }
443 }
444
445 if ($can_write) {
446 foreach ($questions as $qid) {
447 if (in_array($qid, $_POST["qid"])) {
448 $id = $this->object->getId();
449
450 $this->object->setId($qid);
451 $this->object->setOriginalId($id);
452 $this->object->saveToDb();
453
454 $this->object->setId($id);
455 $this->object->setOriginalId(null);
456
457 // see: SurveyQuestion::syncWithOriginal()
458 // what about material?
459 }
460 }
461 }
462 }
463
464 ilUtil::sendSuccess($lng->txt("survey_sync_success"), true);
465 $this->redirectAfterSaving($_REQUEST["rtrn"]);
466 }
467
468 protected function originalSyncForm()
469 {
470 $ilTabs = $this->tabs;
471
472 $ilTabs->activateTab("edit_properties");
473
474 $this->ctrl->saveParameter($this, "rtrn");
475
476 $cgui = new ilConfirmationGUI();
477 $cgui->setHeaderText($this->lng->txt("confirm_sync_questions"));
478
479 $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
480 $cgui->setCancel($this->lng->txt("no"), "cancelSync");
481 $cgui->setConfirm($this->lng->txt("yes"), "sync");
482
483 $this->tpl->setContent($cgui->getHTML());
484 }
485
486 protected function sync()
487 {
488 $original_id = $this->object->original_id;
489 if ($original_id) {
490 $this->object->syncWithOriginal();
491 }
492
493 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
494 $this->redirectAfterSaving($_REQUEST["rtrn"]);
495 }
496
497 protected function cancelSync()
498 {
499 ilUtil::sendInfo($this->lng->txt("question_changed_in_survey_only"), true);
500 $this->redirectAfterSaving($_REQUEST["rtrn"]);
501 }
502
508 protected function redirectAfterSaving($a_return = false)
509 {
510 // return?
511 if ($a_return) {
512 // to calling survey
513 if ($this->parent_url) {
514 $addurl = "";
515 if (strlen($_GET["new_for_survey"])) {
516 $addurl = "&new_id=" . $_GET["q_id"];
517 }
518 ilUtil::redirect(str_replace("&amp;", "&", $this->parent_url) . $addurl);
519 }
520 // to pool
521 else {
522 $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
523 $this->ctrl->redirectByClass("ilObjSurveyQuestionPoolGUI", "questions");
524 }
525 }
526 // stay in form
527 else {
528 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
529 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
530 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
531 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
532 }
533 }
534
535 protected function cancel()
536 {
537 if ($this->parent_url) {
538 ilUtil::redirect($this->parent_url);
539 } else {
540 $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
541 }
542 }
543
544 protected function validateEditForm(ilPropertyFormGUI $a_form)
545 {
546 return true;
547 }
548
549 abstract protected function addFieldsToEditForm(ilPropertyFormGUI $a_form);
550 abstract protected function importEditFormValues(ilPropertyFormGUI $a_form);
551
552 abstract public function getPrintView($question_title = 1, $show_questiontext = 1);
553
554 protected function getPrintViewQuestionTitle($question_title = 1)
555 {
556 switch ($question_title) {
558 $title = ilUtil::prepareFormOutput($this->object->getTitle());
559 break;
560
561 #19448 get rid of showing only the label without title
562 //case 2:
563 // $title = ilUtil::prepareFormOutput($this->object->getLabel());
564 // break;
565
567 $title = ilUtil::prepareFormOutput($this->object->getTitle());
568 if (trim($this->object->getLabel())) {
569 $title .= ' <span class="questionLabel">(' . ilUtil::prepareFormOutput($this->object->getLabel()) . ')</span>';
570 }
571 break;
572 }
573 return $title;
574 }
575
581 public function preview()
582 {
583 $ilTabs = $this->tabs;
584
585 $ilTabs->activateTab("preview");
586
587 $tpl = new ilTemplate("tpl.il_svy_qpl_preview.html", true, true, "Modules/SurveyQuestionPool");
588
589 if ($this->object->getObligatory()) {
590 $tpl->setCurrentBlock("required");
591 $tpl->setVariable("TEXT_REQUIRED", $this->lng->txt("required_field"));
592 $tpl->parseCurrentBlock();
593 }
594
595 $tpl->setVariable("QUESTION_OUTPUT", $this->getWorkingForm());
596
598 $panel->setBody($tpl->get());
599
600 $this->tpl->setContent($panel->getHTML());
601 }
602
603
604 //
605 // EXECUTION
606 //
607
608 abstract public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null, $compress_view = false);
609
613 protected function getMaterialOutput()
614 {
615 if (count($this->object->getMaterial())) {
616 $template = new ilTemplate("tpl.il_svy_qpl_material.html", true, true, "Modules/SurveyQuestionPool");
617 foreach ($this->object->getMaterial() as $material) {
618 $template->setCurrentBlock('material');
619 switch ($material->type) {
620 case 0:
621 $href = SurveyQuestion::_getInternalLinkHref($material->internal_link, $_GET['ref_id']);
622 $template->setVariable('MATERIAL_TYPE', 'internallink');
623 $template->setVariable('MATERIAL_HREF', $href);
624 break;
625 }
626 $template->setVariable('MATERIAL_TITLE', (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material'));
627 $template->setVariable('TEXT_AVAILABLE_MATERIALS', $this->lng->txt('material'));
628 $template->parseCurrentBlock();
629 }
630 return $template->get();
631 }
632 return "";
633 }
634
635 //
636 // MATERIAL
637 //
638
642 public function material($checkonly = false)
643 {
645 $ilTabs = $this->tabs;
646
647 $ilTabs->activateTab("material");
648
649 $add_html = '';
650 if ($rbacsystem->checkAccess('write', $_GET['ref_id'])) {
651 $form = new ilPropertyFormGUI();
652 $form->setFormAction($this->ctrl->getFormAction($this));
653 $form->setTitle($this->lng->txt('add_material'));
654 $form->setMultipart(false);
655 $form->setTableWidth("100%");
656 $form->setId("material");
657
658 // material
659 $material = new ilRadioGroupInputGUI($this->lng->txt("material"), "internalLinkType");
660 $material->setRequired(true);
661 $material->addOption(new ilRadioOption($this->lng->txt('obj_lm'), "lm"));
662 $material->addOption(new ilRadioOption($this->lng->txt('obj_st'), "st"));
663 $material->addOption(new ilRadioOption($this->lng->txt('obj_pg'), "pg"));
664 $material->addOption(new ilRadioOption($this->lng->txt('glossary_term'), "glo"));
665 $form->addItem($material);
666
667 $form->addCommandButton("addMaterial", $this->lng->txt("add"));
668
669 $errors = false;
670
671 if ($checkonly) {
672 $form->setValuesByPost();
673 $errors = !$form->checkInput();
674 if ($errors) {
675 $checkonly = false;
676 }
677 }
678 $add_html = $form->getHTML();
679 }
680
681
682 $mat_html = "";
683 if (count($this->object->getMaterial())) {
684 $table_gui = new ilSurveyMaterialsTableGUI($this, 'material', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
685 $data = array();
686 foreach ($this->object->getMaterial() as $material) {
687 switch ($material->type) {
688 case 0:
689 $href = SurveyQuestion::_getInternalLinkHref($material->internal_link, $_GET['ref_id']);
690 $type = $this->lng->txt('internal_link');
691 break;
692 }
693 $title = (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material');
694 array_push($data, array('href' => $href, 'title' => $title, 'type' => $type));
695 }
696 $table_gui->setData($data);
697 $mat_html = $table_gui->getHTML();
698 }
699
700 if (!$checkonly) {
701 $this->tpl->setVariable("ADM_CONTENT", $add_html . $mat_html);
702 }
703 return $errors;
704 }
705
706 public function deleteMaterial()
707 {
708 if (is_array($_POST['idx'])) {
709 $this->object->deleteMaterials($_POST['idx']);
710 ilUtil::sendSuccess($this->lng->txt('materials_deleted'), true);
711 } else {
712 ilUtil::sendFailure($this->lng->txt('no_checkbox'), true);
713 }
714 $this->ctrl->redirect($this, 'material');
715 }
716
720 public function addMaterial()
721 {
723 $ilTabs = $this->tabs;
724 $ilToolbar = $this->toolbar;
725
726 $ilTabs->activateTab("material");
727
728 $ilToolbar->addButton(
729 $this->lng->txt("cancel"),
730 $this->ctrl->getLinkTarget($this, "material")
731 );
732
733 if (strlen($_SESSION["link_new_type"]) || !$this->material(true)) {
734 switch ($_POST["internalLinkType"]) {
735 case "lm":
736 $_SESSION["link_new_type"] = "lm";
737 $_SESSION["search_link_type"] = "lm";
738 break;
739 case "glo":
740 $_SESSION["link_new_type"] = "glo";
741 $_SESSION["search_link_type"] = "glo";
742 break;
743 case "st":
744 $_SESSION["link_new_type"] = "lm";
745 $_SESSION["search_link_type"] = "st";
746 break;
747 case "pg":
748 $_SESSION["link_new_type"] = "lm";
749 $_SESSION["search_link_type"] = "pg";
750 break;
751 }
752
753 $exp = new ilMaterialExplorer($this, 'addMaterial', $_SESSION["link_new_type"]);
754 $exp->setPathOpen((int) $_GET["ref_id"]);
755 if (!$exp->handleCommand()) {
757 $panel->setHeading($this->lng->txt("select_object_to_link"));
758 $panel->setBody($exp->getHTML());
759
760 $this->tpl->setContent($panel->getHTML());
761 }
762 }
763 }
764
765 public function removeMaterial()
766 {
767 $this->object->material = array();
768 $this->object->saveToDb();
769 $this->editQuestion();
770 }
771
772 public function cancelExplorer()
773 {
774 unset($_SESSION["link_new_type"]);
775 ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
776 $this->ctrl->redirect($this, 'material');
777 }
778
779 public function addPG()
780 {
781 $this->object->addInternalLink("il__pg_" . $_GET["pg"]);
782 unset($_SESSION["link_new_type"]);
783 unset($_SESSION["search_link_type"]);
784 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
785 $this->ctrl->redirect($this, "material");
786 }
787
788 public function addST()
789 {
790 $this->object->addInternalLink("il__st_" . $_GET["st"]);
791 unset($_SESSION["link_new_type"]);
792 unset($_SESSION["search_link_type"]);
793 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
794 $this->ctrl->redirect($this, "material");
795 }
796
797 public function addGIT()
798 {
799 $this->object->addInternalLink("il__git_" . $_GET["git"]);
800 unset($_SESSION["link_new_type"]);
801 unset($_SESSION["search_link_type"]);
802 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
803 $this->ctrl->redirect($this, "material");
804 }
805
806 public function linkChilds()
807 {
808 $ilTabs = $this->tabs;
809
810 $selectable_items = array();
811
812 $source_id = $_GET["source_id"];
813
814 switch ($_SESSION["search_link_type"]) {
815 case "pg":
816 $cont_obj_gui = new ilObjContentObjectGUI("", $source_id, true);
817 $cont_obj = $cont_obj_gui->object;
818 $pages = ilLMPageObject::getPageList($cont_obj->getId());
819 foreach ($pages as $page) {
820 if ($page["type"] == $_SESSION["search_link_type"]) {
821 $selectable_items[] = array(
822 "item_type" => $page["type"]
823 ,"item_id" => $page["obj_id"]
824 ,"title" => $page["title"]
825 );
826 }
827 }
828 break;
829
830 case "st":
831 $cont_obj_gui = new ilObjContentObjectGUI("", $source_id, true);
832 $cont_obj = $cont_obj_gui->object;
833 // get all chapters
834 $ctree = &$cont_obj->getLMTree();
835 $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
836 foreach ($nodes as $node) {
837 if ($node["type"] == $_SESSION["search_link_type"]) {
838 $selectable_items[] = array(
839 "item_type" => $node["type"]
840 ,"item_id" => $node["obj_id"]
841 ,"title" => $node["title"]
842 );
843 }
844 }
845 break;
846
847 case "glo":
848 $glossary = new ilObjGlossary($source_id, true);
849 // get all glossary items
850 $terms = $glossary->getTermList();
851 foreach ($terms as $term) {
852 $selectable_items[] = array(
853 "item_type" => "GIT"
854 ,"item_id" => $term["id"]
855 ,"title" => $term["term"]
856 );
857 }
858 break;
859
860 case "lm":
861 $this->object->addInternalLink("il__lm_" . $source_id);
862 break;
863 }
864
865 if (sizeof($selectable_items)) {
866 $ilTabs->activateTab("material");
867 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
868 $this->ctrl->setParameter($this, "source_id", $source_id);
869
870 $tbl = new SurveyMaterialsSourceTableGUI($this, "linkChilds", "addMaterial");
871 $tbl->setData($selectable_items);
872 $this->tpl->setContent($tbl->getHTML());
873 } else {
874 if ($_SESSION["search_link_type"] == "lm") {
875 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
876
877 unset($_SESSION["link_new_type"]);
878 unset($_SESSION["search_link_type"]);
879 $this->ctrl->redirect($this, "material");
880 } else {
881 ilUtil::sendFailure($this->lng->txt("material_added_empty"), true);
882 $this->ctrl->redirect($this, "addMaterial");
883 }
884 }
885 }
886
887
888 //
889 // PHRASES (see SurveyMatrixQuestionGUI)
890 //
891
892 protected function initPhrasesForm()
893 {
894 $form = new ilPropertyFormGUI();
895 $form->setFormAction($this->ctrl->getFormAction($this, "addSelectedPhrase"));
896 $form->setTitle($this->lng->txt("add_phrase"));
897 // $form->setDescription($this->lng->txt("add_phrase_introduction"));
898
899 $group = new ilRadioGroupInputGUI($this->lng->txt("phrase"), "phrases");
900 $group->setRequired(true);
901 $form->addItem($group);
902
903 foreach (ilSurveyPhrases::_getAvailablePhrases() as $phrase_id => $phrase_array) {
904 $categories = ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
905
906 $opt = new ilRadioOption($phrase_array["title"], $phrase_id);
907 $opt->setInfo(join(",", $categories));
908 $group->addOption($opt);
909
910 if ($phrase_array["org_title"] == "dp_standard_numbers") {
911 $min = new ilNumberInputGUI($this->lng->txt("lower_limit"), "lower_limit");
912 $min->setRequired(true);
913 $min->setSize(5);
914 $opt->addSubItem($min);
915
916 $max = new ilNumberInputGUI($this->lng->txt("upper_limit"), "upper_limit");
917 $max->setRequired(true);
918 $max->setSize(5);
919 $opt->addSubItem($max);
920 }
921 }
922
923 $form->addCommandButton("addSelectedPhrase", $this->lng->txt("add_phrase"));
924 $form->addCommandButton("editQuestion", $this->lng->txt("cancel"));
925
926 return $form;
927 }
928
932 protected function addPhrase(ilPropertyFormGUI $a_form = null)
933 {
934 $ilTabs = $this->tabs;
935
936 $ilTabs->activateTab("edit_properties");
937
938 if (!$a_form) {
939 $result = $this->saveForm();
940 if ($result) {
941 $this->object->saveToDb();
942 }
943
944 $a_form = $this->initPhrasesForm();
945 }
946
947 $this->tpl->setContent($a_form->getHTML());
948 }
949
950 protected function addSelectedPhrase()
951 {
952 $form = $this->initPhrasesForm();
953 if ($form->checkInput()) {
954 $phrase_id = $form->getInput("phrases");
955
956 $valid = true;
957 if (strcmp($this->object->getPhrase($phrase_id), "dp_standard_numbers") != 0) {
958 $this->object->addPhrase($phrase_id);
959 } else {
960 $min = $form->getInput("lower_limit");
961 $max = $form->getInput("upper_limit");
962
963 if ($max <= $min) {
964 $max_field = $form->getItemByPostVar("upper_limit");
965 $max_field->setAlert($this->lng->txt("upper_limit_must_be_greater"));
966 $valid = false;
967 } else {
968 $this->object->addStandardNumbers($min, $max);
969 }
970 }
971
972 if ($valid) {
973 $this->object->saveToDb();
974
975 ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
976 $this->ctrl->redirect($this, 'editQuestion');
977 }
978 }
979
980 $form->setValuesByPost();
981 $this->addPhrase($form);
982 }
983
989 public function savePhrase($a_reload = false)
990 {
991 $ilTabs = $this->tabs;
992 $ilToolbar = $this->toolbar;
993
994 $ilTabs->activateTab("edit_properties");
995
996 if (!$a_reload) {
997 $result = $this->saveForm();
998 if ($result) {
999 $this->object->saveToDb();
1000 }
1001 }
1002
1003 $txt = new ilTextInputGUI($this->lng->txt("enter_phrase_title"), "phrase_title");
1004 $ilToolbar->addInputItem($txt, true);
1005 $ilToolbar->addFormButton($this->lng->txt("confirm"), "confirmSavePhrase");
1006 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
1007
1008 $table_gui = new ilSurveySavePhraseTableGUI($this, 'editQuestion');
1009 $table_gui->setDescription($this->lng->txt("save_phrase_introduction"));
1010
1011 // matrix?
1012 if (method_exists($this->object, "getCategories")) {
1013 $categories = $this->object->getCategories();
1014 } else {
1015 $categories = $this->object->getColumns();
1016 }
1017
1018 $data = array();
1019 for ($i = 0; $i < $categories->getCategoryCount(); $i++) {
1020 $cat = $categories->getCategory($i);
1021
1022 $data[] = array(
1023 "answer" => $cat->title,
1024 "other" => $cat->other,
1025 "scale" => $cat->scale,
1026 "neutral" => $cat->neutral
1027 );
1028 }
1029 $table_gui->setData($data);
1030 $_SESSION['save_phrase_data'] = $data; // :TODO: see savePhrase()
1031
1032 $this->tpl->setContent($table_gui->getHTML());
1033 }
1034
1040 public function confirmSavePhrase()
1041 {
1042 $title = $_POST["phrase_title"];
1043
1044 $valid = true;
1045 if (!trim($title)) {
1046 ilUtil::sendFailure($this->lng->txt("qpl_savephrase_empty"));
1047 $valid = false;
1048 } elseif ($this->object->phraseExists($title)) {
1049 ilUtil::sendFailure($this->lng->txt("qpl_savephrase_exists"));
1050 $valid = false;
1051 }
1052
1053 if ($valid) {
1054 $this->object->savePhrase($title);
1055
1056 ilUtil::sendSuccess($this->lng->txt("phrase_saved"), true);
1057 $this->ctrl->redirect($this, "editQuestion");
1058 }
1059
1060 $this->savePhrase(true);
1061 }
1062
1063 protected function renderStatisticsDetailsTable(array $a_head, array $a_rows, array $a_foot = null)
1064 {
1065 $html = array();
1066 $html[] = '<div class="ilTableOuter table-responsive">';
1067 $html[] = '<table class="table table-striped">';
1068
1069 $html[] = "<thead>";
1070 $html[] = "<tr>";
1071 foreach ($a_head as $col) {
1072 $col = trim($col);
1073 $html[] = "<th>";
1074 $html[] = ($col != "") ? $col : "&nbsp;";
1075 $html[] = "</th>";
1076 }
1077 $html[] = "</tr>";
1078 $html[] = "</thead>";
1079
1080 $html[] = "<tbody>";
1081 foreach ($a_rows as $row) {
1082 $html[] = "<tr>";
1083 foreach ($row as $col) {
1084 $col = trim($col);
1085 $html[] = "<td>";
1086 $html[] = ($col != "") ? $col : "&nbsp;";
1087 $html[] = "</td>";
1088 }
1089 $html[] = "</tr>";
1090 }
1091 $html[] = "</tbody>";
1092
1093 if ($a_foot) {
1094 $html[] = "<tfoot>";
1095 $html[] = "<tr>";
1096 foreach ($a_foot as $col) {
1097 $col = trim($col);
1098 $html[] = "<td>";
1099 $html[] = ($col != "") ? $col : "&nbsp;";
1100 $html[] = "</td>";
1101 }
1102 $html[] = "</tr>";
1103 $html[] = "</tfoot>";
1104 }
1105
1106 $html[] = "</table>";
1107 $html[] = "</div>";
1108 return implode("\n", $html);
1109 }
1110}
$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.
getWorkingForm($working_data="", $question_title=1, $show_questiontext=1, $error_message="", $survey_id=null, $compress_view=false)
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)
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 _getRichTextEditor()
Returns the identifier for the Rich Text Editor.
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 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
$valid
$txt
Definition: error.php:13
global $DIC
Definition: goto.php:24
if(isset($_FILES['img_file']) &&is_array($_FILES['img_file'])) $panel
Definition: imgupload.php:138
$errors
Definition: imgupload.php:49
$ilUser
Definition: imgupload.php:18
$i
Definition: metadata.php:24
$ret
Definition: parser.php:6
$type
$data
Definition: storeScorm.php:23