ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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{
36 protected $tpl;
37 protected $lng;
38 protected $ctrl;
39 protected $cumulated; // [array]
40 protected $parent_url;
41
42 public $object;
43
44 public function __construct($a_id = -1)
45 {
46 global $lng, $tpl, $ilCtrl;
47
48 $this->lng = $lng;
49 $this->tpl = $tpl;
50 $this->ctrl = $ilCtrl;
51 $this->ctrl->saveParameter($this, "q_id");
52 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
53 $this->cumulated = array();
54
55 $this->initObject();
56
57 if($a_id > 0)
58 {
59 $this->object->loadFromDb($a_id);
60 }
61 }
62
63 abstract protected function initObject();
64 abstract public function setQuestionTabs();
65
66 public function &executeCommand()
67 {
68 $cmd = $this->ctrl->getCmd();
69 $next_class = $this->ctrl->getNextClass($this);
70 switch($next_class)
71 {
72 default:
73 $ret =& $this->$cmd();
74 break;
75 }
76 return $ret;
77 }
78
90 static function &_getQuestionGUI($questiontype, $question_id = -1)
91 {
92 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
93 if ((!$questiontype) and ($question_id > 0))
94 {
95 $questiontype = SurveyQuestion::_getQuestiontype($question_id);
96 }
97 SurveyQuestion::_includeClass($questiontype, 1);
98 $question_type_gui = $questiontype . "GUI";
99 $question = new $question_type_gui($question_id);
100 return $question;
101 }
102
103 function _getGUIClassNameForId($a_q_id)
104 {
105 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
106 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
107 $q_type = SurveyQuestion::_getQuestiontype($a_q_id);
108 $class_name = SurveyQuestionGUI::_getClassNameForQType($q_type);
109 return $class_name;
110 }
111
112 function _getClassNameForQType($q_type)
113 {
114 return $q_type;
115 }
116
124 {
125 return $this->object->getQuestionType();
126 }
127
128 protected function outQuestionText($template)
129 {
130 $questiontext = $this->object->getQuestiontext();
131 if (preg_match("/^<.[\\>]?>(.*?)<\\/.[\\>]*?>$/", $questiontext, $matches))
132 {
133 $questiontext = $matches[1];
134 }
135 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
136 if ($this->object->getObligatory($survey_id))
137 {
138 $template->setVariable("OBLIGATORY_TEXT", ' *');
139 }
140 }
141
142 public function setBackUrl($a_url)
143 {
144 $this->parent_url = $a_url;
145 }
146
147 function setQuestionTabsForClass($guiclass)
148 {
149 global $rbacsystem,$ilTabs;
150
151 $this->ctrl->setParameterByClass($guiclass, "sel_question_types", $this->getQuestionType());
152 $this->ctrl->setParameterByClass($guiclass, "q_id", $_GET["q_id"]);
153
154 if ($this->parent_url)
155 {
156 $addurl = "";
157 if (strlen($_GET["new_for_survey"]))
158 {
159 $addurl = "&new_id=" . $_GET["q_id"];
160 }
161 $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $this->parent_url . $addurl);
162 }
163 else
164 {
165 $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
166 $ilTabs->setBackTarget($this->lng->txt("spl"), $this->ctrl->getLinkTargetByClass("ilObjSurveyQuestionPoolGUI", "questions"));
167 }
168 if ($_GET["q_id"])
169 {
170 $ilTabs->addNonTabbedLink("preview",
171 $this->lng->txt("preview"),
172 $this->ctrl->getLinkTargetByClass($guiclass, "preview"));
173 }
174
175 if ($rbacsystem->checkAccess('edit', $_GET["ref_id"]))
176 {
177 $ilTabs->addTab("edit_properties",
178 $this->lng->txt("properties"),
179 $this->ctrl->getLinkTargetByClass($guiclass, "editQuestion"));
180
181 if(stristr($guiclass, "matrix"))
182 {
183 $ilTabs->addTab("layout",
184 $this->lng->txt("layout"),
185 $this->ctrl->getLinkTargetByClass($guiclass, "layout"));
186 }
187 }
188 if ($_GET["q_id"])
189 {
190 $ilTabs->addTab("material",
191 $this->lng->txt("material"),
192 $this->ctrl->getLinkTargetByClass($guiclass, "material"));
193 }
194
195 if ($this->object->getId() > 0)
196 {
197 $title = $this->lng->txt("edit") . " &quot;" . $this->object->getTitle() . "&quot";
198 }
199 else
200 {
201 $title = $this->lng->txt("create_new") . " " . $this->lng->txt($this->getQuestionType());
202 }
203
204 $this->tpl->setVariable("HEADER", $title);
205 }
206
207
208 //
209 // EDITOR
210 //
211
212 protected function initEditForm()
213 {
214 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
215 $form = new ilPropertyFormGUI();
216 $form->setFormAction($this->ctrl->getFormAction($this, "save"));
217 $form->setTitle($this->lng->txt($this->getQuestionType()));
218 $form->setMultipart(FALSE);
219 $form->setTableWidth("100%");
220 // $form->setId("essay");
221
222 // title
223 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
224 $title->setRequired(TRUE);
225 $form->addItem($title);
226
227 // label
228 $label = new ilTextInputGUI($this->lng->txt("label"), "label");
229 $label->setInfo($this->lng->txt("label_info"));
230 $label->setRequired(false);
231 $form->addItem($label);
232
233 // author
234 $author = new ilTextInputGUI($this->lng->txt("author"), "author");
235 $author->setRequired(TRUE);
236 $form->addItem($author);
237
238 // description
239 $description = new ilTextInputGUI($this->lng->txt("description"), "description");
240 $description->setRequired(FALSE);
241 $form->addItem($description);
242
243 // questiontext
244 $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
245 $question->setRequired(TRUE);
246 $question->setRows(10);
247 $question->setCols(80);
248 $question->setUseRte(TRUE);
249 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
250 $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
251 $question->addPlugin("latex");
252 $question->addButton("latex");
253 $question->addButton("pastelatex");
254 $question->setRTESupport($this->object->getId(), "spl", "survey");
255 $form->addItem($question);
256
257 // obligatory
258 $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
259 $shuffle->setValue(1);
260 $shuffle->setRequired(FALSE);
261 $form->addItem($shuffle);
262
263 $this->addFieldsToEditForm($form);
264
265 $this->addCommandButtons($form);
266
267 // values
268 $title->setValue($this->object->getTitle());
269 $label->setValue($this->object->label);
270 $author->setValue($this->object->getAuthor());
271 $description->setValue($this->object->getDescription());
272 $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
273 $shuffle->setChecked($this->object->getObligatory());
274
275 return $form;
276 }
277
278 protected function addCommandButtons($a_form)
279 {
280 $a_form->addCommandButton("saveReturn", $this->lng->txt("save_return"));
281 $a_form->addCommandButton("save", $this->lng->txt("save"));
282
283 // pool question?
284 if(ilObject::_lookupType($this->object->getObjId()) == "spl")
285 {
286 if($this->object->hasCopies())
287 {
288 $a_form->addCommandButton("saveSync", $this->lng->txt("svy_save_sync"));
289 }
290 }
291 }
292
293 protected function editQuestion(ilPropertyFormGUI $a_form = null)
294 {
295 global $ilTabs;
296
297 $ilTabs->activateTab("edit_properties");
298
299 if(!$a_form)
300 {
301 $a_form = $this->initEditForm();
302 }
303 $this->tpl->setContent($a_form->getHTML());
304 }
305
306 protected function saveSync()
307 {
308 $this->save($_REQUEST["rtrn"], true);
309 }
310
311 protected function saveReturn()
312 {
313 $this->save(true);
314 }
315
316 protected function saveForm()
317 {
318 $form = $this->initEditForm();
319 if($form->checkInput())
320 {
321 if ($this->validateEditForm($form))
322 {
323 $this->object->setTitle($form->getInput("title"));
324 $this->object->label = ($form->getInput("label"));
325 $this->object->setAuthor($form->getInput("author"));
326 $this->object->setDescription($form->getInput("description"));
327 $this->object->setQuestiontext($form->getInput("question"));
328 $this->object->setObligatory($form->getInput("obligatory"));
329
330 $this->importEditFormValues($form);
331
332 // will save both core and extended data
333 $this->object->saveToDb();
334
335 return true;
336 }
337 }
338
339 $form->setValuesByPost();
340 $this->editQuestion($form);
341 return false;
342 }
343
344 protected function save($a_return = false, $a_sync = false)
345 {
346 global $ilUser;
347
348 if($this->saveForm())
349 {
350 // #13784
351 if ($a_return &&
352 !SurveyQuestion::_isComplete($this->object->getId()))
353 {
354 ilUtil::sendFailure($this->lng->txt("survey_error_insert_incomplete_question"));
355 return $this->editQuestion();
356 }
357
358 $ilUser->setPref("svy_lastquestiontype", $this->object->getQuestionType());
359 $ilUser->writePref("svy_lastquestiontype", $this->object->getQuestionType());
360
361 $originalexists = $this->object->_questionExists($this->object->original_id);
362 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
363 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestion.php";
364
365 // pool question?
366 if($a_sync)
367 {
368 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
369 $this->ctrl->redirect($this, 'copySyncForm');
370 }
371 else
372 {
373 // form: update original pool question, too?
374 if ($originalexists &&
375 SurveyQuestion::_isWriteable($this->object->original_id, $ilUser->getId()))
376 {
377 if($a_return)
378 {
379 $this->ctrl->setParameter($this, 'rtrn', 1);
380 }
381 $this->ctrl->redirect($this, 'originalSyncForm');
382 }
383 }
384
385 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
386 $this->redirectAfterSaving($a_return);
387 }
388 }
389
390 protected function copySyncForm()
391 {
392 global $ilTabs;
393
394 $ilTabs->activateTab("edit_properties");
395
396 include_once "Modules/SurveyQuestionPool/classes/class.ilSurveySyncTableGUI.php";
397 $tbl = new ilSurveySyncTableGUI($this, "copySyncForm", $this->object);
398
399 $this->tpl->setContent($tbl->getHTML());
400 }
401
402 protected function syncCopies()
403 {
404 global $lng, $ilAccess;
405
406 if(!sizeof($_POST["qid"]))
407 {
408 ilUtil::sendFailure($lng->txt("select_one"));
409 return $this->copySyncForm();
410 }
411
412 foreach($this->object->getCopyIds(true) as $survey_id => $questions)
413 {
414 // check permissions for "parent" survey
415 $can_write = false;
416 $ref_ids = ilObject::_getAllReferences($survey_id);
417 foreach($ref_ids as $ref_id)
418 {
419 if($ilAccess->checkAccess("edit", "", $ref_id))
420 {
421 $can_write = true;
422 break;
423 }
424 }
425
426 if($can_write)
427 {
428 foreach($questions as $qid)
429 {
430 if(in_array($qid, $_POST["qid"]))
431 {
432 $id = $this->object->getId();
433
434 $this->object->setId($qid);
435 $this->object->setOriginalId($id);
436 $this->object->saveToDb();
437
438 $this->object->setId($id);
439 $this->object->setOriginalId(null);
440
441 // see: SurveyQuestion::syncWithOriginal()
442 // what about material?
443 }
444 }
445 }
446 }
447
448 ilUtil::sendSuccess($lng->txt("survey_sync_success"), true);
449 $this->redirectAfterSaving($_REQUEST["rtrn"]);
450 }
451
452 protected function originalSyncForm()
453 {
454 global $ilTabs;
455
456 $ilTabs->activateTab("edit_properties");
457
458 $this->ctrl->saveParameter($this, "rtrn");
459
460 include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
461 $cgui = new ilConfirmationGUI();
462 $cgui->setHeaderText($this->lng->txt("confirm_sync_questions"));
463
464 $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
465 $cgui->setCancel($this->lng->txt("no"), "cancelSync");
466 $cgui->setConfirm($this->lng->txt("yes"), "sync");
467
468 $this->tpl->setContent($cgui->getHTML());
469 }
470
471 protected function sync()
472 {
473 $original_id = $this->object->original_id;
474 if ($original_id)
475 {
476 $this->object->syncWithOriginal();
477 }
478
479 ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
480 $this->redirectAfterSaving($_REQUEST["rtrn"]);
481 }
482
483 protected function cancelSync()
484 {
485 ilUtil::sendInfo($this->lng->txt("question_changed_in_survey_only"), true);
486 $this->redirectAfterSaving($_REQUEST["rtrn"]);
487 }
488
494 protected function redirectAfterSaving($a_return = false)
495 {
496 // return?
497 if($a_return)
498 {
499 // to calling survey
500 if($this->parent_url)
501 {
502 $addurl = "";
503 if (strlen($_GET["new_for_survey"]))
504 {
505 $addurl = "&new_id=" . $_GET["q_id"];
506 }
507 ilUtil::redirect(str_replace("&amp;", "&", $this->parent_url) . $addurl);
508 }
509 // to pool
510 else
511 {
512 $this->ctrl->setParameterByClass("ilObjSurveyQuestionPoolGUI", "q_id_table_nav", $_SESSION['q_id_table_nav']);
513 $this->ctrl->redirectByClass("ilObjSurveyQuestionPoolGUI", "questions");
514 }
515 }
516 // stay in form
517 else
518 {
519 $this->ctrl->setParameterByClass($_GET["cmdClass"], "q_id", $this->object->getId());
520 $this->ctrl->setParameterByClass($_GET["cmdClass"], "sel_question_types", $_GET["sel_question_types"]);
521 $this->ctrl->setParameterByClass($_GET["cmdClass"], "new_for_survey", $_GET["new_for_survey"]);
522 $this->ctrl->redirectByClass($_GET["cmdClass"], "editQuestion");
523 }
524 }
525
526 protected function cancel()
527 {
528 if ($this->parent_url)
529 {
530 ilUtil::redirect($this->parent_url);
531 }
532 else
533 {
534 $this->ctrl->redirectByClass("ilobjsurveyquestionpoolgui", "questions");
535 }
536 }
537
538 protected function validateEditForm(ilPropertyFormGUI $a_form)
539 {
540 return true;
541 }
542
543 abstract protected function addFieldsToEditForm(ilPropertyFormGUI $a_form);
544 abstract protected function importEditFormValues(ilPropertyFormGUI $a_form);
545
546 abstract public function getPrintView($question_title = 1, $show_questiontext = 1);
547
548 protected function getPrintViewQuestionTitle($question_title = 1)
549 {
550 switch ($question_title)
551 {
552 case 1:
553 $title = ilUtil::prepareFormOutput($this->object->getTitle());
554 break;
555
556 case 2:
557 $title = ilUtil::prepareFormOutput($this->object->getLabel());
558 break;
559
560 case 3:
561 $title = ilUtil::prepareFormOutput($this->object->getTitle());
562 if(trim($this->object->getLabel()))
563 {
564 $title .= ' <span class="questionLabel">('.ilUtil::prepareFormOutput($this->object->getLabel()).')</span>';
565 }
566 break;
567 }
568 return $title;
569 }
570
576 function preview()
577 {
578 global $ilTabs;
579
580 $ilTabs->activateTab("preview");
581
582 $tpl = new ilTemplate("tpl.il_svy_qpl_preview.html", true, true, "Modules/SurveyQuestionPool");
583
584 if ($this->object->getObligatory())
585 {
586 $tpl->setCurrentBlock("required");
587 $tpl->setVariable("TEXT_REQUIRED", $this->lng->txt("required_field"));
588 $tpl->parseCurrentBlock();
589 }
590
591 $tpl->setVariable("QUESTION_OUTPUT", $this->getWorkingForm());
592
593 include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
594 $panel = ilPanelGUI::getInstance();
595 $panel->setBody($tpl->get());
596
597 $this->tpl->setContent($panel->getHTML());
598 }
599
600
601 //
602 // EXECUTION
603 //
604
605 abstract public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null);
606
610 protected function getMaterialOutput()
611 {
612 if (count($this->object->getMaterial()))
613 {
614 $template = new ilTemplate("tpl.il_svy_qpl_material.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
615 foreach ($this->object->getMaterial() as $material)
616 {
617 $template->setCurrentBlock('material');
618 switch ($material->type)
619 {
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 //
637 // EVALUATION
638 //
639
640 abstract public function getCumulatedResultsDetails($survey_id, $counter, $finished_ids);
641
642 protected function renderChart($a_id, $a_variables)
643 {
644 include_once "Services/Chart/classes/class.ilChart.php";
646 $chart->setsize(700, 400);
647
648 $legend = new ilChartLegend();
649 $chart->setLegend($legend);
650 $chart->setYAxisToInteger(true);
651
652 $data = $chart->getDataInstance(ilChartGrid::DATA_BARS);
653 $data->setLabel($this->lng->txt("category_nr_selected"));
654 $data->setBarOptions(0.5, "center");
655
656 $max = 5;
657
658 if(sizeof($a_variables) <= $max)
659 {
660 if($a_variables)
661 {
662 $labels = array();
663 foreach($a_variables as $idx => $points)
664 {
665 $data->addPoint($idx, $points["selected"]);
666 $labels[$idx] = ($idx+1).". ".ilUtil::prepareFormOutput($points["title"]);
667 }
668 $chart->addData($data);
669
670 $chart->setTicks($labels, false, true);
671 }
672
673 return "<div style=\"margin:10px\">".$chart->getHTML()."</div>";
674 }
675 else
676 {
677 $chart_legend = array();
678 $labels = array();
679 foreach($a_variables as $idx => $points)
680 {
681 $data->addPoint($idx, $points["selected"]);
682 $labels[$idx] = ($idx+1).".";
683 $chart_legend[($idx+1)] = ilUtil::prepareFormOutput($points["title"]);
684 }
685 $chart->addData($data);
686
687 $chart->setTicks($labels, false, true);
688
689 $legend = "<table>";
690 foreach($chart_legend as $number => $caption)
691 {
692 $legend .= "<tr valign=\"top\"><td>".$number.".</td><td>".$caption."</td></tr>";
693 }
694 $legend .= "</table>";
695
696 return "<div style=\"margin:10px\"><table><tr valign=\"bottom\"><td>".
697 $chart->getHTML()."</td><td class=\"small\" style=\"padding-left:15px\">".
698 $legend."</td></tr></table></div>";
699 }
700 }
701
702
703
704 //
705 // MATERIAL
706 //
707
711 public function material($checkonly = FALSE)
712 {
713 global $rbacsystem, $ilTabs;
714
715 $ilTabs->activateTab("material");
716
717 $add_html = '';
718 if ($rbacsystem->checkAccess('write', $_GET['ref_id']))
719 {
720 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
721 $form = new ilPropertyFormGUI();
722 $form->setFormAction($this->ctrl->getFormAction($this));
723 $form->setTitle($this->lng->txt('add_material'));
724 $form->setMultipart(FALSE);
725 $form->setTableWidth("100%");
726 $form->setId("material");
727
728 // material
729 $material = new ilRadioGroupInputGUI($this->lng->txt("material"), "internalLinkType");
730 $material->setRequired(true);
731 $material->addOption(new ilRadioOption($this->lng->txt('obj_lm'), "lm"));
732 $material->addOption(new ilRadioOption($this->lng->txt('obj_st'), "st"));
733 $material->addOption(new ilRadioOption($this->lng->txt('obj_pg'), "pg"));
734 $material->addOption(new ilRadioOption($this->lng->txt('glossary_term'), "glo"));
735 $form->addItem($material);
736
737 $form->addCommandButton("addMaterial", $this->lng->txt("add"));
738
739 $errors = false;
740
741 if ($checkonly)
742 {
743 $form->setValuesByPost();
744 $errors = !$form->checkInput();
745 if ($errors) $checkonly = false;
746 }
747 $add_html = $form->getHTML();
748 }
749
750
751 $mat_html = "";
752 if (count($this->object->getMaterial()))
753 {
754 include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyMaterialsTableGUI.php";
755 $table_gui = new ilSurveyMaterialsTableGUI($this, 'material', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
756 $data = array();
757 foreach ($this->object->getMaterial() as $material)
758 {
759 switch ($material->type)
760 {
761 case 0:
762 $href = SurveyQuestion::_getInternalLinkHref($material->internal_link, $_GET['ref_id']);
763 $type = $this->lng->txt('internal_link');
764 break;
765 }
766 $title = (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material');
767 array_push($data, array('href' => $href, 'title' => $title, 'type' => $type));
768 }
769 $table_gui->setData($data);
770 $mat_html = $table_gui->getHTML();
771 }
772
773 if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $add_html . $mat_html);
774 return $errors;
775 }
776
777 public function deleteMaterial()
778 {
779 if (is_array($_POST['idx']))
780 {
781 $this->object->deleteMaterials($_POST['idx']);
782 ilUtil::sendSuccess($this->lng->txt('materials_deleted'), true);
783 }
784 else
785 {
786 ilUtil::sendFailure($this->lng->txt('no_checkbox'), true);
787 }
788 $this->ctrl->redirect($this, 'material');
789 }
790
794 public function addMaterial()
795 {
796 global $tree, $ilTabs, $ilToolbar;
797
798 $ilTabs->activateTab("material");
799
800 $ilToolbar->addButton($this->lng->txt("cancel"),
801 $this->ctrl->getLinkTarget($this, "material"));
802
803 if (strlen($_SESSION["link_new_type"]) || !$this->material(true))
804 {
805 include_once("./Modules/SurveyQuestionPool/classes/class.ilMaterialExplorer.php");
806 switch ($_POST["internalLinkType"])
807 {
808 case "lm":
809 $_SESSION["link_new_type"] = "lm";
810 $_SESSION["search_link_type"] = "lm";
811 break;
812 case "glo":
813 $_SESSION["link_new_type"] = "glo";
814 $_SESSION["search_link_type"] = "glo";
815 break;
816 case "st":
817 $_SESSION["link_new_type"] = "lm";
818 $_SESSION["search_link_type"] = "st";
819 break;
820 case "pg":
821 $_SESSION["link_new_type"] = "lm";
822 $_SESSION["search_link_type"] = "pg";
823 break;
824 }
825
826 $exp = new ilMaterialExplorer($this, 'addMaterial', $_SESSION["link_new_type"]);
827 $exp->setPathOpen((int)$_GET["ref_id"]);
828 if (!$exp->handleCommand())
829 {
830 include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
831 $panel = ilPanelGUI::getInstance();
832 $panel->setHeading($this->lng->txt("select_object_to_link"));
833 $panel->setBody($exp->getHTML());
834
835 $this->tpl->setContent($panel->getHTML());
836 }
837 }
838 }
839
840 function removeMaterial()
841 {
842 $this->object->material = array();
843 $this->object->saveToDb();
844 $this->editQuestion();
845 }
846
847 function cancelExplorer()
848 {
849 unset($_SESSION["link_new_type"]);
850 ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
851 $this->ctrl->redirect($this, 'material');
852 }
853
854 function addPG()
855 {
856 $this->object->addInternalLink("il__pg_" . $_GET["pg"]);
857 unset($_SESSION["link_new_type"]);
858 unset($_SESSION["search_link_type"]);
859 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
860 $this->ctrl->redirect($this, "material");
861 }
862
863 function addST()
864 {
865 $this->object->addInternalLink("il__st_" . $_GET["st"]);
866 unset($_SESSION["link_new_type"]);
867 unset($_SESSION["search_link_type"]);
868 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
869 $this->ctrl->redirect($this, "material");
870 }
871
872 function addGIT()
873 {
874 $this->object->addInternalLink("il__git_" . $_GET["git"]);
875 unset($_SESSION["link_new_type"]);
876 unset($_SESSION["search_link_type"]);
877 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
878 $this->ctrl->redirect($this, "material");
879 }
880
881 function linkChilds()
882 {
883 global $ilTabs;
884
885 $selectable_items = array();
886
887 $source_id = $_GET["source_id"];
888
889 switch ($_SESSION["search_link_type"])
890 {
891 case "pg":
892 include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
893 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
894 $cont_obj_gui =& new ilObjContentObjectGUI("", $source_id, true);
895 $cont_obj = $cont_obj_gui->object;
896 $pages = ilLMPageObject::getPageList($cont_obj->getId());
897 foreach($pages as $page)
898 {
899 if($page["type"] == $_SESSION["search_link_type"])
900 {
901 $selectable_items[] = array(
902 "item_type" => $page["type"]
903 ,"item_id" => $page["obj_id"]
904 ,"title" => $page["title"]
905 );
906 }
907 }
908 break;
909
910 case "st":
911 include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
912 $cont_obj_gui =& new ilObjContentObjectGUI("", $source_id, true);
913 $cont_obj = $cont_obj_gui->object;
914 // get all chapters
915 $ctree =& $cont_obj->getLMTree();
916 $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
917 foreach($nodes as $node)
918 {
919 if($node["type"] == $_SESSION["search_link_type"])
920 {
921 $selectable_items[] = array(
922 "item_type" => $node["type"]
923 ,"item_id" => $node["obj_id"]
924 ,"title" => $node["title"]
925 );
926 }
927 }
928 break;
929
930 case "glo":
931 include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
932 $glossary =& new ilObjGlossary($source_id, true);
933 // get all glossary items
934 $terms = $glossary->getTermList();
935 foreach($terms as $term)
936 {
937 $selectable_items[] = array(
938 "item_type" => "GIT"
939 ,"item_id" => $term["id"]
940 ,"title" => $term["term"]
941 );
942 }
943 break;
944
945 case "lm":
946 $this->object->addInternalLink("il__lm_" . $source_id);
947 break;
948 }
949
950 if(sizeof($selectable_items))
951 {
952 $ilTabs->activateTab("material");
953 $this->ctrl->setParameter($this, "q_id", $this->object->getId());
954 $this->ctrl->setParameter($this, "source_id", $source_id);
955
956 include_once "Modules/SurveyQuestionPool/classes/tables/class.SurveyMaterialsSourceTableGUI.php";
957 $tbl = new SurveyMaterialsSourceTableGUI($this, "linkChilds", "addMaterial");
958 $tbl->setData($selectable_items);
959 $this->tpl->setContent($tbl->getHTML());
960 }
961 else
962 {
963 if($_SESSION["search_link_type"] == "lm")
964 {
965 ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
966
967 unset($_SESSION["link_new_type"]);
968 unset($_SESSION["search_link_type"]);
969 $this->ctrl->redirect($this, "material");
970 }
971 else
972 {
973 ilUtil::sendFailure($this->lng->txt("material_added_empty"), true);
974 $this->ctrl->redirect($this, "addMaterial");
975 }
976 }
977 }
978
979
980 //
981 // PHRASES (see SurveyMatrixQuestionGUI)
982 //
983
984 protected function initPhrasesForm()
985 {
986 include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
987 $form = new ilPropertyFormGUI();
988 $form->setFormAction($this->ctrl->getFormAction($this, "addSelectedPhrase"));
989 $form->setTitle($this->lng->txt("add_phrase"));
990 // $form->setDescription($this->lng->txt("add_phrase_introduction"));
991
992 $group = new ilRadioGroupInputGUI($this->lng->txt("phrase"), "phrases");
993 $group->setRequired(true);
994 $form->addItem($group);
995
996 include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
997 foreach (ilSurveyPhrases::_getAvailablePhrases() as $phrase_id => $phrase_array)
998 {
999 $categories = ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
1000
1001 $opt = new ilRadioOption($phrase_array["title"], $phrase_id);
1002 $opt->setInfo(join($categories, ","));
1003 $group->addOption($opt);
1004
1005 if($phrase_array["org_title"] == "dp_standard_numbers")
1006 {
1007 $min = new ilNumberInputGUI($this->lng->txt("lower_limit"), "lower_limit");
1008 $min->setRequired(true);
1009 $min->setSize(5);
1010 $opt->addSubItem($min);
1011
1012 $max = new ilNumberInputGUI($this->lng->txt("upper_limit"), "upper_limit");
1013 $max->setRequired(true);
1014 $max->setSize(5);
1015 $opt->addSubItem($max);
1016 }
1017 }
1018
1019 $form->addCommandButton("addSelectedPhrase", $this->lng->txt("add_phrase"));
1020 $form->addCommandButton("editQuestion", $this->lng->txt("cancel"));
1021
1022 return $form;
1023 }
1024
1028 protected function addPhrase(ilPropertyFormGUI $a_form = null)
1029 {
1030 global $ilTabs;
1031
1032 $ilTabs->activateTab("edit_properties");
1033
1034 if(!$a_form)
1035 {
1036 $result = $this->saveForm();
1037 if($result)
1038 {
1039 $this->object->saveToDb();
1040 }
1041
1042 $a_form = $this->initPhrasesForm();
1043 }
1044
1045 $this->tpl->setContent($a_form->getHTML());
1046 }
1047
1048 protected function addSelectedPhrase()
1049 {
1050 $form = $this->initPhrasesForm();
1051 if($form->checkInput())
1052 {
1053 $phrase_id = $form->getInput("phrases");
1054
1055 $valid = true;
1056 if (strcmp($this->object->getPhrase($phrase_id), "dp_standard_numbers") != 0)
1057 {
1058 $this->object->addPhrase($phrase_id);
1059 }
1060 else
1061 {
1062 $min = $form->getInput("lower_limit");
1063 $max = $form->getInput("upper_limit");
1064
1065 if($max <= $min)
1066 {
1067 $max_field = $form->getItemByPostVar("upper_limit");
1068 $max_field->setAlert($this->lng->txt("upper_limit_must_be_greater"));
1069 $valid = false;
1070 }
1071 else
1072 {
1073 $this->object->addStandardNumbers($min, $max);
1074 }
1075 }
1076
1077 if($valid)
1078 {
1079 $this->object->saveToDb();
1080
1081 ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
1082 $this->ctrl->redirect($this, 'editQuestion');
1083 }
1084 }
1085
1086 $form->setValuesByPost();
1087 $this->addPhrase($form);
1088 }
1089
1095 function savePhrase($a_reload = false)
1096 {
1097 global $ilTabs, $ilToolbar;
1098
1099 $ilTabs->activateTab("edit_properties");
1100
1101 if (!$a_reload)
1102 {
1103 $result = $this->saveForm();
1104 if ($result)
1105 {
1106 $this->object->saveToDb();
1107 }
1108 }
1109
1110 include_once("./Services/Form/classes/class.ilTextInputGUI.php");
1111 $txt = new ilTextInputGUI($this->lng->txt("enter_phrase_title"), "phrase_title");
1112 $ilToolbar->addInputItem($txt, true);
1113 $ilToolbar->addFormButton($this->lng->txt("confirm"), "confirmSavePhrase");
1114 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
1115
1116 include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveySavePhraseTableGUI.php";
1117 $table_gui = new ilSurveySavePhraseTableGUI($this, 'editQuestion');
1118 $table_gui->setDescription($this->lng->txt("save_phrase_introduction"));
1119
1120 // matrix?
1121 if(method_exists($this->object, "getCategories"))
1122 {
1123 $categories = $this->object->getCategories();
1124 }
1125 else
1126 {
1127 $categories = $this->object->getColumns();
1128 }
1129
1130 $data = array();
1131 for ($i = 0; $i < $categories->getCategoryCount(); $i++)
1132 {
1133 $cat = $categories->getCategory($i);
1134
1135 $data[] = array(
1136 "answer" => $cat->title,
1137 "other" => $cat->other,
1138 "scale" => $cat->scale,
1139 "neutral" => $cat->neutral
1140 );
1141 }
1142 $table_gui->setData($data);
1143 $_SESSION['save_phrase_data'] = $data; // :TODO: see savePhrase()
1144
1145 $this->tpl->setContent($table_gui->getHTML());
1146 }
1147
1154 {
1155 $title = $_POST["phrase_title"];
1156
1157 $valid = true;
1158 if (!trim($title))
1159 {
1160 ilUtil::sendFailure($this->lng->txt("qpl_savephrase_empty"));
1161 $valid = false;
1162 }
1163 else if ($this->object->phraseExists($title))
1164 {
1165 ilUtil::sendFailure($this->lng->txt("qpl_savephrase_exists"));
1166 $valid = false;
1167 }
1168
1169 if($valid)
1170 {
1171 $this->object->savePhrase($title);
1172
1173 ilUtil::sendSuccess($this->lng->txt("phrase_saved"), true);
1174 $this->ctrl->redirect($this, "editQuestion");
1175 }
1176
1177 $this->savePhrase(true);
1178 }
1179
1180 protected function renderStatisticsDetailsTable(array $a_head, array $a_rows, array $a_foot = null)
1181 {
1182 $html = array();
1183 $html[] = '<div class="ilTableOuter table-responsive">';
1184 $html[] = '<table class="table table-striped">';
1185
1186 $html[] = "<thead>";
1187 $html[] = "<tr>";
1188 foreach($a_head as $col)
1189 {
1190 $col = trim($col);
1191 $html[] = "<th>";
1192 $html[] = ($col != "") ? $col : "&nbsp;";
1193 $html[] = "</th>";
1194 }
1195 $html[] = "</tr>";
1196 $html[] = "</thead>";
1197
1198 $html[] = "<tbody>";
1199 foreach($a_rows as $row)
1200 {
1201 $html[] = "<tr>";
1202 foreach($row as $col)
1203 {
1204 $col = trim($col);
1205 $html[] = "<td>";
1206 $html[] = ($col != "") ? $col : "&nbsp;";
1207 $html[] = "</td>";
1208 }
1209 $html[] = "</tr>";
1210 }
1211 $html[] = "</tbody>";
1212
1213 if($a_foot)
1214 {
1215 $html[] = "<tfoot>";
1216 $html[] = "<tr>";
1217 foreach($a_foot as $col)
1218 {
1219 $col = trim($col);
1220 $html[] = "<td>";
1221 $html[] = ($col != "") ? $col : "&nbsp;";
1222 $html[] = "</td>";
1223 }
1224 $html[] = "</tr>";
1225 $html[] = "</tfoot>";
1226 }
1227
1228 $html[] = "</table>";
1229 $html[] = "</div>";
1230 return implode("\n", $html);
1231 }
1232}
1233
1234?>
$result
$_GET["client_id"]
$_SESSION["AccountId"]
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.
getCumulatedResultsDetails($survey_id, $counter, $finished_ids)
savePhrase($a_reload=false)
Creates an output to save the current answers as a phrase.
renderChart($a_id, $a_variables)
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.
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.
importEditFormValues(ilPropertyFormGUI $a_form)
_getInternalLinkHref($target="", $a_parent_ref_id=null)
_isWriteable($question_id, $user_id)
Returns true if the question is writeable by a certain user.
_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.
static getInstanceByType($a_type, $a_id)
Get type instance.
const TYPE_GRID
This class represents a checkbox property in a property form.
Confirmation screen class.
getPageList($lm_id)
static
This class represents a number property in a property form.
& _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 & _getCategoriesForPhrase($phrase_id)
Gets the available categories for a given phrase.
static & _getAvailablePhrases($useronly=0)
Gets the available phrases from the database.
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)
http redirect to other 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
$_POST['username']
Definition: cron.php:12
$valid
$txt
Definition: error.php:12
$html
Definition: example_001.php:87
$data
$tbl
Definition: example_048.php:81
$legend
global $ilCtrl
Definition: ilias.php:18
$cmd
Definition: sahs_server.php:35
$ref_id
Definition: sahs_server.php:39
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
$errors
global $ilUser
Definition: imgupload.php:15