ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
34 abstract 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 
123  function getQuestionType()
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 
553  function preview()
554  {
555  global $ilTabs;
556 
557  $ilTabs->activateTab("preview");
558 
559  $tpl = new ilTemplate("tpl.il_svy_qpl_preview.html", true, true, "Modules/SurveyQuestionPool");
560 
561  if ($this->object->getObligatory())
562  {
563  $tpl->setCurrentBlock("required");
564  $tpl->setVariable("TEXT_REQUIRED", $this->lng->txt("required_field"));
565  $tpl->parseCurrentBlock();
566  }
567 
568  $tpl->setVariable("QUESTION_OUTPUT", $this->getWorkingForm());
569 
570  include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
571  $panel = ilPanelGUI::getInstance();
572  $panel->setBody($tpl->get());
573 
574  $this->tpl->setContent($panel->getHTML());
575  }
576 
577 
578  //
579  // EXECUTION
580  //
581 
582  abstract public function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null);
583 
587  protected function getMaterialOutput()
588  {
589  if (count($this->object->getMaterial()))
590  {
591  $template = new ilTemplate("tpl.il_svy_qpl_material.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
592  foreach ($this->object->getMaterial() as $material)
593  {
594  $template->setCurrentBlock('material');
595  switch ($material->type)
596  {
597  case 0:
598  $href = SurveyQuestion::_getInternalLinkHref($material->internal_link, $_GET['ref_id']);
599  $template->setVariable('MATERIAL_TYPE', 'internallink');
600  $template->setVariable('MATERIAL_HREF', $href);
601  break;
602  }
603  $template->setVariable('MATERIAL_TITLE', (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material'));
604  $template->setVariable('TEXT_AVAILABLE_MATERIALS', $this->lng->txt('material'));
605  $template->parseCurrentBlock();
606  }
607  return $template->get();
608  }
609  return "";
610  }
611 
612 
613  //
614  // EVALUATION
615  //
616 
617  abstract public function getCumulatedResultsDetails($survey_id, $counter, $finished_ids);
618 
619  protected function renderChart($a_id, $a_variables)
620  {
621  include_once "Services/Chart/classes/class.ilChart.php";
623  $chart->setsize(700, 400);
624 
625  $legend = new ilChartLegend();
626  $chart->setLegend($legend);
627  $chart->setYAxisToInteger(true);
628 
629  $data = $chart->getDataInstance(ilChartGrid::DATA_BARS);
630  $data->setLabel($this->lng->txt("users_answered"));
631  $data->setBarOptions(0.5, "center");
632 
633  $max = 5;
634 
635  if(sizeof($a_variables) <= $max)
636  {
637  if($a_variables)
638  {
639  $labels = array();
640  foreach($a_variables as $idx => $points)
641  {
642  $data->addPoint($idx, $points["selected"]);
643  $labels[$idx] = ($idx+1).". ".ilUtil::prepareFormOutput($points["title"]);
644  }
645  $chart->addData($data);
646 
647  $chart->setTicks($labels, false, true);
648  }
649 
650  return "<div style=\"margin:10px\">".$chart->getHTML()."</div>";
651  }
652  else
653  {
654  $chart_legend = array();
655  $labels = array();
656  foreach($a_variables as $idx => $points)
657  {
658  $data->addPoint($idx, $points["selected"]);
659  $labels[$idx] = ($idx+1).".";
660  $chart_legend[($idx+1)] = ilUtil::prepareFormOutput($points["title"]);
661  }
662  $chart->addData($data);
663 
664  $chart->setTicks($labels, false, true);
665 
666  $legend = "<table>";
667  foreach($chart_legend as $number => $caption)
668  {
669  $legend .= "<tr valign=\"top\"><td>".$number.".</td><td>".$caption."</td></tr>";
670  }
671  $legend .= "</table>";
672 
673  return "<div style=\"margin:10px\"><table><tr valign=\"bottom\"><td>".
674  $chart->getHTML()."</td><td class=\"small\" style=\"padding-left:15px\">".
675  $legend."</td></tr></table></div>";
676  }
677  }
678 
679 
680 
681  //
682  // MATERIAL
683  //
684 
688  public function material($checkonly = FALSE)
689  {
690  global $rbacsystem, $ilTabs;
691 
692  $ilTabs->activateTab("material");
693 
694  $add_html = '';
695  if ($rbacsystem->checkAccess('write', $_GET['ref_id']))
696  {
697  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
698  $form = new ilPropertyFormGUI();
699  $form->setFormAction($this->ctrl->getFormAction($this));
700  $form->setTitle($this->lng->txt('add_material'));
701  $form->setMultipart(FALSE);
702  $form->setTableWidth("100%");
703  $form->setId("material");
704 
705  // material
706  $material = new ilRadioGroupInputGUI($this->lng->txt("material"), "internalLinkType");
707  $material->setRequired(true);
708  $material->addOption(new ilRadioOption($this->lng->txt('obj_lm'), "lm"));
709  $material->addOption(new ilRadioOption($this->lng->txt('obj_st'), "st"));
710  $material->addOption(new ilRadioOption($this->lng->txt('obj_pg'), "pg"));
711  $material->addOption(new ilRadioOption($this->lng->txt('glossary_term'), "glo"));
712  $form->addItem($material);
713 
714  $form->addCommandButton("addMaterial", $this->lng->txt("add"));
715 
716  $errors = false;
717 
718  if ($checkonly)
719  {
720  $form->setValuesByPost();
721  $errors = !$form->checkInput();
722  if ($errors) $checkonly = false;
723  }
724  $add_html = $form->getHTML();
725  }
726 
727 
728  $mat_html = "";
729  if (count($this->object->getMaterial()))
730  {
731  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveyMaterialsTableGUI.php";
732  $table_gui = new ilSurveyMaterialsTableGUI($this, 'material', (($rbacsystem->checkAccess('write', $_GET['ref_id']) ? true : false)));
733  $data = array();
734  foreach ($this->object->getMaterial() as $material)
735  {
736  switch ($material->type)
737  {
738  case 0:
739  $href = SurveyQuestion::_getInternalLinkHref($material->internal_link, $_GET['ref_id']);
740  $type = $this->lng->txt('internal_link');
741  break;
742  }
743  $title = (strlen($material->title)) ? ilUtil::prepareFormOutput($material->title) : $this->lng->txt('material');
744  array_push($data, array('href' => $href, 'title' => $title, 'type' => $type));
745  }
746  $table_gui->setData($data);
747  $mat_html = $table_gui->getHTML();
748  }
749 
750  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $add_html . $mat_html);
751  return $errors;
752  }
753 
754  public function deleteMaterial()
755  {
756  if (is_array($_POST['idx']))
757  {
758  $this->object->deleteMaterials($_POST['idx']);
759  ilUtil::sendSuccess($this->lng->txt('materials_deleted'), true);
760  }
761  else
762  {
763  ilUtil::sendFailure($this->lng->txt('no_checkbox'), true);
764  }
765  $this->ctrl->redirect($this, 'material');
766  }
767 
771  public function addMaterial()
772  {
773  global $tree, $ilTabs, $ilToolbar;
774 
775  $ilTabs->activateTab("material");
776 
777  $ilToolbar->addButton($this->lng->txt("cancel"),
778  $this->ctrl->getLinkTarget($this, "material"));
779 
780  if (strlen($_SESSION["link_new_type"]) || !$this->material(true))
781  {
782  include_once("./Modules/SurveyQuestionPool/classes/class.ilMaterialExplorer.php");
783  switch ($_POST["internalLinkType"])
784  {
785  case "lm":
786  $_SESSION["link_new_type"] = "lm";
787  $_SESSION["search_link_type"] = "lm";
788  break;
789  case "glo":
790  $_SESSION["link_new_type"] = "glo";
791  $_SESSION["search_link_type"] = "glo";
792  break;
793  case "st":
794  $_SESSION["link_new_type"] = "lm";
795  $_SESSION["search_link_type"] = "st";
796  break;
797  case "pg":
798  $_SESSION["link_new_type"] = "lm";
799  $_SESSION["search_link_type"] = "pg";
800  break;
801  }
802 
803  $exp = new ilMaterialExplorer($this, 'addMaterial', $_SESSION["link_new_type"]);
804  $exp->setPathOpen((int)$_GET["ref_id"]);
805  if (!$exp->handleCommand())
806  {
807  include_once "Services/UIComponent/Panel/classes/class.ilPanelGUI.php";
808  $panel = ilPanelGUI::getInstance();
809  $panel->setHeading($this->lng->txt("select_object_to_link"));
810  $panel->setBody($exp->getHTML());
811 
812  $this->tpl->setContent($panel->getHTML());
813  }
814  }
815  }
816 
817  function removeMaterial()
818  {
819  $this->object->material = array();
820  $this->object->saveToDb();
821  $this->editQuestion();
822  }
823 
824  function cancelExplorer()
825  {
826  unset($_SESSION["link_new_type"]);
827  ilUtil::sendInfo($this->lng->txt("msg_cancel"), true);
828  $this->ctrl->redirect($this, 'material');
829  }
830 
831  function addPG()
832  {
833  $this->object->addInternalLink("il__pg_" . $_GET["pg"]);
834  unset($_SESSION["link_new_type"]);
835  unset($_SESSION["search_link_type"]);
836  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
837  $this->ctrl->redirect($this, "material");
838  }
839 
840  function addST()
841  {
842  $this->object->addInternalLink("il__st_" . $_GET["st"]);
843  unset($_SESSION["link_new_type"]);
844  unset($_SESSION["search_link_type"]);
845  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
846  $this->ctrl->redirect($this, "material");
847  }
848 
849  function addGIT()
850  {
851  $this->object->addInternalLink("il__git_" . $_GET["git"]);
852  unset($_SESSION["link_new_type"]);
853  unset($_SESSION["search_link_type"]);
854  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
855  $this->ctrl->redirect($this, "material");
856  }
857 
858  function linkChilds()
859  {
860  global $ilTabs;
861 
862  $selectable_items = array();
863 
864  $source_id = $_GET["source_id"];
865 
866  switch ($_SESSION["search_link_type"])
867  {
868  case "pg":
869  include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
870  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
871  $cont_obj_gui =& new ilObjContentObjectGUI("", $source_id, true);
872  $cont_obj = $cont_obj_gui->object;
873  $pages = ilLMPageObject::getPageList($cont_obj->getId());
874  foreach($pages as $page)
875  {
876  if($page["type"] == $_SESSION["search_link_type"])
877  {
878  $selectable_items[] = array(
879  "item_type" => $page["type"]
880  ,"item_id" => $page["obj_id"]
881  ,"title" => $page["title"]
882  );
883  }
884  }
885  break;
886 
887  case "st":
888  include_once("./Modules/LearningModule/classes/class.ilObjContentObjectGUI.php");
889  $cont_obj_gui =& new ilObjContentObjectGUI("", $source_id, true);
890  $cont_obj = $cont_obj_gui->object;
891  // get all chapters
892  $ctree =& $cont_obj->getLMTree();
893  $nodes = $ctree->getSubtree($ctree->getNodeData($ctree->getRootId()));
894  foreach($nodes as $node)
895  {
896  if($node["type"] == $_SESSION["search_link_type"])
897  {
898  $selectable_items[] = array(
899  "item_type" => $node["type"]
900  ,"item_id" => $node["obj_id"]
901  ,"title" => $node["title"]
902  );
903  }
904  }
905  break;
906 
907  case "glo":
908  include_once "./Modules/Glossary/classes/class.ilObjGlossary.php";
909  $glossary =& new ilObjGlossary($source_id, true);
910  // get all glossary items
911  $terms = $glossary->getTermList();
912  foreach($terms as $term)
913  {
914  $selectable_items[] = array(
915  "item_type" => "GIT"
916  ,"item_id" => $term["id"]
917  ,"title" => $term["term"]
918  );
919  }
920  break;
921 
922  case "lm":
923  $this->object->addInternalLink("il__lm_" . $source_id);
924  break;
925  }
926 
927  if(sizeof($selectable_items))
928  {
929  $ilTabs->activateTab("material");
930  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
931  $this->ctrl->setParameter($this, "source_id", $source_id);
932 
933  include_once "Modules/SurveyQuestionPool/classes/tables/class.SurveyMaterialsSourceTableGUI.php";
934  $tbl = new SurveyMaterialsSourceTableGUI($this, "linkChilds", "addMaterial");
935  $tbl->setData($selectable_items);
936  $this->tpl->setContent($tbl->getHTML());
937  }
938  else
939  {
940  if($_SESSION["search_link_type"] == "lm")
941  {
942  ilUtil::sendSuccess($this->lng->txt("material_added_successfully"), true);
943 
944  unset($_SESSION["link_new_type"]);
945  unset($_SESSION["search_link_type"]);
946  $this->ctrl->redirect($this, "material");
947  }
948  else
949  {
950  ilUtil::sendFailure($this->lng->txt("material_added_empty"), true);
951  $this->ctrl->redirect($this, "addMaterial");
952  }
953  }
954  }
955 
956 
957  //
958  // PHRASES (see SurveyMatrixQuestionGUI)
959  //
960 
961  protected function initPhrasesForm()
962  {
963  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
964  $form = new ilPropertyFormGUI();
965  $form->setFormAction($this->ctrl->getFormAction($this, "addSelectedPhrase"));
966  $form->setTitle($this->lng->txt("add_phrase"));
967  // $form->setDescription($this->lng->txt("add_phrase_introduction"));
968 
969  $group = new ilRadioGroupInputGUI($this->lng->txt("phrase"), "phrases");
970  $group->setRequired(true);
971  $form->addItem($group);
972 
973  include_once "./Modules/SurveyQuestionPool/classes/class.ilSurveyPhrases.php";
974  foreach (ilSurveyPhrases::_getAvailablePhrases() as $phrase_id => $phrase_array)
975  {
976  $categories = ilSurveyPhrases::_getCategoriesForPhrase($phrase_id);
977 
978  $opt = new ilRadioOption($phrase_array["title"], $phrase_id);
979  $opt->setInfo(join($categories, ","));
980  $group->addOption($opt);
981 
982  if($phrase_array["org_title"] == "dp_standard_numbers")
983  {
984  $min = new ilNumberInputGUI($this->lng->txt("lower_limit"), "lower_limit");
985  $min->setRequired(true);
986  $min->setSize(5);
987  $opt->addSubItem($min);
988 
989  $max = new ilNumberInputGUI($this->lng->txt("upper_limit"), "upper_limit");
990  $max->setRequired(true);
991  $max->setSize(5);
992  $opt->addSubItem($max);
993  }
994  }
995 
996  $form->addCommandButton("addSelectedPhrase", $this->lng->txt("add_phrase"));
997  $form->addCommandButton("editQuestion", $this->lng->txt("cancel"));
998 
999  return $form;
1000  }
1001 
1005  protected function addPhrase(ilPropertyFormGUI $a_form = null)
1006  {
1007  global $ilTabs;
1008 
1009  $ilTabs->activateTab("edit_properties");
1010 
1011  if(!$a_form)
1012  {
1013  $result = $this->saveForm();
1014  if($result)
1015  {
1016  $this->object->saveToDb();
1017  }
1018 
1019  $a_form = $this->initPhrasesForm();
1020  }
1021 
1022  $this->tpl->setContent($a_form->getHTML());
1023  }
1024 
1025  protected function addSelectedPhrase()
1026  {
1027  $form = $this->initPhrasesForm();
1028  if($form->checkInput())
1029  {
1030  $phrase_id = $form->getInput("phrases");
1031 
1032  $valid = true;
1033  if (strcmp($this->object->getPhrase($phrase_id), "dp_standard_numbers") != 0)
1034  {
1035  $this->object->addPhrase($phrase_id);
1036  }
1037  else
1038  {
1039  $min = $form->getInput("lower_limit");
1040  $max = $form->getInput("upper_limit");
1041 
1042  if($max <= $min)
1043  {
1044  $max_field = $form->getItemByPostVar("upper_limit");
1045  $max_field->setAlert($this->lng->txt("upper_limit_must_be_greater"));
1046  $valid = false;
1047  }
1048  else
1049  {
1050  $this->object->addStandardNumbers($min, $max);
1051  }
1052  }
1053 
1054  if($valid)
1055  {
1056  $this->object->saveToDb();
1057 
1058  ilUtil::sendSuccess($this->lng->txt('phrase_added'), true);
1059  $this->ctrl->redirect($this, 'editQuestion');
1060  }
1061  }
1062 
1063  $form->setValuesByPost();
1064  $this->addPhrase($form);
1065  }
1066 
1072  function savePhrase($a_reload = false)
1073  {
1074  global $ilTabs, $ilToolbar;
1075 
1076  $ilTabs->activateTab("edit_properties");
1077 
1078  if (!$a_reload)
1079  {
1080  $result = $this->saveForm();
1081  if ($result)
1082  {
1083  $this->object->saveToDb();
1084  }
1085  }
1086 
1087  include_once("./Services/Form/classes/class.ilTextInputGUI.php");
1088  $txt = new ilTextInputGUI($this->lng->txt("enter_phrase_title"), "phrase_title");
1089  $ilToolbar->addInputItem($txt, true);
1090  $ilToolbar->addFormButton($this->lng->txt("confirm"), "confirmSavePhrase");
1091  $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
1092 
1093  include_once "./Modules/SurveyQuestionPool/classes/tables/class.ilSurveySavePhraseTableGUI.php";
1094  $table_gui = new ilSurveySavePhraseTableGUI($this, 'editQuestion');
1095  $table_gui->setDescription($this->lng->txt("save_phrase_introduction"));
1096 
1097  // matrix?
1098  if(method_exists($this->object, "getCategories"))
1099  {
1100  $categories = $this->object->getCategories();
1101  }
1102  else
1103  {
1104  $categories = $this->object->getColumns();
1105  }
1106 
1107  $data = array();
1108  for ($i = 0; $i < $categories->getCategoryCount(); $i++)
1109  {
1110  $cat = $categories->getCategory($i);
1111 
1112  $data[] = array(
1113  "answer" => $cat->title,
1114  "other" => $cat->other,
1115  "scale" => $cat->scale,
1116  "neutral" => $cat->neutral
1117  );
1118  }
1119  $table_gui->setData($data);
1120  $_SESSION['save_phrase_data'] = $data; // :TODO: see savePhrase()
1121 
1122  $this->tpl->setContent($table_gui->getHTML());
1123  }
1124 
1130  function confirmSavePhrase()
1131  {
1132  $title = $_POST["phrase_title"];
1133 
1134  $valid = true;
1135  if (!trim($title))
1136  {
1137  ilUtil::sendFailure($this->lng->txt("qpl_savephrase_empty"));
1138  $valid = false;
1139  }
1140  else if ($this->object->phraseExists($title))
1141  {
1142  ilUtil::sendFailure($this->lng->txt("qpl_savephrase_exists"));
1143  $valid = false;
1144  }
1145 
1146  if($valid)
1147  {
1148  $this->object->savePhrase($title);
1149 
1150  ilUtil::sendSuccess($this->lng->txt("phrase_saved"), true);
1151  $this->ctrl->redirect($this, "editQuestion");
1152  }
1153 
1154  $this->savePhrase(true);
1155  }
1156 }
1157 
1158 ?>