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