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