ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilSurveyEditorGUI.php
Go to the documentation of this file.
1<?php
2
21
31{
32 protected \ILIAS\Survey\Sequence\SequenceManager $sequence_manager;
33 protected \ILIAS\Survey\InternalGUIService $gui;
34 protected \ILIAS\Survey\PrintView\GUIService $print;
35 protected \ILIAS\HTTP\Services $http;
36 protected \ILIAS\DI\UIServices $ui;
37 protected string $requested_pgov;
40 protected ilCtrl $ctrl;
41 protected ilLanguage $lng;
43 protected ilTabsGUI $tabs;
44 protected ilHelpGUI $help;
46 protected ilObjUser $user;
47 protected ilTree $tree;
50 protected array $print_options;
51
52 public function __construct(ilObjSurveyGUI $a_parent_gui)
53 {
54 global $DIC;
55
56 $this->tabs = $DIC->tabs();
57 $this->help = $DIC["ilHelp"];
58 $this->toolbar = $DIC->toolbar();
59 $this->user = $DIC->user();
60 $this->tree = $DIC->repositoryTree();
61 $ilCtrl = $DIC->ctrl();
62 $lng = $DIC->language();
63 $tpl = $DIC["tpl"];
64
65 $this->parent_gui = $a_parent_gui;
67 $survey = $this->parent_gui->getObject();
68 $this->object = $survey;
69
70 $this->ctrl = $ilCtrl;
71 $this->lng = $lng;
72 $this->tpl = $tpl;
73
74 $this->ctrl->saveParameter($this, array("pgov", "pgov_pos"));
75
76 $this->print_options = array(
77 //0 => $this->lng->txt('none'),
78 ilObjSurvey::PRINT_HIDE_LABELS => $this->lng->txt('svy_print_hide_labels'),
79 //2 => $this->lng->txt('svy_print_label_only'),
80 ilObjSurvey::PRINT_SHOW_LABELS => $this->lng->txt('svy_print_show_labels')
81 );
82 $this->edit_manager = $DIC->survey()
83 ->internal()
84 ->domain()
85 ->edit();
86 $this->request = $DIC->survey()
87 ->internal()
88 ->gui()
89 ->editing()
90 ->request();
91 $this->requested_pgov = $this->request->getTargetPosition();
92 $this->ui = $DIC->ui();
93 $this->http = $DIC->http();
94 $this->print = $DIC->survey()
95 ->internal()
96 ->gui()
97 ->print();
98 $this->gui = $DIC->survey()
99 ->internal()
100 ->gui();
101 $this->sequence_manager = $DIC->survey()->internal()->domain()->sequence(
102 $this->object->getSurveyId(),
103 $this->object
104 );
105 }
106
107 public function setRequestedPgov(string $pgov): void
108 {
109 $this->requested_pgov = $pgov;
110 }
111
112 public function executeCommand(): void
113 {
114 $ilTabs = $this->tabs;
115
116 $cmd = $this->ctrl->getCmd("questions");
117
118 $next_class = $this->ctrl->getNextClass($this);
119 switch ($next_class) {
120
121 default:
122 // question gui
123 if (stripos($next_class, "questiongui") !== false) {
124 $ilTabs->clearTargets();
125 $this->ctrl->saveParameter($this, array("new_for_survey"));
127 null,
128 $this->request->getQuestionId()
129 );
130 if (is_object($q_gui->object)) {
131 $ilHelp = $this->help;
132 $ilHelp->setScreenIdComponent("spl_qt" . $q_gui->object->getQuestionTypeId());
133 }
134 // $q_gui->object->setObjId($this->object->getId());
135 $q_gui->setBackUrl($this->ctrl->getLinkTarget($this, "questions"));
136 $q_gui->setQuestionTabs();
137 $this->ctrl->forwardCommand($q_gui);
138
139 if (!$this->request->getNewForSurvey()) {
140 // not on create
141 $this->tpl->setTitle($this->lng->txt("question") . ": " . $q_gui->object->getTitle());
142 }
143 } else {
144 $cmd .= "Object";
145 $this->$cmd();
146 }
147 break;
148 }
149 }
150
151 protected function questionsSubtabs(
152 string $a_cmd
153 ): void {
154 $ilTabs = $this->tabs;
155
156 if ($a_cmd === "questions" && $this->requested_pgov !== "") {
157 $a_cmd = "page";
158 }
159
160 $this->ctrl->setParameter($this, "pgov", "");
161 $ilTabs->addSubTab(
162 "questions",
163 $this->lng->txt("survey_question_editor"),
164 $this->ctrl->getLinkTarget($this, "questions")
165 );
166 $this->ctrl->setParameter($this, "pgov", $this->requested_pgov);
167
168 if ($this->object->getSurveyPages()) {
169 if ($a_cmd === "page") {
170 $this->ctrl->setParameterByClass("ilsurveyexecutiongui", "pgov", max(1, $this->request->getPage()));
171 }
172 $this->ctrl->setParameterByClass("ilsurveyexecutiongui", "prvw", 1);
173 $ilTabs->addSubTab(
174 "preview",
175 $this->lng->txt("preview"),
176 $this->ctrl->getLinkTargetByClass(array("ilobjsurveygui", "ilsurveyexecutiongui"), "preview")
177 );
178 }
179
180 $ilTabs->activateSubTab($a_cmd);
181 }
182
183
184 //
185 // QUESTIONS BROWSER INCL. MULTI-ACTIONS
186 //
187
188 public function questionsObject(): void
189 {
190 $ilToolbar = $this->toolbar;
191 $ilUser = $this->user;
192
193 // insert new questions?
194 if ($this->request->getNewId() > 0) {
195 // add a question to the survey previous created in a questionpool
196 $existing = $this->object->getExistingQuestions();
197 if (!in_array($this->request->getNewId(), $existing)) {
198 $inserted = $this->object->insertQuestion($this->request->getNewId());
199 if (!$inserted) {
200 if (!$this->object->isQuestionInSurvey($this->request->getNewId())) {
201 $this->tpl->setOnScreenMessage(
202 'failure',
203 $this->lng->txt("survey_error_insert_incomplete_question")
204 );
205 }
206 } else {
207 // this ensures the status update of the survey, see #36162
208 $this->ctrl->redirect($this, "questions");
209 }
210 }
211 }
212 $this->questionsSubtabs("questions");
213
214 $hasDatasets = ilObjSurvey::_hasDatasets($this->object->getSurveyId());
215 $read_only = $hasDatasets;
216
217 // toolbar
218 if (!$read_only) {
219 $qtypes = array();
220 foreach (ilObjSurveyQuestionPool::_getQuestiontypes() as $translation => $data) {
221 $qtypes[$data["type_tag"]] = $translation;
222 }
223
224 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
225 $types = new ilSelectInputGUI($this->lng->txt("create_new"), "sel_question_types");
226 $types->setOptions($qtypes);
227 $ilToolbar->addStickyItem($types, "");
228
229 $this->gui->button(
230 $this->lng->txt("svy_create_question"),
231 "createQuestion"
232 )->submit()->toToolbar(true);
233
234
235 $cmd = ((int) $ilUser->getPref('svy_insert_type') === 1 ||
236 ($ilUser->getPref('svy_insert_type') ?? '') === '')
237 ? 'browseForQuestions'
238 : 'browseForQuestionblocks';
239
240 $this->gui->button(
241 $this->lng->txt("browse_for_questions"),
242 $this->ctrl->getLinkTarget($this, $cmd)
243 )->toToolbar(true);
244
245 if ($this->object->hasQuestions()) {
246 $ilToolbar->addSeparator();
247 $this->gui->button(
248 $this->lng->txt("add_heading"),
249 $this->ctrl->getLinkTarget($this, "addHeading")
250 )->toToolbar();
251 }
252
253 $ilToolbar->addSeparator();
254 $print_view = $this->print->list($this->object->getRefId());
255 $modal_elements = $print_view->getModalElements(
256 $this->ctrl->getLinkTarget(
257 $this,
258 "printListViewSelection"
259 )
260 );
261 $ilToolbar->addComponent($modal_elements->button);
262 $ilToolbar->addComponent($modal_elements->modal);
263 }
264 $mess = "";
265 if ($hasDatasets) {
267 $mess = $mbox->getHTML();
268 }
269
270 // table gui
271 $table = new ilSurveyQuestionTableGUI(
272 $this,
273 "questions",
274 $this->object,
275 $read_only
276 );
277 $this->tpl->setContent($mess . $table->getHTML());
278 }
279
284 protected function gatherSelectedTableItems(
285 bool $allow_blocks = true,
286 bool $allow_questions = true,
287 bool $allow_headings = false,
288 bool $allow_questions_in_blocks = false
289 ): array {
290 $block_map = array();
291 foreach ($this->object->getSurveyQuestions() as $item) {
292 $block_map[$item["question_id"]] = $item["questionblock_id"];
293 }
294
295 $questions = $blocks = $headings = array();
296 $ids = $this->request->getIds();
297 if (count($ids) > 0) {
298 foreach ($ids as $key) {
299 // questions
300 if ($allow_questions && preg_match("/cb_(\d+)/", $key, $matches)) {
301 if (($allow_questions_in_blocks || !$block_map[$matches[1]]) &&
302 !in_array($block_map[$matches[1]], $blocks)) {
303 $questions[] = $matches[1];
304 }
305 }
306 // blocks
307 if ($allow_blocks && preg_match("/cb_qb_(\d+)/", $key, $matches)) {
308 $blocks[] = $matches[1];
309 }
310 // headings
311 if ($allow_headings && preg_match("/cb_tb_(\d+)/", $key, $matches)) {
312 $headings[] = $matches[1];
313 }
314 }
315 }
316
317 return array("questions" => $questions,
318 "blocks" => $blocks,
319 "headings" => $headings);
320 }
321
322 public function saveObligatoryObject(): void
323 {
324 $req_order = $this->request->getOrder();
325 $req_block_order = $this->request->getBlockOrder();
326 if (count($req_order) > 0) {
327 $position = -1;
328 $order = array();
329 asort($req_order);
330 foreach (array_keys($req_order) as $id) {
331 // block items
332 if (strpos($id, "qb_") === 0) {
333 $block_id = substr($id, 3);
334 $block = $req_block_order[$block_id];
335 asort($block);
336 foreach (array_keys($block) as $question_id) {
337 $position++;
338 $order[$question_id] = $position;
339 }
340 } else {
341 $question_id = substr($id, 2);
342 $position++;
343 $order[$question_id] = $position;
344 }
345 }
346 $this->object->updateOrder($order);
347 }
348
349 $obligatory = $this->request->getObligatory();
350 $this->object->setObligatoryStates($obligatory);
351 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
352 $this->ctrl->redirect($this, "questions");
353 }
354
355 public function unfoldQuestionblockObject(): void
356 {
357 $items = $this->gatherSelectedTableItems(true, false, false, false);
358 if (count($items["blocks"])) {
359 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
360 $this->object->unfoldQuestionblocks($items["blocks"]);
361 } else {
362 $this->tpl->setOnScreenMessage('info', $this->lng->txt("qpl_unfold_select_none"), true);
363 }
364 $this->ctrl->redirect($this, "questions");
365 }
366
367 public function moveQuestionsObject(): void
368 {
369 $items = $this->gatherSelectedTableItems(true, true, false, false);
370
371 $move_questions = $items["questions"];
372 foreach ($items["blocks"] as $block_id) {
373 foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid) {
374 $move_questions[] = $qid;
375 }
376 }
377 if (count($move_questions) === 0) {
378 $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_question_selected_for_move"), true);
379 $this->ctrl->redirect($this, "questions");
380 } else {
381 $this->edit_manager->setMoveSurveyQuestions($this->object->getId(), $move_questions);
382 $this->tpl->setOnScreenMessage('info', $this->lng->txt("select_target_position_for_move_question"));
383 $this->questionsObject();
384 }
385 }
386
387 public function insertQuestionsBeforeObject(): void
388 {
389 $this->insertQuestions(0);
390 }
391
392 public function insertQuestionsAfterObject(): void
393 {
394 $this->insertQuestions(1);
395 }
396
397 protected function insertQuestions(
398 int $insert_mode
399 ): void {
400 $copy = ($this->edit_manager->getQuestionClipboardMode($this->object->getRefId()) === "copy");
401 if ($copy) {
402 $this->copyPasteObject($insert_mode);
403 return;
404 }
405
406 $insert_id = null;
407 $ids = $this->request->getIds();
408 if (count($ids) > 0) {
409 $items = $this->gatherSelectedTableItems(true, true, false, false);
410
411 // we are using POST id for original order
412 while (!$insert_id && count($ids) > 0) {
413 $target = array_shift($ids);
414 if (preg_match("/^cb_(\d+)$/", $target, $matches)) {
415 // questions in blocks are not allowed
416 if (in_array($matches[1], $items["questions"])) {
417 $insert_id = $matches[1];
418 }
419 }
420 if (!$insert_id && preg_match("/^cb_qb_(\d+)$/", $target, $matches)) {
421 $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
422 if (count($ids)) {
423 if ($insert_mode === 0) {
424 $insert_id = $ids[0];
425 } elseif ($insert_mode === 1) {
426 $insert_id = $ids[count($ids) - 1];
427 }
428 }
429 }
430 }
431 }
432 if (!$insert_id) {
433 $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_target_selected_for_move"), true);
434 } else {
435 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
436 if ($this->edit_manager->getMoveSurveyId() === $this->object->getId()) {
437 $this->object->moveQuestions(
438 $this->edit_manager->getMoveSurveyQuestions(),
439 $insert_id,
440 $insert_mode
441 );
442 $this->edit_manager->clearMoveSurveyQuestions();
443 }
444 }
445
446 $this->ctrl->redirect($this, "questions");
447 }
448
449 public function removeQuestionsObject(): void
450 {
451 $items = $this->gatherSelectedTableItems(true, true, true, true);
452 if (count($items["blocks"]) + count($items["questions"]) + count($items["headings"]) > 0) {
453 $this->tpl->setOnScreenMessage('question', $this->lng->txt("remove_questions"));
454 $this->removeQuestionsForm($items["blocks"], $items["questions"], $items["headings"]);
455 } else {
456 $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_question_selected_for_removal"), true);
457 $this->ctrl->redirect($this, "questions");
458 }
459 }
460
461 public function removeQuestionsForm(
462 array $checked_questionblocks,
463 array $checked_questions,
464 array $checked_headings
465 ): void {
466 $cgui = new ilConfirmationGUI();
467 $cgui->setHeaderText($this->lng->txt("survey_sure_delete_questions"));
468 $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
469 $cgui->setCancel($this->lng->txt("cancel"), "questions");
470 $cgui->setConfirm($this->lng->txt("confirm"), "confirmRemoveQuestions");
471 $surveyquestions = $this->object->getSurveyQuestions();
472 foreach ($surveyquestions as $question_id => $data) {
473 if (in_array($data["question_id"], $checked_questions)) {
474 $type = SurveyQuestion::_getQuestionTypeName($data["type_tag"]);
475
476 $cgui->addItem(
477 "q_id[]",
478 $data["question_id"],
479 $type . ": " . $data["title"]
480 );
481 } elseif ((in_array($data["questionblock_id"], $checked_questionblocks))) {
482 $type = SurveyQuestion::_getQuestionTypeName($data["type_tag"]);
483
484 $cgui->addItem(
485 "cb[" . $data["questionblock_id"] . "]",
486 $data["questionblock_id"],
487 $data["questionblock_title"] . " - " . $type . ": " . $data["title"]
488 );
489 } elseif (in_array($data["question_id"], $checked_headings)) {
490 $cgui->addItem(
491 "heading[" . $data["question_id"] . "]",
492 $data["question_id"],
493 $data["heading"]
494 );
495 }
496 }
497
498 $this->tpl->setContent($cgui->getHTML());
499 }
500
501 public function confirmRemoveQuestionsObject(): void
502 {
503 $checked_questions = $this->request->getQuestionIds();
504 $checked_questionblocks = $this->request->getBlockIds();
505 $checked_headings = $this->request->getHeadings();
506
507 if (count($checked_questions) || count($checked_questionblocks)) {
508 $this->object->removeQuestions($checked_questions, $checked_questionblocks);
509 }
510 if ($checked_headings) {
511 foreach ($checked_headings as $q_id) {
512 $this->object->saveHeading("", $q_id);
513 }
514 }
515 $this->object->saveCompletionStatus();
516 $this->tpl->setOnScreenMessage('success', $this->lng->txt("questions_removed"), true);
517 $this->ctrl->redirect($this, "questions");
518 }
519
520 public function copyQuestionsToPoolObject(): void
521 {
522 $items = $this->gatherSelectedTableItems(true, true, false, true);
523
524 // gather questions from blocks
525 $copy_questions = $items["questions"];
526 foreach ($items["blocks"] as $block_id) {
527 foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid) {
528 $copy_questions[] = $qid;
529 }
530 }
531 $copy_questions = array_unique($copy_questions);
532
533 // only if not already in pool
534 if (count($copy_questions)) {
535 foreach ($copy_questions as $idx => $question_id) {
536 $question = ilObjSurvey::_instanciateQuestion($question_id);
537 if ($question->getOriginalId()) {
538 unset($copy_questions[$idx]);
539 }
540 }
541 }
542 if (count($copy_questions) === 0) {
543 $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_question_selected_for_copy_to_pool"), true);
544 $this->ctrl->redirect($this, "questions");
545 } else {
546 $this->questionsSubtabs("questions");
547
548 $form = new ilPropertyFormGUI();
549
550 $form->setFormAction($this->ctrl->getFormAction($this, "executeCreateQuestion"));
551
552 $ids = new ilHiddenInputGUI("question_ids");
553 $ids->setValue(implode(";", $copy_questions));
554 $form->addItem($ids);
555
556 $questionpools = $this->object->getAvailableQuestionpools(false, false, true, "write");
557 $pools = new ilSelectInputGUI($this->lng->txt("survey_copy_select_questionpool"), "sel_spl");
558 $pools->setOptions($questionpools);
559 $form->addItem($pools);
560
561 $form->addCommandButton("executeCopyQuestionsToPool", $this->lng->txt("submit"));
562 $form->addCommandButton("questions", $this->lng->txt("cancel"));
563
564 $this->tpl->setContent($form->getHTML());
565 }
566 }
567
568 public function executeCopyQuestionsToPoolObject(): void
569 {
570 $question_ids = $this->request->getQuestionIdsFromString();
571 $pool_id = ilObject::_lookupObjId($this->request->getSelectedPool());
572
573 foreach ($question_ids as $qid) {
574 // create copy (== pool "original")
575 $new_question = ilObjSurvey::_instanciateQuestion($qid);
576 $new_question->setId();
577 $new_question->setObjId($pool_id);
578 $new_question->saveToDb();
579
580 // link "source" (survey) to copy (pool)
581 SurveyQuestion::_changeOriginalId($qid, $new_question->getId(), $pool_id);
582 }
583
584 $this->tpl->setOnScreenMessage('success', $this->lng->txt("survey_copy_to_questionpool_success"), true);
585 $this->ctrl->redirect($this, "questions");
586 }
587
588
589 //
590 // QUESTION CREATION
591 //
592
593 public function createQuestionObject(
594 ?ilPropertyFormGUI $a_form = null,
595 $sel_question_types = null,
596 ?string $pgov_pos = null
598 $this->executeCreateQuestionObject(null, 1, $pgov_pos);
599 }
600
602 ?string $q_type = null,
603 ?int $pool_usage = null,
604 ?string $pgov_pos = null
605 ): void {
606 $this->edit_manager->setPoolChoice($this->request->getPoolUsage());
607
608 if (is_null($q_type)) {
609 $q_type = $this->request->getSelectedQuestionTypes();
610 }
611
612 $pgov = $this->requested_pgov;
613 if (is_null($pgov_pos)) {
614 $pgov_pos = $this->request->getTargetQuestionPosition();
615 }
616
617 if (is_null($pool_usage)) {
618 $pool_usage = $this->request->getPoolUsage();
619 }
620 $pool_usage = 1;
621
622 $obj_id = 0;
623 $obj_id = $this->object->getId();
624
625 // create question and redirect to question form
626
627 $q_gui = SurveyQuestionGUI::_getQuestionGUI($q_type);
628 $q_gui->object->setObjId($obj_id); // survey/pool!
629 $q_gui->object->createNewQuestion();
630 $q_gui_class = get_class($q_gui);
631
632 if ($pgov !== "") {
633 $this->ctrl->setParameterByClass($q_gui_class, "pgov", $pgov);
634 $this->ctrl->setParameterByClass($q_gui_class, "pgov_pos", $pgov_pos);
635 }
636
637 $this->ctrl->setParameterByClass($q_gui_class, "ref_id", $this->object->getRefId());
638 $this->ctrl->setParameterByClass($q_gui_class, "new_for_survey", $this->object->getRefId());
639 $this->ctrl->setParameterByClass($q_gui_class, "q_id", $q_gui->object->getId());
640 $this->ctrl->setParameterByClass($q_gui_class, "sel_question_types", $q_gui->getQuestionType());
641 $this->ctrl->redirectByClass($q_gui_class, "editQuestion");
642 }
643
644 protected function createQuestionPool($name = "dummy"): int
645 {
646 $tree = $this->tree;
647
648 $parent_ref = $tree->getParentId($this->object->getRefId());
649
650 $qpl = new ilObjSurveyQuestionPool();
651 $qpl->setType("spl");
652 $qpl->setTitle($name);
653 $qpl->setDescription("");
654 $qpl->create();
655 $qpl->createReference();
656 $qpl->putInTree($parent_ref);
657 $qpl->setPermissions($parent_ref);
658 $qpl->setOnline(1); // must be online to be available
659 $qpl->saveToDb();
660
661 return $qpl->getId();
662 }
663
664
665 //
666 // ADD FROM POOL
667 //
668
669 protected function setBrowseForQuestionsSubtabs(): void
670 {
671 $ilTabs = $this->tabs;
672 $ilToolbar = $this->toolbar;
673 $ilUser = $this->user;
674
675 $link = $this->ctrl->getLinkTarget($this, "questions");
676 $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $link);
677
678 // type selector
679 $types = new ilSelectInputGUI($this->lng->txt("display_all_available"), "datatype");
680 $types->setOptions(array(
681 1 => $this->lng->txt("questions"),
682 2 => $this->lng->txt("questionblocks")
683 ));
684 $types->setValue($ilUser->getPref('svy_insert_type'));
685 $ilToolbar->addInputItem($types, true);
686 $ilToolbar->addFormButton($this->lng->txt("change"), "changeDatatype");
687 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "changeDatatype"));
688 }
689
690 public function changeDatatypeObject(): void
691 {
692 $ilUser = $this->user;
693
694 $ilUser->writePref('svy_insert_type', $this->request->getDataType());
695
696 switch ($this->request->getDataType()) {
697 case 2:
698 $this->ctrl->redirect($this, 'browseForQuestionblocks');
699 break;
700
701 case 1:
702 default:
703 $this->ctrl->redirect($this, 'browseForQuestions');
704 break;
705 }
706 }
707
708 public function browseForQuestionsObject(): void
709 {
710 $this->setBrowseForQuestionsSubtabs();
711
712 $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', $this->object, true);
713 $table_gui->setEditable(true);
714 $this->tpl->setContent($table_gui->getHTML());
715 }
716
717 public function filterQuestionBrowserObject(): void
718 {
719 $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', $this->object);
720 $table_gui->writeFilterToSession();
721 $this->ctrl->redirect($this, 'browseForQuestions');
722 }
723
724 public function resetfilterQuestionBrowserObject(): void
725 {
726 $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', $this->object);
727 $table_gui->resetFilter();
728 $this->ctrl->redirect($this, 'browseForQuestions');
729 }
730
731 public function insertQuestionsObject(): void
732 {
733 $inserted_objects = 0;
734 $page_gui = null;
735 $qids = $this->request->getQuestionIds();
736 if (count($qids) > 0) {
737 foreach ($qids as $question_id) {
738 if ($this->requested_pgov === "") {
739 $this->object->insertQuestion($question_id);
740 } else {
741 // "pgov" must be set to 1 to land here
742 // target position in page (pgov_pos) is processed there
743 $page_gui->insertNewQuestion($question_id);
744 }
745 $inserted_objects++;
746 }
747 }
748 if ($inserted_objects) {
749 $this->object->saveCompletionStatus();
750 $this->tpl->setOnScreenMessage('success', $this->lng->txt("questions_inserted"), true);
751 $this->ctrl->redirect($this, "questions");
752 } else {
753 $this->tpl->setOnScreenMessage('info', $this->lng->txt("insert_missing_question"), true);
754 $this->ctrl->redirect($this, 'browseForQuestions');
755 }
756 }
757
758 public function browseForQuestionblocksObject(): void
759 {
760 $this->setBrowseForQuestionsSubtabs();
761
762 $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', $this->object, true);
763 $table_gui->setEditable(true);
764 $this->tpl->setContent($table_gui->getHTML());
765 }
766
767 public function filterQuestionblockBrowserObject(): void
768 {
769 $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', $this->object);
770 $table_gui->writeFilterToSession();
771 $this->ctrl->redirect($this, 'browseForQuestionblocks');
772 }
773
775 {
776 $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', $this->object);
777 $table_gui->resetFilter();
778 $this->ctrl->redirect($this, 'browseForQuestionblocks');
779 }
780
781 public function insertQuestionblocksObject(): void
782 {
783 $inserted_objects = 0;
784 $page_gui = null;
785 $block_ids = $this->request->getBlockIds();
786 if (count($block_ids) > 0) {
787 foreach ($block_ids as $questionblock_id) {
788 if ($this->requested_pgov === "") {
789 $this->object->insertQuestionblock($questionblock_id);
790 } else {
791 $page_gui->insertQuestionBlock($questionblock_id);
792 }
793 $inserted_objects++;
794 }
795 }
796 if ($inserted_objects) {
797 $this->object->saveCompletionStatus();
798 $this->tpl->setOnScreenMessage('success', ($inserted_objects === 1) ? $this->lng->txt("questionblock_inserted") : $this->lng->txt("questionblocks_inserted"), true);
799 $this->ctrl->redirect($this, "questions");
800 } else {
801 $this->tpl->setOnScreenMessage('info', $this->lng->txt("insert_missing_questionblock"), true);
802 $this->ctrl->redirect($this, 'browseForQuestionblocks');
803 }
804 }
805
806
807 //
808 // BLOCKS
809 //
810
811 public function editQuestionblockObject(
812 ?ilPropertyFormGUI $a_form = null
813 ): void {
814 $block_id = $this->request->getBlockId();
815 $this->ctrl->setParameter($this, "bl_id", $block_id);
816
817 if (!$a_form) {
818 $a_form = $this->initQuestionblockForm($block_id);
819 }
820
821 $this->questionsSubtabs("questions");
822 $this->tpl->setContent($a_form->getHTML());
823 }
824
826 ?ilPropertyFormGUI $a_form = null
827 ): void {
828 if (!$a_form) {
829 // gather questions from table selected
830 $items = $this->gatherSelectedTableItems(false, true, false, false);
831
832 $qids = $this->request->getQuestionIds();
833 if (count($qids) > 0) {
834 $items["questions"] = $qids;
835 }
836 if (count($items["questions"]) < 2) {
837 $this->tpl->setOnScreenMessage('info', $this->lng->txt("qpl_define_questionblock_select_missing"), true);
838 $this->ctrl->redirect($this, "questions");
839 }
840
841 $a_form = $this->initQuestionblockForm(null, $items["questions"]);
842 }
843
844 $this->questionsSubtabs("questions");
845 $this->tpl->setContent($a_form->getHTML());
846 }
847
848 protected function initQuestionblockForm(
849 ?int $a_block_id = null,
850 ?array $a_question_ids = null
852 $questionblock = null;
853 $form = new ilPropertyFormGUI();
854 $form->setFormAction($this->ctrl->getFormAction($this, "saveDefineQuestionblock"));
855 $form->setTitle($this->lng->txt("define_questionblock"));
856
857 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
858 $title->setRequired(true);
859 $form->addItem($title);
860
861 $toggle_blocktitle = new ilCheckboxInputGUI($this->lng->txt("survey_show_blocktitle"), "show_blocktitle");
862 $toggle_blocktitle->setInfo($this->lng->txt("survey_show_blocktitle_description"));
863 $form->addItem($toggle_blocktitle);
864
865 $toggle_questiontitle = new ilCheckboxInputGUI($this->lng->txt("show_questiontext"), "show_questiontext");
866 $toggle_questiontitle->setInfo($this->lng->txt("show_questiontext_description"));
867 $form->addItem($toggle_questiontitle);
868
869 if ($a_block_id) {
870 $questionblock = ilObjSurvey::_getQuestionblock($a_block_id);
871 $title->setValue($questionblock["title"]);
872 $toggle_blocktitle->setChecked((bool) $questionblock["show_blocktitle"]);
873 $toggle_questiontitle->setChecked((bool) $questionblock["show_questiontext"]);
874 } else {
875 $toggle_blocktitle->setChecked(true);
876 $toggle_questiontitle->setChecked(true);
877 }
878
879 $compress_view = new ilCheckboxInputGUI($this->lng->txt("svy_compress_view"), "compress_view");
880 $compress_view->setInfo($this->lng->txt("svy_compress_view_info"));
881 $compress_view->setChecked((bool) ($questionblock["compress_view"] ?? false));
882 $form->addItem($compress_view);
883
884 $form->addCommandButton("saveDefineQuestionblock", $this->lng->txt("save"));
885 $form->addCommandButton("questions", $this->lng->txt("cancel"));
886
887 // reload?
888 $qids = $this->request->getQuestionIds();
889 if (!$a_question_ids && count($qids) > 0) {
890 $a_question_ids = $qids;
891 }
892
893 if ($a_question_ids) {
894 foreach ($a_question_ids as $q_id) {
895 $hidden = new ilHiddenInputGUI("qids[]");
896 $hidden->setValue($q_id);
897 $form->addItem($hidden);
898 }
899 }
900
901 return $form;
902 }
903
904 public function saveDefineQuestionblockObject(): void
905 {
906 $block_id = $this->request->getBlockId();
907 $q_ids = $this->request->getQuestionIds();
908
909 $this->ctrl->setParameter($this, "bl_id", $block_id);
910
911 if (!$block_id && count($q_ids) === 0) {
912 $this->ctrl->redirect($this, "questions");
913 }
914
915 $form = $this->initQuestionblockForm($block_id);
916 if ($form->checkInput()) {
917 $title = $form->getInput("title");
918 $show_questiontext = $form->getInput("show_questiontext");
919 $show_blocktitle = $form->getInput("show_blocktitle") ;
920 $compress_view = $form->getInput("compress_view") ;
921 if ($block_id) {
922 $this->object->modifyQuestionblock(
923 $block_id,
924 $title,
925 $show_questiontext,
926 $show_blocktitle,
927 $compress_view
928 );
929 } elseif ($q_ids) {
930 $this->object->createQuestionblock(
931 $title,
932 $show_questiontext,
933 $show_blocktitle,
934 $q_ids,
935 $compress_view
936 );
937 }
938
939 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
940 $this->ctrl->redirect($this, "questions");
941 }
942
943 $form->setValuesByPost();
944 $this->editQuestionblockObject($form);
945 }
946
947
948 //
949 // HEADING
950 //
951
952 protected function initHeadingForm(
953 ?int $a_question_id = null
955 $survey_questions = $this->object->getSurveyQuestions();
956
957 $form = new ilPropertyFormGUI();
958 $form->setFormAction($this->ctrl->getFormAction($this, ""));
959
960 // heading
961 $heading = new ilTextAreaInputGUI($this->lng->txt("heading"), "heading");
962 $heading->setRows(10);
963 $heading->setCols(80);
964 $heading->setRequired(true);
965 $form->addItem($heading);
966
967 $insertbefore = new ilSelectInputGUI($this->lng->txt("insert"), "insertbefore");
968 $options = array();
969 foreach ($survey_questions as $key => $value) {
970 $options[$key] = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
971 }
972 $insertbefore->setOptions($options);
973 $insertbefore->setRequired(true);
974 $form->addItem($insertbefore);
975
976 $form->addCommandButton("saveHeading", $this->lng->txt("save"));
977 $form->addCommandButton("questions", $this->lng->txt("cancel"));
978
979 if ($a_question_id) {
980 $form->setTitle($this->lng->txt("edit_heading"));
981
982 $heading->setValue($this->object->prepareTextareaOutput($survey_questions[$a_question_id]["heading"] ?? ""));
983 $insertbefore->setValue($a_question_id);
984 $insertbefore->setDisabled(true);
985 } else {
986 $form->setTitle($this->lng->txt("add_heading"));
987 }
988
989 return $form;
990 }
991
992 public function addHeadingObject(
993 ?ilPropertyFormGUI $a_form = null
994 ): void {
995 $q_id = $this->request->getQuestionId();
996 $this->ctrl->setParameter($this, "q_id", $q_id);
997
998 $this->questionsSubtabs("questions");
999
1000 if (!$a_form) {
1001 $a_form = $this->initHeadingForm($q_id);
1002 }
1003
1004 $this->tpl->setContent($a_form->getHTML());
1005 }
1006
1007 public function editHeadingObject(
1008 ?ilPropertyFormGUI $a_form = null
1009 ): void {
1010 $q_id = $this->request->getQuestionId();
1011 $this->ctrl->setParameter($this, "q_id", $q_id);
1012
1013 $this->questionsSubtabs("questions");
1014
1015 if (!$a_form) {
1016 $a_form = $this->initHeadingForm($q_id);
1017 }
1018
1019 $this->tpl->setContent($a_form->getHTML());
1020 }
1021
1022 public function saveHeadingObject(): void
1023 {
1024 // #15474
1025 $q_id = $this->request->getQuestionId();
1026 $this->ctrl->setParameter($this, "q_id", $q_id);
1027
1028 $form = $this->initHeadingForm($q_id);
1029 if ($form->checkInput()) {
1030 $purifier = new ilSvyStandardPurifier();
1031 $heading = $form->getInput("heading");
1032
1033 $heading = $purifier->purify($heading);
1034
1035 $this->object->saveHeading($heading, $form->getInput("insertbefore"));
1036 $this->ctrl->redirect($this, "questions");
1037 }
1038
1039 $form->setValuesByPost();
1040 $this->addHeadingObject($form);
1041 }
1042
1043 public function removeHeadingObject(): void
1044 {
1045 $q_id = $this->request->getQuestionId();
1046 $this->ctrl->setParameter($this, "q_id", $q_id);
1047
1048 if (!$q_id) {
1049 $this->ctrl->redirect($this, "questions");
1050 }
1051
1052 $this->questionsSubtabs("questions");
1053
1054 $cgui = new ilConfirmationGUI();
1055 $cgui->setHeaderText($this->lng->txt("confirm_remove_heading"));
1056
1057 $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmedRemoveHeading"));
1058 $cgui->setCancel($this->lng->txt("cancel"), "questions");
1059 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedRemoveHeading");
1060
1061 $this->tpl->setContent($cgui->getHTML());
1062 }
1063
1064 public function confirmedRemoveHeadingObject(): void
1065 {
1066 $q_id = $this->request->getQuestionId();
1067 if (!$q_id) {
1068 $this->ctrl->redirect($this, "questions");
1069 }
1070
1071 $this->object->saveHeading("", $q_id);
1072 $this->ctrl->redirect($this, "questions");
1073 }
1074
1075 public function printViewObject(): void
1076 {
1077 $print_view = $this->print->page($this->object->getRefId());
1078 $print_view->sendPrintView();
1079 }
1080
1081 public function printListViewSelectionObject(): void
1082 {
1083 $view = $this->print->list($this->object->getRefId());
1084 $view->sendForm();
1085 }
1086
1087 public function printListViewObject(): void
1088 {
1089 $print_view = $this->print->list($this->object->getRefId());
1090 $print_view->sendPrintView();
1091 }
1092
1093 protected function copyQuestionObject(): void
1094 {
1095 $id = $this->request->getQuestionId();
1096 $lng = $this->lng;
1097 $this->tpl->setOnScreenMessage('success', $lng->txt("survey_questions_to_clipboard_copy"), true);
1098 //$this->suppress_clipboard_msg = true;
1099
1100 $this->edit_manager->setQuestionClipboard(
1101 $this->object->getRefId(),
1102 0,
1103 "copy",
1104 [$id]
1105 );
1106 $this->ctrl->redirect($this, "questions");
1107 }
1108
1113 protected function copyPasteObject($pos = 0): void
1114 {
1115 $a_id = null;
1116 $ids = $this->request->getIds();
1117 if (count($ids) > 0) {
1118 if (substr($ids[0], 0, 3) == "cb_") {
1119 $a_id = (int) substr($ids[0], 3);
1120 }
1121 }
1122 if (is_null($a_id)) {
1123 return;
1124 }
1125
1126 $qids = $this->edit_manager->getQuestionClipboardQuestions($this->object->getRefId());
1127 $mode = $this->edit_manager->getQuestionClipboardMode($this->object->getRefId());
1128 $pages = $this->object->getSurveyPages();
1129 $target = null;
1130 foreach ($pages as $page) {
1131 foreach ($page as $question) {
1132 if ($question["question_id"] === $a_id) {
1133 $target = $page;
1134 }
1135 }
1136 }
1137 if (is_null($target)) {
1138 return;
1139 }
1140
1141 if ($mode !== "copy") {
1142 return;
1143 }
1144
1145 $titles = array();
1146 foreach ($this->object->getSurveyPages() as $page) {
1147 foreach ($page as $question) {
1148 $titles[] = $question["title"];
1149 }
1150 }
1151
1152 // copy questions
1153 $question_pointer = array();
1154 foreach ($qids as $qid) {
1155 // create new questions
1156 $question = ilObjSurvey::_instanciateQuestion($qid);
1157
1158 // handle exisiting copies
1159 $title = $question->getTitle();
1160 $max = 0;
1161 foreach ($titles as $existing_title) {
1162 #21278 preg_quote with delimiter
1163 if (preg_match("/" . preg_quote($title, "/") . " \‍(([0-9]+)\‍)$/", $existing_title, $match)) {
1164 $max = max($match[1], $max);
1165 }
1166 }
1167 if ($max) {
1168 $title .= " (" . ($max + 1) . ")";
1169 } else {
1170 $title .= " (2)";
1171 }
1172 $titles[] = $title;
1173 $question->setTitle($title);
1174
1175 $question->id = -1;
1176 $question->saveToDb(); // this creates the copy
1177
1178 $question_pointer[$qid] = $question->getId();
1179 $this->sequence_manager->appendQuestion($question->getId(), false);
1180 }
1181
1182 // copy textblocks
1183 $this->object->cloneTextblocks($question_pointer);
1184
1185 $this->object->loadQuestionsFromDb();
1186
1187 $nodes = array_values($question_pointer);
1188
1189
1190 // paste
1191
1192 // create new block
1193 if (count($target) === 1) {
1194 $this->object->moveQuestions($nodes, $a_id, $pos);
1195 }
1196 // add to existing block
1197 else {
1198 $target_block_id = $target;
1199 $target_block_id = array_shift($target_block_id);
1200 $target_block_id = $target_block_id["questionblock_id"];
1201
1202 foreach ($nodes as $qid) {
1203 $this->object->addQuestionToBlock($qid, $target_block_id);
1204 }
1205
1206 // move to new position
1207 $this->object->moveQuestions($nodes, $a_id, $pos);
1208 }
1209
1210 $this->clearClipboard();
1211 $this->ctrl->redirect($this, "questions");
1212 }
1213
1214 protected function clearClipboard(): void
1215 {
1216 $this->edit_manager->clearQuestionClipboard($this->object->getRefId());
1217 }
1218
1219 public function getAutoBlockTitle(): string
1220 {
1221 $lng = $this->lng;
1222 return $lng->txt("survey_auto_block_title");
1223 }
1224
1225}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _getQuestionGUI(?string $questiontype, int $question_id=-1)
Creates a question gui representation.
static _getQuestionTypeName(string $type_tag)
Return the translation for a given question type.
static _changeOriginalId(int $a_question_id, int $a_original_id, int $a_object_id)
Change original id of existing question in db.
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...
setHeaderText(string $a_headertext)
Class ilCtrl provides processing control methods.
Help GUI class.
setScreenIdComponent(string $a_comp)
This class represents a hidden form property in a property form.
language handling
@ilCtrl_Calls ilObjSurveyGUI: ilSurveyEvaluationGUI, ilSurveyExecutionGUI @ilCtrl_Calls ilObjSurveyGU...
Class ilObjSurveyQuestionPool.
static _getQuestiontypes()
Get all available question types.
static _getQuestionblock(int $questionblock_id)
get question block properties
static _hasDatasets(int $survey_id)
static _instanciateQuestion(int $question_id)
Creates an instance of a question with a given question id.
User class.
static _lookupObjId(int $ref_id)
This class represents a property form user interface.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilSurveyEditorGUI.
copyPasteObject($pos=0)
Paste from clipboard.
gatherSelectedTableItems(bool $allow_blocks=true, bool $allow_questions=true, bool $allow_headings=false, bool $allow_questions_in_blocks=false)
Gather (and filter) selected items from table gui.
createQuestionObject(?ilPropertyFormGUI $a_form=null, $sel_question_types=null, ?string $pgov_pos=null)
ILIAS Survey InternalGUIService $gui
executeCreateQuestionObject(?string $q_type=null, ?int $pool_usage=null, ?string $pgov_pos=null)
ILIAS HTTP Services $http
createQuestionblockObject(?ilPropertyFormGUI $a_form=null)
addHeadingObject(?ilPropertyFormGUI $a_form=null)
ilGlobalTemplateInterface $tpl
removeQuestionsForm(array $checked_questionblocks, array $checked_questions, array $checked_headings)
initQuestionblockForm(?int $a_block_id=null, ?array $a_question_ids=null)
insertQuestions(int $insert_mode)
ILIAS Survey Sequence SequenceManager $sequence_manager
EditingGUIRequest $request
createQuestionPool($name="dummy")
editHeadingObject(?ilPropertyFormGUI $a_form=null)
ILIAS Survey PrintView GUIService $print
editQuestionblockObject(?ilPropertyFormGUI $a_form=null)
ILIAS DI UIServices $ui
initHeadingForm(?int $a_question_id=null)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
getParentId(int $a_node_id)
get parent id of given node
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26