ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $this->tpl->setOnScreenMessage('failure', $this->lng->txt("survey_error_insert_incomplete_question"));
201 } else {
202 // this ensures the status update of the survey, see #36162
203 $this->ctrl->redirect($this, "questions");
204 }
205 }
206 }
207 $this->questionsSubtabs("questions");
208
209 $hasDatasets = ilObjSurvey::_hasDatasets($this->object->getSurveyId());
210 $read_only = $hasDatasets;
211
212 // toolbar
213 if (!$read_only) {
214 $qtypes = array();
215 foreach (ilObjSurveyQuestionPool::_getQuestiontypes() as $translation => $data) {
216 $qtypes[$data["type_tag"]] = $translation;
217 }
218
219 $ilToolbar->setFormAction($this->ctrl->getFormAction($this));
220 $types = new ilSelectInputGUI($this->lng->txt("create_new"), "sel_question_types");
221 $types->setOptions($qtypes);
222 $ilToolbar->addStickyItem($types, "");
223
224 $this->gui->button(
225 $this->lng->txt("svy_create_question"),
226 "createQuestion"
227 )->submit()->toToolbar(true);
228
229
230 $cmd = ((int) $ilUser->getPref('svy_insert_type') === 1 ||
231 ($ilUser->getPref('svy_insert_type') ?? '') === '')
232 ? 'browseForQuestions'
233 : 'browseForQuestionblocks';
234
235 $this->gui->button(
236 $this->lng->txt("browse_for_questions"),
237 $this->ctrl->getLinkTarget($this, $cmd)
238 )->toToolbar(true);
239
240 if ($this->object->hasQuestions()) {
241 $ilToolbar->addSeparator();
242 $this->gui->button(
243 $this->lng->txt("add_heading"),
244 $this->ctrl->getLinkTarget($this, "addHeading")
245 )->toToolbar();
246 }
247
248 $ilToolbar->addSeparator();
249 $print_view = $this->print->list($this->object->getRefId());
250 $modal_elements = $print_view->getModalElements(
251 $this->ctrl->getLinkTarget(
252 $this,
253 "printListViewSelection"
254 )
255 );
256 $ilToolbar->addComponent($modal_elements->button);
257 $ilToolbar->addComponent($modal_elements->modal);
258 }
259 $mess = "";
260 if ($hasDatasets) {
262 $mess = $mbox->getHTML();
263 }
264
265 // table gui
266 $table = new ilSurveyQuestionTableGUI(
267 $this,
268 "questions",
269 $this->object,
270 $read_only
271 );
272 $this->tpl->setContent($mess . $table->getHTML());
273 }
274
279 protected function gatherSelectedTableItems(
280 bool $allow_blocks = true,
281 bool $allow_questions = true,
282 bool $allow_headings = false,
283 bool $allow_questions_in_blocks = false
284 ): array {
285 $block_map = array();
286 foreach ($this->object->getSurveyQuestions() as $item) {
287 $block_map[$item["question_id"]] = $item["questionblock_id"];
288 }
289
290 $questions = $blocks = $headings = array();
291 $ids = $this->request->getIds();
292 if (count($ids) > 0) {
293 foreach ($ids as $key) {
294 // questions
295 if ($allow_questions && preg_match("/cb_(\d+)/", $key, $matches)) {
296 if (($allow_questions_in_blocks || !$block_map[$matches[1]]) &&
297 !in_array($block_map[$matches[1]], $blocks)) {
298 $questions[] = $matches[1];
299 }
300 }
301 // blocks
302 if ($allow_blocks && preg_match("/cb_qb_(\d+)/", $key, $matches)) {
303 $blocks[] = $matches[1];
304 }
305 // headings
306 if ($allow_headings && preg_match("/cb_tb_(\d+)/", $key, $matches)) {
307 $headings[] = $matches[1];
308 }
309 }
310 }
311
312 return array("questions" => $questions,
313 "blocks" => $blocks,
314 "headings" => $headings);
315 }
316
317 public function saveObligatoryObject(): void
318 {
319 $req_order = $this->request->getOrder();
320 $req_block_order = $this->request->getBlockOrder();
321 if (count($req_order) > 0) {
322 $position = -1;
323 $order = array();
324 asort($req_order);
325 foreach (array_keys($req_order) as $id) {
326 // block items
327 if (strpos($id, "qb_") === 0) {
328 $block_id = substr($id, 3);
329 $block = $req_block_order[$block_id];
330 asort($block);
331 foreach (array_keys($block) as $question_id) {
332 $position++;
333 $order[$question_id] = $position;
334 }
335 } else {
336 $question_id = substr($id, 2);
337 $position++;
338 $order[$question_id] = $position;
339 }
340 }
341 $this->object->updateOrder($order);
342 }
343
344 $obligatory = $this->request->getObligatory();
345 $this->object->setObligatoryStates($obligatory);
346 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
347 $this->ctrl->redirect($this, "questions");
348 }
349
350 public function unfoldQuestionblockObject(): void
351 {
352 $items = $this->gatherSelectedTableItems(true, false, false, false);
353 if (count($items["blocks"])) {
354 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
355 $this->object->unfoldQuestionblocks($items["blocks"]);
356 } else {
357 $this->tpl->setOnScreenMessage('info', $this->lng->txt("qpl_unfold_select_none"), true);
358 }
359 $this->ctrl->redirect($this, "questions");
360 }
361
362 public function moveQuestionsObject(): void
363 {
364 $items = $this->gatherSelectedTableItems(true, true, false, false);
365
366 $move_questions = $items["questions"];
367 foreach ($items["blocks"] as $block_id) {
368 foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid) {
369 $move_questions[] = $qid;
370 }
371 }
372 if (count($move_questions) === 0) {
373 $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_question_selected_for_move"), true);
374 $this->ctrl->redirect($this, "questions");
375 } else {
376 $this->edit_manager->setMoveSurveyQuestions($this->object->getId(), $move_questions);
377 $this->tpl->setOnScreenMessage('info', $this->lng->txt("select_target_position_for_move_question"));
378 $this->questionsObject();
379 }
380 }
381
382 public function insertQuestionsBeforeObject(): void
383 {
384 $this->insertQuestions(0);
385 }
386
387 public function insertQuestionsAfterObject(): void
388 {
389 $this->insertQuestions(1);
390 }
391
392 protected function insertQuestions(
393 int $insert_mode
394 ): void {
395 $copy = ($this->edit_manager->getQuestionClipboardMode($this->object->getRefId()) === "copy");
396 if ($copy) {
397 $this->copyPasteObject($insert_mode);
398 return;
399 }
400
401 $insert_id = null;
402 $ids = $this->request->getIds();
403 if (count($ids) > 0) {
404 $items = $this->gatherSelectedTableItems(true, true, false, false);
405
406 // we are using POST id for original order
407 while (!$insert_id && count($ids) > 0) {
408 $target = array_shift($ids);
409 if (preg_match("/^cb_(\d+)$/", $target, $matches)) {
410 // questions in blocks are not allowed
411 if (in_array($matches[1], $items["questions"])) {
412 $insert_id = $matches[1];
413 }
414 }
415 if (!$insert_id && preg_match("/^cb_qb_(\d+)$/", $target, $matches)) {
416 $ids = $this->object->getQuestionblockQuestionIds($matches[1]);
417 if (count($ids)) {
418 if ($insert_mode === 0) {
419 $insert_id = $ids[0];
420 } elseif ($insert_mode === 1) {
421 $insert_id = $ids[count($ids) - 1];
422 }
423 }
424 }
425 }
426 }
427 if (!$insert_id) {
428 $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_target_selected_for_move"), true);
429 } else {
430 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
431 if ($this->edit_manager->getMoveSurveyId() === $this->object->getId()) {
432 $this->object->moveQuestions(
433 $this->edit_manager->getMoveSurveyQuestions(),
434 $insert_id,
435 $insert_mode
436 );
437 $this->edit_manager->clearMoveSurveyQuestions();
438 }
439 }
440
441 $this->ctrl->redirect($this, "questions");
442 }
443
444 public function removeQuestionsObject(): void
445 {
446 $items = $this->gatherSelectedTableItems(true, true, true, true);
447 if (count($items["blocks"]) + count($items["questions"]) + count($items["headings"]) > 0) {
448 $this->tpl->setOnScreenMessage('question', $this->lng->txt("remove_questions"));
449 $this->removeQuestionsForm($items["blocks"], $items["questions"], $items["headings"]);
450 } else {
451 $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_question_selected_for_removal"), true);
452 $this->ctrl->redirect($this, "questions");
453 }
454 }
455
456 public function removeQuestionsForm(
457 array $checked_questionblocks,
458 array $checked_questions,
459 array $checked_headings
460 ): void {
461 $cgui = new ilConfirmationGUI();
462 $cgui->setHeaderText($this->lng->txt("survey_sure_delete_questions"));
463 $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmRemoveQuestions"));
464 $cgui->setCancel($this->lng->txt("cancel"), "questions");
465 $cgui->setConfirm($this->lng->txt("confirm"), "confirmRemoveQuestions");
466 $surveyquestions = $this->object->getSurveyQuestions();
467 foreach ($surveyquestions as $question_id => $data) {
468 if (in_array($data["question_id"], $checked_questions)) {
469 $type = SurveyQuestion::_getQuestionTypeName($data["type_tag"]);
470
471 $cgui->addItem(
472 "q_id[]",
473 $data["question_id"],
474 $type . ": " . $data["title"]
475 );
476 } elseif ((in_array($data["questionblock_id"], $checked_questionblocks))) {
477 $type = SurveyQuestion::_getQuestionTypeName($data["type_tag"]);
478
479 $cgui->addItem(
480 "cb[" . $data["questionblock_id"] . "]",
481 $data["questionblock_id"],
482 $data["questionblock_title"] . " - " . $type . ": " . $data["title"]
483 );
484 } elseif (in_array($data["question_id"], $checked_headings)) {
485 $cgui->addItem(
486 "heading[" . $data["question_id"] . "]",
487 $data["question_id"],
488 $data["heading"]
489 );
490 }
491 }
492
493 $this->tpl->setContent($cgui->getHTML());
494 }
495
496 public function confirmRemoveQuestionsObject(): void
497 {
498 $checked_questions = $this->request->getQuestionIds();
499 $checked_questionblocks = $this->request->getBlockIds();
500 $checked_headings = $this->request->getHeadings();
501
502 if (count($checked_questions) || count($checked_questionblocks)) {
503 $this->object->removeQuestions($checked_questions, $checked_questionblocks);
504 }
505 if ($checked_headings) {
506 foreach ($checked_headings as $q_id) {
507 $this->object->saveHeading("", $q_id);
508 }
509 }
510 $this->object->saveCompletionStatus();
511 $this->tpl->setOnScreenMessage('success', $this->lng->txt("questions_removed"), true);
512 $this->ctrl->redirect($this, "questions");
513 }
514
515 public function copyQuestionsToPoolObject(): void
516 {
517 $items = $this->gatherSelectedTableItems(true, true, false, true);
518
519 // gather questions from blocks
520 $copy_questions = $items["questions"];
521 foreach ($items["blocks"] as $block_id) {
522 foreach ($this->object->getQuestionblockQuestionIds($block_id) as $qid) {
523 $copy_questions[] = $qid;
524 }
525 }
526 $copy_questions = array_unique($copy_questions);
527
528 // only if not already in pool
529 if (count($copy_questions)) {
530 foreach ($copy_questions as $idx => $question_id) {
531 $question = ilObjSurvey::_instanciateQuestion($question_id);
532 if ($question->getOriginalId()) {
533 unset($copy_questions[$idx]);
534 }
535 }
536 }
537 if (count($copy_questions) === 0) {
538 $this->tpl->setOnScreenMessage('info', $this->lng->txt("no_question_selected_for_copy_to_pool"), true);
539 $this->ctrl->redirect($this, "questions");
540 } else {
541 $this->questionsSubtabs("questions");
542
543 $form = new ilPropertyFormGUI();
544
545 $form->setFormAction($this->ctrl->getFormAction($this, "executeCreateQuestion"));
546
547 $ids = new ilHiddenInputGUI("question_ids");
548 $ids->setValue(implode(";", $copy_questions));
549 $form->addItem($ids);
550
551 $questionpools = $this->object->getAvailableQuestionpools(false, false, true, "write");
552 $pools = new ilSelectInputGUI($this->lng->txt("survey_copy_select_questionpool"), "sel_spl");
553 $pools->setOptions($questionpools);
554 $form->addItem($pools);
555
556 $form->addCommandButton("executeCopyQuestionsToPool", $this->lng->txt("submit"));
557 $form->addCommandButton("questions", $this->lng->txt("cancel"));
558
559 $this->tpl->setContent($form->getHTML());
560 }
561 }
562
563 public function executeCopyQuestionsToPoolObject(): void
564 {
565 $question_ids = $this->request->getQuestionIdsFromString();
566 $pool_id = ilObject::_lookupObjId($this->request->getSelectedPool());
567
568 foreach ($question_ids as $qid) {
569 // create copy (== pool "original")
570 $new_question = ilObjSurvey::_instanciateQuestion($qid);
571 $new_question->setId();
572 $new_question->setObjId($pool_id);
573 $new_question->saveToDb();
574
575 // link "source" (survey) to copy (pool)
576 SurveyQuestion::_changeOriginalId($qid, $new_question->getId(), $pool_id);
577 }
578
579 $this->tpl->setOnScreenMessage('success', $this->lng->txt("survey_copy_to_questionpool_success"), true);
580 $this->ctrl->redirect($this, "questions");
581 }
582
583
584 //
585 // QUESTION CREATION
586 //
587
588 public function createQuestionObject(
589 ?ilPropertyFormGUI $a_form = null,
590 $sel_question_types = null,
591 ?string $pgov_pos = null
593 $this->executeCreateQuestionObject(null, 1, $pgov_pos);
594 }
595
597 ?string $q_type = null,
598 ?int $pool_usage = null,
599 ?string $pgov_pos = null
600 ): void {
601 $this->edit_manager->setPoolChoice($this->request->getPoolUsage());
602
603 if (is_null($q_type)) {
604 $q_type = $this->request->getSelectedQuestionTypes();
605 }
606
607 $pgov = $this->requested_pgov;
608 if (is_null($pgov_pos)) {
609 $pgov_pos = $this->request->getTargetQuestionPosition();
610 }
611
612 if (is_null($pool_usage)) {
613 $pool_usage = $this->request->getPoolUsage();
614 }
615 $pool_usage = 1;
616
617 $obj_id = 0;
618 $obj_id = $this->object->getId();
619
620 // create question and redirect to question form
621
622 $q_gui = SurveyQuestionGUI::_getQuestionGUI($q_type);
623 $q_gui->object->setObjId($obj_id); // survey/pool!
624 $q_gui->object->createNewQuestion();
625 $q_gui_class = get_class($q_gui);
626
627 if ($pgov !== "") {
628 $this->ctrl->setParameterByClass($q_gui_class, "pgov", $pgov);
629 $this->ctrl->setParameterByClass($q_gui_class, "pgov_pos", $pgov_pos);
630 }
631
632 $this->ctrl->setParameterByClass($q_gui_class, "ref_id", $this->object->getRefId());
633 $this->ctrl->setParameterByClass($q_gui_class, "new_for_survey", $this->object->getRefId());
634 $this->ctrl->setParameterByClass($q_gui_class, "q_id", $q_gui->object->getId());
635 $this->ctrl->setParameterByClass($q_gui_class, "sel_question_types", $q_gui->getQuestionType());
636 $this->ctrl->redirectByClass($q_gui_class, "editQuestion");
637 }
638
639 protected function createQuestionPool($name = "dummy"): int
640 {
641 $tree = $this->tree;
642
643 $parent_ref = $tree->getParentId($this->object->getRefId());
644
645 $qpl = new ilObjSurveyQuestionPool();
646 $qpl->setType("spl");
647 $qpl->setTitle($name);
648 $qpl->setDescription("");
649 $qpl->create();
650 $qpl->createReference();
651 $qpl->putInTree($parent_ref);
652 $qpl->setPermissions($parent_ref);
653 $qpl->setOnline(1); // must be online to be available
654 $qpl->saveToDb();
655
656 return $qpl->getId();
657 }
658
659
660 //
661 // ADD FROM POOL
662 //
663
664 protected function setBrowseForQuestionsSubtabs(): void
665 {
666 $ilTabs = $this->tabs;
667 $ilToolbar = $this->toolbar;
668 $ilUser = $this->user;
669
670 $link = $this->ctrl->getLinkTarget($this, "questions");
671 $ilTabs->setBackTarget($this->lng->txt("menubacktosurvey"), $link);
672
673 // type selector
674 $types = new ilSelectInputGUI($this->lng->txt("display_all_available"), "datatype");
675 $types->setOptions(array(
676 1 => $this->lng->txt("questions"),
677 2 => $this->lng->txt("questionblocks")
678 ));
679 $types->setValue($ilUser->getPref('svy_insert_type'));
680 $ilToolbar->addInputItem($types, true);
681 $ilToolbar->addFormButton($this->lng->txt("change"), "changeDatatype");
682 $ilToolbar->setFormAction($this->ctrl->getFormAction($this, "changeDatatype"));
683 }
684
685 public function changeDatatypeObject(): void
686 {
687 $ilUser = $this->user;
688
689 $ilUser->writePref('svy_insert_type', $this->request->getDataType());
690
691 switch ($this->request->getDataType()) {
692 case 2:
693 $this->ctrl->redirect($this, 'browseForQuestionblocks');
694 break;
695
696 case 1:
697 default:
698 $this->ctrl->redirect($this, 'browseForQuestions');
699 break;
700 }
701 }
702
703 public function browseForQuestionsObject(): void
704 {
705 $this->setBrowseForQuestionsSubtabs();
706
707 $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', $this->object, true);
708 $table_gui->setEditable(true);
709 $this->tpl->setContent($table_gui->getHTML());
710 }
711
712 public function filterQuestionBrowserObject(): void
713 {
714 $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', $this->object);
715 $table_gui->writeFilterToSession();
716 $this->ctrl->redirect($this, 'browseForQuestions');
717 }
718
719 public function resetfilterQuestionBrowserObject(): void
720 {
721 $table_gui = new ilSurveyQuestionbrowserTableGUI($this, 'browseForQuestions', $this->object);
722 $table_gui->resetFilter();
723 $this->ctrl->redirect($this, 'browseForQuestions');
724 }
725
726 public function insertQuestionsObject(): void
727 {
728 $inserted_objects = 0;
729 $page_gui = null;
730 $qids = $this->request->getQuestionIds();
731 if (count($qids) > 0) {
732 foreach ($qids as $question_id) {
733 if ($this->requested_pgov === "") {
734 $this->object->insertQuestion($question_id);
735 } else {
736 // "pgov" must be set to 1 to land here
737 // target position in page (pgov_pos) is processed there
738 $page_gui->insertNewQuestion($question_id);
739 }
740 $inserted_objects++;
741 }
742 }
743 if ($inserted_objects) {
744 $this->object->saveCompletionStatus();
745 $this->tpl->setOnScreenMessage('success', $this->lng->txt("questions_inserted"), true);
746 $this->ctrl->redirect($this, "questions");
747 } else {
748 $this->tpl->setOnScreenMessage('info', $this->lng->txt("insert_missing_question"), true);
749 $this->ctrl->redirect($this, 'browseForQuestions');
750 }
751 }
752
753 public function browseForQuestionblocksObject(): void
754 {
755 $this->setBrowseForQuestionsSubtabs();
756
757 $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', $this->object, true);
758 $table_gui->setEditable(true);
759 $this->tpl->setContent($table_gui->getHTML());
760 }
761
762 public function filterQuestionblockBrowserObject(): void
763 {
764 $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', $this->object);
765 $table_gui->writeFilterToSession();
766 $this->ctrl->redirect($this, 'browseForQuestionblocks');
767 }
768
770 {
771 $table_gui = new ilSurveyQuestionblockbrowserTableGUI($this, 'browseForQuestionblocks', $this->object);
772 $table_gui->resetFilter();
773 $this->ctrl->redirect($this, 'browseForQuestionblocks');
774 }
775
776 public function insertQuestionblocksObject(): void
777 {
778 $inserted_objects = 0;
779 $page_gui = null;
780 $block_ids = $this->request->getBlockIds();
781 if (count($block_ids) > 0) {
782 foreach ($block_ids as $questionblock_id) {
783 if ($this->requested_pgov === "") {
784 $this->object->insertQuestionblock($questionblock_id);
785 } else {
786 $page_gui->insertQuestionBlock($questionblock_id);
787 }
788 $inserted_objects++;
789 }
790 }
791 if ($inserted_objects) {
792 $this->object->saveCompletionStatus();
793 $this->tpl->setOnScreenMessage('success', ($inserted_objects === 1) ? $this->lng->txt("questionblock_inserted") : $this->lng->txt("questionblocks_inserted"), true);
794 $this->ctrl->redirect($this, "questions");
795 } else {
796 $this->tpl->setOnScreenMessage('info', $this->lng->txt("insert_missing_questionblock"), true);
797 $this->ctrl->redirect($this, 'browseForQuestionblocks');
798 }
799 }
800
801
802 //
803 // BLOCKS
804 //
805
806 public function editQuestionblockObject(
807 ?ilPropertyFormGUI $a_form = null
808 ): void {
809 $block_id = $this->request->getBlockId();
810 $this->ctrl->setParameter($this, "bl_id", $block_id);
811
812 if (!$a_form) {
813 $a_form = $this->initQuestionblockForm($block_id);
814 }
815
816 $this->questionsSubtabs("questions");
817 $this->tpl->setContent($a_form->getHTML());
818 }
819
821 ?ilPropertyFormGUI $a_form = null
822 ): void {
823 if (!$a_form) {
824 // gather questions from table selected
825 $items = $this->gatherSelectedTableItems(false, true, false, false);
826
827 $qids = $this->request->getQuestionIds();
828 if (count($qids) > 0) {
829 $items["questions"] = $qids;
830 }
831 if (count($items["questions"]) < 2) {
832 $this->tpl->setOnScreenMessage('info', $this->lng->txt("qpl_define_questionblock_select_missing"), true);
833 $this->ctrl->redirect($this, "questions");
834 }
835
836 $a_form = $this->initQuestionblockForm(null, $items["questions"]);
837 }
838
839 $this->questionsSubtabs("questions");
840 $this->tpl->setContent($a_form->getHTML());
841 }
842
843 protected function initQuestionblockForm(
844 ?int $a_block_id = null,
845 ?array $a_question_ids = null
847 $questionblock = null;
848 $form = new ilPropertyFormGUI();
849 $form->setFormAction($this->ctrl->getFormAction($this, "saveDefineQuestionblock"));
850 $form->setTitle($this->lng->txt("define_questionblock"));
851
852 $title = new ilTextInputGUI($this->lng->txt("title"), "title");
853 $title->setRequired(true);
854 $form->addItem($title);
855
856 $toggle_blocktitle = new ilCheckboxInputGUI($this->lng->txt("survey_show_blocktitle"), "show_blocktitle");
857 $toggle_blocktitle->setInfo($this->lng->txt("survey_show_blocktitle_description"));
858 $form->addItem($toggle_blocktitle);
859
860 $toggle_questiontitle = new ilCheckboxInputGUI($this->lng->txt("show_questiontext"), "show_questiontext");
861 $toggle_questiontitle->setInfo($this->lng->txt("show_questiontext_description"));
862 $form->addItem($toggle_questiontitle);
863
864 if ($a_block_id) {
865 $questionblock = ilObjSurvey::_getQuestionblock($a_block_id);
866 $title->setValue($questionblock["title"]);
867 $toggle_blocktitle->setChecked((bool) $questionblock["show_blocktitle"]);
868 $toggle_questiontitle->setChecked((bool) $questionblock["show_questiontext"]);
869 } else {
870 $toggle_blocktitle->setChecked(true);
871 $toggle_questiontitle->setChecked(true);
872 }
873
874 $compress_view = new ilCheckboxInputGUI($this->lng->txt("svy_compress_view"), "compress_view");
875 $compress_view->setInfo($this->lng->txt("svy_compress_view_info"));
876 $compress_view->setChecked((bool) ($questionblock["compress_view"] ?? false));
877 $form->addItem($compress_view);
878
879 $form->addCommandButton("saveDefineQuestionblock", $this->lng->txt("save"));
880 $form->addCommandButton("questions", $this->lng->txt("cancel"));
881
882 // reload?
883 $qids = $this->request->getQuestionIds();
884 if (!$a_question_ids && count($qids) > 0) {
885 $a_question_ids = $qids;
886 }
887
888 if ($a_question_ids) {
889 foreach ($a_question_ids as $q_id) {
890 $hidden = new ilHiddenInputGUI("qids[]");
891 $hidden->setValue($q_id);
892 $form->addItem($hidden);
893 }
894 }
895
896 return $form;
897 }
898
899 public function saveDefineQuestionblockObject(): void
900 {
901 $block_id = $this->request->getBlockId();
902 $q_ids = $this->request->getQuestionIds();
903
904 $this->ctrl->setParameter($this, "bl_id", $block_id);
905
906 if (!$block_id && count($q_ids) === 0) {
907 $this->ctrl->redirect($this, "questions");
908 }
909
910 $form = $this->initQuestionblockForm($block_id);
911 if ($form->checkInput()) {
912 $title = $form->getInput("title");
913 $show_questiontext = $form->getInput("show_questiontext");
914 $show_blocktitle = $form->getInput("show_blocktitle") ;
915 $compress_view = $form->getInput("compress_view") ;
916 if ($block_id) {
917 $this->object->modifyQuestionblock(
918 $block_id,
919 $title,
920 $show_questiontext,
921 $show_blocktitle,
922 $compress_view
923 );
924 } elseif ($q_ids) {
925 $this->object->createQuestionblock(
926 $title,
927 $show_questiontext,
928 $show_blocktitle,
929 $q_ids,
930 $compress_view
931 );
932 }
933
934 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
935 $this->ctrl->redirect($this, "questions");
936 }
937
938 $form->setValuesByPost();
939 $this->editQuestionblockObject($form);
940 }
941
942
943 //
944 // HEADING
945 //
946
947 protected function initHeadingForm(
948 ?int $a_question_id = null
950 $survey_questions = $this->object->getSurveyQuestions();
951
952 $form = new ilPropertyFormGUI();
953 $form->setFormAction($this->ctrl->getFormAction($this, ""));
954
955 // heading
956 $heading = new ilTextAreaInputGUI($this->lng->txt("heading"), "heading");
957 $heading->setRows(10);
958 $heading->setCols(80);
959 $heading->setRequired(true);
960 $form->addItem($heading);
961
962 $insertbefore = new ilSelectInputGUI($this->lng->txt("insert"), "insertbefore");
963 $options = array();
964 foreach ($survey_questions as $key => $value) {
965 $options[$key] = $this->lng->txt("before") . ": \"" . $value["title"] . "\"";
966 }
967 $insertbefore->setOptions($options);
968 $insertbefore->setRequired(true);
969 $form->addItem($insertbefore);
970
971 $form->addCommandButton("saveHeading", $this->lng->txt("save"));
972 $form->addCommandButton("questions", $this->lng->txt("cancel"));
973
974 if ($a_question_id) {
975 $form->setTitle($this->lng->txt("edit_heading"));
976
977 $heading->setValue($this->object->prepareTextareaOutput($survey_questions[$a_question_id]["heading"] ?? ""));
978 $insertbefore->setValue($a_question_id);
979 $insertbefore->setDisabled(true);
980 } else {
981 $form->setTitle($this->lng->txt("add_heading"));
982 }
983
984 return $form;
985 }
986
987 public function addHeadingObject(
988 ?ilPropertyFormGUI $a_form = null
989 ): void {
990 $q_id = $this->request->getQuestionId();
991 $this->ctrl->setParameter($this, "q_id", $q_id);
992
993 $this->questionsSubtabs("questions");
994
995 if (!$a_form) {
996 $a_form = $this->initHeadingForm($q_id);
997 }
998
999 $this->tpl->setContent($a_form->getHTML());
1000 }
1001
1002 public function editHeadingObject(
1003 ?ilPropertyFormGUI $a_form = null
1004 ): void {
1005 $q_id = $this->request->getQuestionId();
1006 $this->ctrl->setParameter($this, "q_id", $q_id);
1007
1008 $this->questionsSubtabs("questions");
1009
1010 if (!$a_form) {
1011 $a_form = $this->initHeadingForm($q_id);
1012 }
1013
1014 $this->tpl->setContent($a_form->getHTML());
1015 }
1016
1017 public function saveHeadingObject(): void
1018 {
1019 // #15474
1020 $q_id = $this->request->getQuestionId();
1021 $this->ctrl->setParameter($this, "q_id", $q_id);
1022
1023 $form = $this->initHeadingForm($q_id);
1024 if ($form->checkInput()) {
1025 $this->object->saveHeading(
1027 $form->getInput("heading"),
1028 true,
1030 ),
1031 $form->getInput("insertbefore")
1032 );
1033 $this->ctrl->redirect($this, "questions");
1034 }
1035
1036 $form->setValuesByPost();
1037 $this->addHeadingObject($form);
1038 }
1039
1040 public function removeHeadingObject(): void
1041 {
1042 $q_id = $this->request->getQuestionId();
1043 $this->ctrl->setParameter($this, "q_id", $q_id);
1044
1045 if (!$q_id) {
1046 $this->ctrl->redirect($this, "questions");
1047 }
1048
1049 $this->questionsSubtabs("questions");
1050
1051 $cgui = new ilConfirmationGUI();
1052 $cgui->setHeaderText($this->lng->txt("confirm_remove_heading"));
1053
1054 $cgui->setFormAction($this->ctrl->getFormAction($this, "confirmedRemoveHeading"));
1055 $cgui->setCancel($this->lng->txt("cancel"), "questions");
1056 $cgui->setConfirm($this->lng->txt("confirm"), "confirmedRemoveHeading");
1057
1058 $this->tpl->setContent($cgui->getHTML());
1059 }
1060
1061 public function confirmedRemoveHeadingObject(): void
1062 {
1063 $q_id = $this->request->getQuestionId();
1064 if (!$q_id) {
1065 $this->ctrl->redirect($this, "questions");
1066 }
1067
1068 $this->object->saveHeading("", $q_id);
1069 $this->ctrl->redirect($this, "questions");
1070 }
1071
1072 public function printViewObject(): void
1073 {
1074 $print_view = $this->print->page($this->object->getRefId());
1075 $print_view->sendPrintView();
1076 }
1077
1078 public function printListViewSelectionObject(): void
1079 {
1080 $view = $this->print->list($this->object->getRefId());
1081 $view->sendForm();
1082 }
1083
1084 public function printListViewObject(): void
1085 {
1086 $print_view = $this->print->list($this->object->getRefId());
1087 $print_view->sendPrintView();
1088 }
1089
1090 protected function copyQuestionObject(): void
1091 {
1092 $id = $this->request->getQuestionId();
1093 $lng = $this->lng;
1094 $this->tpl->setOnScreenMessage('success', $lng->txt("survey_questions_to_clipboard_copy"), true);
1095 //$this->suppress_clipboard_msg = true;
1096
1097 $this->edit_manager->setQuestionClipboard(
1098 $this->object->getRefId(),
1099 0,
1100 "copy",
1101 [$id]
1102 );
1103 $this->ctrl->redirect($this, "questions");
1104 }
1105
1110 protected function copyPasteObject($pos = 0): void
1111 {
1112 $a_id = null;
1113 $ids = $this->request->getIds();
1114 if (count($ids) > 0) {
1115 if (substr($ids[0], 0, 3) == "cb_") {
1116 $a_id = (int) substr($ids[0], 3);
1117 }
1118 }
1119 if (is_null($a_id)) {
1120 return;
1121 }
1122
1123 $qids = $this->edit_manager->getQuestionClipboardQuestions($this->object->getRefId());
1124 $mode = $this->edit_manager->getQuestionClipboardMode($this->object->getRefId());
1125 $pages = $this->object->getSurveyPages();
1126 $target = null;
1127 foreach ($pages as $page) {
1128 foreach ($page as $question) {
1129 if ($question["question_id"] === $a_id) {
1130 $target = $page;
1131 }
1132 }
1133 }
1134 if (is_null($target)) {
1135 return;
1136 }
1137
1138 if ($mode !== "copy") {
1139 return;
1140 }
1141
1142 $titles = array();
1143 foreach ($this->object->getSurveyPages() as $page) {
1144 foreach ($page as $question) {
1145 $titles[] = $question["title"];
1146 }
1147 }
1148
1149 // copy questions
1150 $question_pointer = array();
1151 foreach ($qids as $qid) {
1152 // create new questions
1153 $question = ilObjSurvey::_instanciateQuestion($qid);
1154
1155 // handle exisiting copies
1156 $title = $question->getTitle();
1157 $max = 0;
1158 foreach ($titles as $existing_title) {
1159 #21278 preg_quote with delimiter
1160 if (preg_match("/" . preg_quote($title, "/") . " \‍(([0-9]+)\‍)$/", $existing_title, $match)) {
1161 $max = max($match[1], $max);
1162 }
1163 }
1164 if ($max) {
1165 $title .= " (" . ($max + 1) . ")";
1166 } else {
1167 $title .= " (2)";
1168 }
1169 $titles[] = $title;
1170 $question->setTitle($title);
1171
1172 $question->id = -1;
1173 $question->saveToDb(); // this creates the copy
1174
1175 $question_pointer[$qid] = $question->getId();
1176 $this->sequence_manager->appendQuestion($question->getId(), false);
1177 }
1178
1179 // copy textblocks
1180 $this->object->cloneTextblocks($question_pointer);
1181
1182 $this->object->loadQuestionsFromDb();
1183
1184 $nodes = array_values($question_pointer);
1185
1186
1187 // paste
1188
1189 // create new block
1190 if (count($target) === 1) {
1191 $this->object->moveQuestions($nodes, $a_id, $pos);
1192 }
1193 // add to existing block
1194 else {
1195 $target_block_id = $target;
1196 $target_block_id = array_shift($target_block_id);
1197 $target_block_id = $target_block_id["questionblock_id"];
1198
1199 foreach ($nodes as $qid) {
1200 $this->object->addQuestionToBlock($qid, $target_block_id);
1201 }
1202
1203 // move to new position
1204 $this->object->moveQuestions($nodes, $a_id, $pos);
1205 }
1206
1207 $this->clearClipboard();
1208 $this->ctrl->redirect($this, "questions");
1209 }
1210
1211 protected function clearClipboard(): void
1212 {
1213 $this->edit_manager->clearQuestionClipboard($this->object->getRefId());
1214 }
1215
1216 public function getAutoBlockTitle(): string
1217 {
1218 $lng = $this->lng;
1219 return $lng->txt("survey_auto_block_title");
1220 }
1221
1222}
$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.
static _getUsedHTMLTagsAsString(string $module='')
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 stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
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