ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLOEditorGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
33{
34 public const TEST_TYPE_UNDEFINED = 0;
35 public const TEST_TYPE_IT = 1;
36 public const TEST_TYPE_QT = 2;
37
38 public const TEST_NEW = 1;
39 public const TEST_ASSIGN = 2;
40
42
54 protected Factory $refinery;
55
57
59 {
60 global $DIC;
61
62 $this->main_tpl = $DIC->ui()->mainTemplate();
63 $this->parent_obj = $parent_gui->getObject();
64 $this->parent_gui = $parent_gui;
66
67 $cs = $DIC->contentStyle();
68 $this->content_style_domain = $cs->domain()->styleForRefId($this->parent_obj->getRefId());
69
70 $this->lng = $DIC->language();
71 $this->ctrl = $DIC->ctrl();
72 $this->tpl = $DIC->ui()->mainTemplate();
73 $this->tabs = $DIC->tabs();
74 $this->toolbar = $DIC->toolbar();
75 $this->logger = $DIC->logger()->crs();
76 $this->http = $DIC->http();
77 $this->refinery = $DIC->refinery();
78 }
79
80 public function executeCommand(): void
81 {
82 $next_class = $this->ctrl->getNextClass($this);
83 $cmd = $this->ctrl->getCmd();
84
85 $this->setTabs();
86 switch ($next_class) {
87 case 'ilcourseobjectivesgui':
88
89 $this->ctrl->setReturn($this, 'returnFromObjectives');
90 $this->tabs->clearTargets();
91 $this->tabs->setBackTarget(
92 $this->lng->txt('back'),
93 $this->ctrl->getLinkTarget($this, 'listObjectives')
94 );
95
96 $reg_gui = new ilCourseObjectivesGUI($this->getParentObject()->getRefId());
97 $this->ctrl->forwardCommand($reg_gui);
98 break;
99
100 case 'ilcontainerstartobjectsgui':
101
102 $stgui = new ilContainerStartObjectsGUI($this->getParentObject());
103 $ret = $this->ctrl->forwardCommand($stgui);
104
105 $this->tabs->activateSubTab('start');
106 $this->tabs->removeSubTab('manage');
107 break;
108
109 case 'ilconditionhandlergui':
110
111 $this->ctrl->saveParameterByClass('ilconditionhandlergui', 'objective_id');
112
113 $this->tabs->clearTargets();
114 $this->tabs->setBackTarget(
115 $this->lng->txt('back'),
116 $this->ctrl->getLinkTarget($this, 'listObjectives')
117 );
118
119 $cond = new ilConditionHandlerGUI();
120 $cond->setBackButtons(array());
121 $cond->setAutomaticValidation(false);
122 $cond->setTargetType("lobj");
123 $cond->setTargetRefId($this->getParentObject()->getRefId());
124 $cond->setTargetId($this->initObjectiveIdFromQuery());
125
126 // objective
127 $obj = new ilCourseObjective($this->getParentObject(), $this->initObjectiveIdFromQuery());
128 $cond->setTargetTitle($obj->getTitle());
129 $this->ctrl->forwardCommand($cond);
130 break;
131
132 case 'illopagegui':
133 $this->ctrl->saveParameterByClass('illopagegui', 'objective_id');
134
135 $this->tabs->clearTargets();
136 $this->tabs->setBackTarget(
137 $this->lng->txt('back'),
138 $this->ctrl->getLinkTarget($this, 'listObjectives')
139 );
140
141 $objtv_id = $this->initObjectiveIdFromQuery();
142
143 if (!ilLOPage::_exists('lobj', $objtv_id)) {
144 // doesn't exist -> create new one
145 $new_page_object = new ilLOPage();
146 $new_page_object->setParentId($objtv_id);
147 $new_page_object->setId($objtv_id);
148 $new_page_object->createFromXML();
149 unset($new_page_object);
150 }
151
152 $this->ctrl->setReturn($this, 'listObjectives');
153 $pgui = new ilLOPageGUI($objtv_id);
154 $pgui->setPresentationTitle(ilCourseObjective::lookupObjectiveTitle($objtv_id));
155
156 $pgui->setStyleId($this->content_style_domain->getEffectiveStyleId());
157
158 // #14895
159 $this->tpl->setCurrentBlock("ContentStyle");
160 $this->tpl->setVariable(
161 "LOCATION_CONTENT_STYLESHEET",
162 ilObjStyleSheet::getContentStylePath($this->content_style_domain->getEffectiveStyleId())
163 );
164 $this->tpl->parseCurrentBlock();
165
166 $ret = $this->ctrl->forwardCommand($pgui);
167 if ($ret) {
168 $this->tpl->setContent($ret);
169 }
170 break;
171
172 default:
173 if (!$cmd) {
174 // get first unaccomplished step
175 $cmd = ilLOEditorStatus::getInstance($this->getParentObject())->getFirstFailedStep();
176 }
177 $this->$cmd();
178
179 break;
180 }
181 }
182
183 protected function initObjectiveIdFromQuery(): int
184 {
185 if ($this->http->wrapper()->query()->has('objective_id')) {
186 return $this->http->wrapper()->query()->retrieve(
187 'objective_id',
188 $this->refinery->kindlyTo()->int()
189 );
190 }
191 return 0;
192 }
193
194 protected function initObjectiveIdsFromPost(): array
195 {
196 if ($this->http->wrapper()->post()->has('objective')) {
197 return $this->http->wrapper()->post()->retrieve(
198 'objective',
199 $this->refinery->kindlyTo()->listOf(
200 $this->refinery->kindlyTo()->int()
201 )
202 );
203 }
204 return [];
205 }
206
207 protected function initTestTypeFromQuery(): int
208 {
209 if ($this->http->wrapper()->query()->has('tt')) {
210 return $this->http->wrapper()->query()->retrieve(
211 'tt',
212 $this->refinery->kindlyTo()->int()
213 );
214 }
215 return 0;
216 }
217
218 protected function returnFromObjectives(): void
219 {
221 $this->listObjectives();
222 }
223
224 public function getParentObject(): ilObject
225 {
226 return $this->parent_obj;
227 }
228
229 public function getParentGUI(): ilObjCourseGUI
230 {
231 return $this->parent_gui;
232 }
233
234 public function getSettings(): ilLOSettings
235 {
236 return $this->settings;
237 }
238
239 public function setTestType(int $a_type): void
240 {
241 $this->test_type = $a_type;
242 }
243
244 public function getTestType(): int
245 {
246 return $this->test_type;
247 }
248
249 protected function settings(?ilPropertyFormGUI $form = null): void
250 {
251 if (!$form instanceof ilPropertyFormGUI) {
252 $form = $this->initSettingsForm();
253 }
254 $this->tabs->activateSubTab('settings');
255 $this->tpl->setContent($form->getHTML());
257 }
258
259 protected function deleteAssignments(int $a_type): void
260 {
261 $assignments = ilLOTestAssignments::getInstance($this->getParentObject()->getId());
262 foreach ($assignments->getAssignmentsByType($a_type) as $assignment) {
263 $assignment->delete();
264 }
265 }
266
268 {
269 switch ($settings->getInitialTestType()) {
273
274 // no break
278
279 break;
280
283 $settings->setInitialTest(0);
284 break;
285 }
286
287 switch ($settings->getQualifyingTestType()) {
290 break;
291
293 $settings->setQualifiedTest(0);
294 break;
295 }
296 $settings->update();
297 }
298
299 protected function saveSettings(): void
300 {
301 $form = $this->initSettingsForm();
302 if ($form->checkInput()) {
304 $settings->setInitialTestType((int) $form->getInput('ittype'));
305 switch ($settings->getInitialTestType()) {
307 $settings->setInitialTestAsStart((bool) $form->getInput('start_ip'));
308 break;
309
312 break;
313
315 $settings->setInitialTestAsStart((bool) $form->getInput('start_iq'));
316 break;
317
320 break;
321
324 break;
325 }
326
327 $settings->setQualifyingTestType((int) $form->getInput('qttype'));
328 switch ($settings->getQualifyingTestType()) {
330 $settings->setQualifyingTestAsStart((bool) $form->getInput('start_q'));
331 break;
332
335 break;
336 }
337
338 $settings->resetResults((bool) $form->getInput('reset'));
339 $settings->setPassedObjectiveMode((int) $form->getInput('passed_mode'));
340
341 if (
344 ) {
346 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('crs_loc_settings_err_qstart'), true);
347 }
348
349 $settings->update();
350 $this->updateStartObjects();
351 $this->updateTestAssignments($settings);
352
354
355 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
356 $this->ctrl->redirect($this, 'settings');
357 }
358
359 // Error
360 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
361 $form->setValuesByPost();
362 $this->settings($form);
363 }
364
369 {
370 $form = new ilPropertyFormGUI();
371 $form->setFormAction($this->ctrl->getFormAction($this));
372 $form->setTitle($this->lng->txt('crs_loc_settings_tbl'));
373
374 // initial test
375 $type_selector = new ilRadioGroupInputGUI($this->lng->txt('crs_loc_settings_it_type'), 'ittype');
376 $type_selector->setRequired(true);
377 $type_selector->setValue((string) $this->getSettings()->getInitialTestType());
378
379 $type_ipa = new ilRadioOption(
380 $this->lng->txt('crs_loc_settings_type_it_placement_all'),
382 );
383 $type_ipa->setInfo($this->lng->txt('crs_loc_settings_type_it_placement_all_info'));
384 $type_selector->addOption($type_ipa);
385
386 $start_ip = new ilCheckboxInputGUI($this->lng->txt('crs_loc_settings_it_start_object'), 'start_ip');
387 $start_ip->setValue((string) 1);
388 $start_ip->setChecked($this->getSettings()->isInitialTestStart());
389 $type_ipa->addSubItem($start_ip);
390
391 $type_ips = new ilRadioOption(
392 $this->lng->txt('crs_loc_settings_type_it_placement_sel'),
394 );
395 $type_ips->setInfo($this->lng->txt('crs_loc_settings_type_it_placement_sel_info'));
396 $type_selector->addOption($type_ips);
397
398 $type_iqa = new ilRadioOption(
399 $this->lng->txt('crs_loc_settings_type_it_qualifying_all'),
401 );
402 $type_iqa->setInfo($this->lng->txt('crs_loc_settings_type_it_qualifying_all_info'));
403 $type_selector->addOption($type_iqa);
404
405 $start_iq = new ilCheckboxInputGUI($this->lng->txt('crs_loc_settings_it_start_object'), 'start_iq');
406 $start_iq->setValue('1');
407 $start_iq->setChecked($this->getSettings()->isInitialTestStart());
408 $type_iqa->addSubItem($start_iq);
409
410 $type_iqs = new ilRadioOption(
411 $this->lng->txt('crs_loc_settings_type_it_qualifying_sel'),
413 );
414 $type_iqs->setInfo($this->lng->txt('crs_loc_settings_type_it_qualifying_sel_info'));
415 $type_selector->addOption($type_iqs);
416
417 $type_ino = new ilRadioOption(
418 $this->lng->txt('crs_loc_settings_type_it_none'),
420 );
421 $type_ino->setInfo($this->lng->txt('crs_loc_settings_type_it_none_info'));
422 $type_selector->addOption($type_ino);
423
424 $form->addItem($type_selector);
425
426 // qualifying test
427 $qt_selector = new ilRadioGroupInputGUI($this->lng->txt('crs_loc_settings_qt_all'), 'qttype');
428 $qt_selector->setRequired(true);
429 $qt_selector->setValue((string) $this->getSettings()->getQualifyingTestType());
430
431 $type_qa = new ilRadioOption(
432 $this->lng->txt('crs_loc_settings_type_q_all'),
434 );
435 $type_qa->setInfo($this->lng->txt('crs_loc_settings_type_q_all_info'));
436 $qt_selector->addOption($type_qa);
437
438 $start_q = new ilCheckboxInputGUI($this->lng->txt('crs_loc_settings_qt_start_object'), 'start_q');
439 $start_q->setValue('1');
440 $start_q->setChecked($this->getSettings()->isQualifyingTestStart());
441 $type_qa->addSubItem($start_q);
442
443 $passed_mode = new ilRadioGroupInputGUI($this->lng->txt('crs_loc_settings_passed_mode'), 'passed_mode');
444 $passed_mode->setValue(
445 (string) ($this->getSettings()->getPassedObjectiveMode() ?: ilLOSettings::HIDE_PASSED_OBJECTIVE_QST)
446 );
447
448 $passed_mode->addOption(
449 new ilRadioOption(
450 $this->lng->txt('crs_loc_settings_passed_mode_hide'),
452 )
453 );
454 $passed_mode->addOption(
455 new ilRadioOption(
456 $this->lng->txt('crs_loc_settings_passed_mode_mark'),
458 )
459 );
460 $type_qa->addSubItem($passed_mode);
461
462 $type_qs = new ilRadioOption(
463 $this->lng->txt('crs_loc_settings_type_q_selected'),
465 );
466 $type_qs->setInfo($this->lng->txt('crs_loc_settings_type_q_selected_info'));
467 $qt_selector->addOption($type_qs);
468
469 $form->addItem($qt_selector);
470
471 // reset results
472 $reset = new ilCheckboxInputGUI($this->lng->txt('crs_loc_settings_reset'), 'reset');
473 $reset->setValue('1');
474 $reset->setChecked($this->getSettings()->isResetResultsEnabled());
475 $reset->setOptionTitle($this->lng->txt('crs_loc_settings_reset_enable'));
476 $reset->setInfo($this->lng->txt('crs_loc_settings_reset_enable_info'));
477 $form->addItem($reset);
478
479 $form->addCommandButton('saveSettings', $this->lng->txt('save'));
480 return $form;
481 }
482
483 protected function materials(): void
484 {
485 $this->tabs->activateSubTab('materials');
486
487 $this->parent_gui->renderAddNewItem('itgr');
488
489 $this->tpl->setOnScreenMessage(
490 'info',
491 $this->lng->txt('crs_objective_status_materials_info')
492 );
493
495 }
496
497 protected function testsOverview(): void
498 {
500 $this->setTestType($this->initTestTypeFromQuery());
501 }
502 $this->ctrl->setParameter($this, 'tt', $this->getTestType());
503
504 $this->toolbar->setFormAction($this->ctrl->getFormAction($this));
505 $this->toolbar->addButton(
506 $this->lng->txt('crs_loc_btn_new_assignment'),
507 $this->ctrl->getLinkTarget($this, 'testAssignment')
508 );
509
511 switch ($this->getTestType()) {
513 $this->tabs->activateSubTab('itests');
514 break;
515
517 $this->tabs->activateSubTab('qtests');
518 break;
519 }
520
521 try {
522 $table = new ilLOTestAssignmentTableGUI(
523 $this,
524 'testsOverview',
525 $this->getParentObject()->getId(),
526 $this->getTestType(),
528 );
529 $table->init();
530 $table->parseMultipleAssignments();
531 $this->tpl->setContent($table->getHTML());
532
533 $this->showStatus(
537 );
539 $this->logger->debug(': Show new assignment screen because of : ' . $ex->getMessage());
540 $this->testSettings();
541 }
542 }
543
544 protected function testsOverviewInitial(): void
545 {
547 $this->testsOverview();
548 }
549
550 protected function testsOverviewQualified(): void
551 {
553 $this->testsOverview();
554 }
555
559 protected function testOverview(): void
560 {
562 $this->setTestType($this->initTestTypeFromQuery());
563 }
564 $this->ctrl->setParameter($this, 'tt', $this->getTestType());
565
567 switch ($this->getTestType()) {
569 $this->tabs->activateSubTab('itest');
570 break;
571
573 $this->tabs->activateSubTab('qtest');
574 break;
575 }
576
577 // Check if test is assigned
578 if (!$settings->getTestByType($this->getTestType())) {
579 $this->testSettings();
580 return;
581 }
582
583 try {
584 $table = new ilLOTestAssignmentTableGUI(
585 $this,
586 'testOverview',
587 $this->getParentObject()->getId(),
588 $this->getTestType()
589 );
590 $table->init();
591 $table->parse(ilLOSettings::getInstanceByObjId($this->getParentObject()->getId())->getTestByType($this->getTestType()));
592 $this->tpl->setContent($table->getHTML());
593
594 $this->showStatus(
598 );
600 $this->logger->debug(': Show new assignment screen because of : ' . $ex->getMessage());
601 $this->testSettings();
602 }
603 }
604
605 protected function testOverviewInitial(): void
606 {
608 $this->testOverview();
609 }
610
611 protected function testOverviewQualified(): void
612 {
614 $this->testOverview();
615 }
616
620 protected function confirmDeleteTests(): void
621 {
622 $this->setTestType($this->initTestTypeFromQuery());
623 $this->ctrl->setParameter($this, 'tt', $this->getTestType());
624
626 switch ($this->getTestType()) {
628 $this->tabs->activateSubTab('itests');
629 break;
630
632 $this->tabs->activateSubTab('qtests');
633 break;
634 }
635
636 $tests = [];
637 if ($this->http->wrapper()->post()->has('tst')) {
638 $tests = $this->http->wrapper()->post()->retrieve(
639 'tst',
640 $this->refinery->kindlyTo()->listOf(
641 $this->refinery->kindlyTo()->int()
642 )
643 );
644 }
645 if (!count($tests)) {
646 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
647 $this->ctrl->redirect($this, 'testsOverview');
648 }
649 $confirm = new ilConfirmationGUI();
650 $confirm->setHeaderText($this->lng->txt('crs_loc_confirm_delete_tst'));
651 $confirm->setFormAction($this->ctrl->getFormAction($this));
652 $confirm->setConfirm($this->lng->txt('crs_loc_delete_assignment'), 'deleteTests');
653 $confirm->setCancel($this->lng->txt('cancel'), 'testsOverview');
654 foreach ($tests as $assign_id) {
655 $assignment = new ilLOTestAssignment($assign_id);
656
657 $obj_id = ilObject::_lookupObjId($assignment->getTestRefId());
658 $confirm->addItem('tst[]', (string) $assign_id, ilObject::_lookupTitle($obj_id));
659 }
660
661 $this->tpl->setContent($confirm->getHTML());
662
663 $this->showStatus(
667 );
668 }
669
673 protected function confirmDeleteTest(): void
674 {
675 $this->setTestType($this->initTestTypeFromQuery());
676 $this->ctrl->setParameter($this, 'tt', $this->getTestType());
677
679 switch ($this->getTestType()) {
681 $this->tabs->activateSubTab('itest');
682 break;
683
685 $this->tabs->activateSubTab('qtest');
686 break;
687 }
688
689 $tests = [];
690 if ($this->http->wrapper()->post()->has('tst')) {
691 $tests = $this->http->wrapper()->post()->retrieve(
692 'tst',
693 $this->refinery->kindlyTo()->listOf(
694 $this->refinery->kindlyTo()->int()
695 )
696 );
697 }
698 if (count($tests) === 0) {
699 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
700 $this->ctrl->redirect($this, 'testOverview');
701 }
702
703 $confirm = new ilConfirmationGUI();
704 $confirm->setHeaderText($this->lng->txt('crs_loc_confirm_delete_tst'));
705 $confirm->setFormAction($this->ctrl->getFormAction($this));
706 $confirm->setConfirm($this->lng->txt('crs_loc_delete_assignment'), 'deleteTest');
707 $confirm->setCancel($this->lng->txt('cancel'), 'testOverview');
708
709 foreach ($tests as $tst_id) {
710 $obj_id = ilObject::_lookupObjId($tst_id);
711 $confirm->addItem('tst[]', (string) $tst_id, ilObject::_lookupTitle($obj_id));
712 }
713 $this->tpl->setContent($confirm->getHTML());
714
715 $this->showStatus(
719 );
720 }
721
722 protected function deleteTests(): void
723 {
724 $this->setTestType($this->initTestTypeFromQuery());
725 $this->ctrl->setParameter($this, 'tt', $this->getTestType());
726
728 switch ($this->getTestType()) {
730 $this->tabs->activateSubTab('itests');
731 break;
732
734 $this->tabs->activateSubTab('qtests');
735 break;
736 }
737
738 $tests = [];
739 if ($this->http->wrapper()->post()->has('tst')) {
740 $tests = $this->http->wrapper()->post()->retrieve(
741 'tst',
742 $this->refinery->kindlyTo()->listOf(
743 $this->refinery->kindlyTo()->int()
744 )
745 );
746 }
747 foreach ($tests as $assign_id) {
748 $assignment = new ilLOTestAssignment($assign_id);
749 $assignment->delete();
750
751 // finally delete start object assignment
752 $start = new ilContainerStartObjects(
753 $this->getParentObject()->getRefId(),
754 $this->getParentObject()->getId()
755 );
756 $start->deleteItem($assignment->getTestRefId());
757
758 // ... and assigned questions
759 ilCourseObjectiveQuestion::deleteTest($assignment->getTestRefId());
760 }
761
762 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
763 $this->ctrl->redirect($this, 'testsOverview');
764 }
765
766 protected function deleteTest(): void
767 {
768 $this->setTestType($this->initTestTypeFromQuery());
769 $this->ctrl->setParameter($this, 'tt', $this->getTestType());
770
772 switch ($this->getTestType()) {
774 $this->tabs->activateSubTab('itest');
775 break;
776
778 $this->tabs->activateSubTab('qtest');
779 break;
780 }
781
782 $tests = [];
783 if ($this->http->wrapper()->post()->has('tst')) {
784 $tests = $this->http->wrapper()->post()->retrieve(
785 'tst',
786 $this->refinery->kindlyTo()->listOf(
787 $this->refinery->kindlyTo()->int()
788 )
789 );
790 }
791 foreach ($tests as $tst_id) {
792 switch ($this->getTestType()) {
794 $settings->setInitialTest(0);
795 break;
796
799 break;
800 }
801 $settings->update();
802
803 // finally delete start object assignment
804 $start = new ilContainerStartObjects(
805 $this->getParentObject()->getRefId(),
806 $this->getParentObject()->getId()
807 );
808 $start->deleteItem($tst_id);
809
810 // ... and assigned questions
812 }
813
814 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
815 $this->ctrl->redirect($this, 'testOverview');
816 }
817
818 protected function testAssignment(?ilPropertyFormGUI $form = null): void
819 {
821 $this->setTestType($this->initTestTypeFromQuery());
822 }
823 $this->ctrl->setParameter($this, 'tt', $this->getTestType());
824
825 switch ($this->getTestType()) {
827 $this->tabs->activateSubTab('itests');
828 break;
829
831 $this->tabs->activateSubTab('qtests');
832 break;
833 }
834 if (!$form instanceof ilPropertyFormGUI) {
835 $form_helper = new ilLOTestAssignmentForm($this, $this->getParentObject(), $this->getTestType());
836 $form = $form_helper->initForm(true);
837 }
838 $this->tpl->setContent($form->getHTML());
839
840 $this->showStatus(
841 ($this->getTestType() == self::TEST_TYPE_IT) ?
844 );
845 }
846
847 protected function testSettings(?ilPropertyFormGUI $form = null): void
848 {
849 $this->ctrl->setParameter($this, 'tt', $this->getTestType());
850 switch ($this->getTestType()) {
852 $this->tabs->activateSubTab('itest');
853 break;
854
856 $this->tabs->activateSubTab('qtest');
857 break;
858 }
859
860 if (!$form instanceof ilPropertyFormGUI) {
861 $form_helper = new ilLOTestAssignmentForm($this, $this->getParentObject(), $this->getTestType());
862 $form = $form_helper->initForm(false);
863 }
864 $this->tpl->setContent($form->getHTML());
865
866 $this->showStatus(
867 ($this->getTestType() == self::TEST_TYPE_IT) ?
870 );
871 }
872
873 protected function updateStartObjects(): void
874 {
875 $start = new ilContainerStartObjects(0, $this->getParentObject()->getId());
876 $this->getSettings()->updateStartObjects($start);
877 }
878
879 protected function saveMultiTestAssignment(): void
880 {
881 $this->ctrl->setParameter($this, 'tt', $this->initTestTypeFromQuery());
882 $this->setTestType($this->initTestTypeFromQuery());
883
885
886 $form_helper = new ilLOTestAssignmentForm($this, $this->getParentObject(), $this->getTestType());
887 $form = $form_helper->initForm(true);
888
889 if ($form->checkInput()) {
890 $mode = $form->getInput('mode');
891
892 if ($mode == self::TEST_NEW) {
893 $tst = new ilObjTest();
894 $tst->setType('tst');
895 $tst->setTitle($form->getInput('title'));
896 $tst->setDescription($form->getInput('desc'));
897 $tst->create();
898 $tst->saveToDb();
899 $tst->createReference();
900 $tst->putInTree($this->getParentObject()->getRefId());
901 $tst->setPermissions($this->getParentObject()->getRefId());
902 $general_settings = $tst->getMainSettings()->getGeneralSettings()->withQuestionSetType($form->getInput('qtype'));
903 $tst->getMainSettingsRepository()->store(
904 $tst->getMainSettings()->withGeneralSettings($general_settings)
905 );
906
907 $assignment = new ilLOTestAssignment();
908 $assignment->setContainerId($this->getParentObject()->getId());
909 $assignment->setAssignmentType($this->getTestType());
910 $assignment->setObjectiveId((int) $form->getInput('objective'));
911 $assignment->setTestRefId($tst->getRefId());
912 $assignment->save();
913 } else {
914 $assignment = new ilLOTestAssignment();
915 $assignment->setContainerId($this->getParentObject()->getId());
916 $assignment->setAssignmentType($this->getTestType());
917 $assignment->setObjectiveId((int) $form->getInput('objective'));
918 $assignment->setTestRefId((int) $form->getInput('tst'));
919 $assignment->save();
920
921 $tst = new ilObjTest((int) $form->getInput('tst'), true);
922 $tst->saveToDb();
923 }
924
925 // deassign as objective material
926 if ($tst instanceof ilObjTest) {
927 $this->updateMaterialAssignments($tst);
928 }
929 $this->updateStartObjects();
930
931 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
932 $this->ctrl->redirect($this, 'testsOverview');
933 }
934
935 // Error
936 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
937 $form->setValuesByPost();
938 $this->testAssignment($form);
939 }
940
941 protected function updateMaterialAssignments(ilObjTest $test): void
942 {
943 foreach (ilCourseObjective::_getObjectiveIds($this->getParentObject()->getId()) as $objective_id) {
944 $materials = new ilCourseObjectiveMaterials($objective_id);
945 foreach ($materials->getMaterials() as $material) {
946 if ($material['ref_id'] == $test->getRefId()) {
947 $materials->delete($material['lm_ass_id']);
948 }
949 }
950 }
951 }
952
953 protected function saveTest(): void
954 {
955 $this->ctrl->setParameter($this, 'tt', $this->initTestTypeFromQuery());
956 $this->setTestType($this->initTestTypeFromQuery());
957
959
960 $form_helper = new ilLOTestAssignmentForm($this, $this->getParentObject(), $this->getTestType());
961 $form = $form_helper->initForm(false);
962
963 if ($form->checkInput()) {
964 $mode = $form->getInput('mode');
965
966 if ($mode == self::TEST_NEW) {
967 $tst = new ilObjTest();
968 $tst->setType('tst');
969 $tst->setTitle($form->getInput('title'));
970 $tst->setDescription($form->getInput('desc'));
971 $tst->create();
972 $tst->saveToDb();
973 $tst->createReference();
974 $tst->putInTree($this->getParentObject()->getRefId());
975 $tst->setPermissions($this->getParentObject()->getRefId());
976 $general_settings = $tst->getMainSettings()->getGeneralSettings()->withQuestionSetType($form->getInput('qtype'));
977 $tst->getMainSettingsRepository()->store(
978 $tst->getMainSettings()->withGeneralSettings($general_settings)
979 );
980
981 if ($this->getTestType() == self::TEST_TYPE_IT) {
982 $this->getSettings()->setInitialTest($tst->getRefId());
983 } else {
984 $this->getSettings()->setQualifiedTest($tst->getRefId());
985 }
986 $this->getSettings()->update();
987 } else {
988 if ($this->getTestType() == self::TEST_TYPE_IT) {
989 $this->getSettings()->setInitialTest((int) $form->getInput('tst'));
990 } else {
991 $this->getSettings()->setQualifiedTest((int) $form->getInput('tst'));
992 }
993
994 $this->getSettings()->update();
995 $tst = new ilObjTest($settings->getTestByType($this->getTestType()), true);
996 $tst->saveToDb();
997 }
998
999 // deassign as objective material
1000 if ($tst instanceof ilObjTest) {
1001 $this->updateMaterialAssignments($tst);
1002 }
1003 $this->updateStartObjects();
1004
1005 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'));
1006 $this->ctrl->redirect($this, 'testOverview');
1007 }
1008
1009 // Error
1010 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'));
1011 $form->setValuesByPost();
1012 $this->testSettings($form);
1013 }
1014
1015 protected function listObjectives(): void
1016 {
1018 $this->tabs->activateSubTab('objectives');
1019
1021 $this->getParentObject()->getId(),
1022 false
1023 );
1024
1025 if ($objectives === []) {
1026 $this->showObjectiveCreation();
1027 return;
1028 }
1029
1030 $this->toolbar->addButton(
1031 $this->lng->txt('crs_add_objective'),
1032 $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', "create")
1033 );
1034
1035 $table = new ilCourseObjectivesTableGUI($this, $this->getParentObject());
1036 $table->setTitle($this->lng->txt('crs_objectives'), '', $this->lng->txt('crs_objectives'));
1037 $table->parse($objectives);
1038 $this->tpl->setContent($table->getHTML());
1039
1041 }
1042
1043 protected function showObjectiveCreation(?ilPropertyFormGUI $form = null): void
1044 {
1045 $this->tabs->activateSubTab('objectives');
1046 if (!$form instanceof ilPropertyFormGUI) {
1047 $form = $this->initSimpleObjectiveForm();
1048 }
1049 $this->tpl->setContent($form->getHTML());
1051 }
1052
1054 {
1055 $form = new ilPropertyFormGUI();
1056 $form->setTitle($this->lng->txt('crs_loc_form_create_objectives'));
1057 $form->setFormAction($this->ctrl->getFormAction($this));
1058
1059 $txt = new ilTextWizardInputGUI($this->lng->txt('crs_objectives'), 'objectives');
1060 $txt->setValues(array(0 => ''));
1061 $txt->setRequired(true);
1062 $form->addItem($txt);
1063
1064 $form->addCommandButton('saveObjectiveCreation', $this->lng->txt('save'));
1065 return $form;
1066 }
1067
1068 protected function saveObjectiveCreation(): void
1069 {
1070 $form = $this->initSimpleObjectiveForm();
1071 if ($form->checkInput()) {
1072 foreach ((array) $form->getInput('objectives') as $title) {
1073 $obj = new ilCourseObjective($this->getParentObject());
1074 $obj->setActive(true);
1075 $obj->setTitle($title);
1076 $obj->add();
1077 }
1078 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1079 $this->ctrl->redirect($this, '');
1080 }
1081
1082 $form->setValuesByPost();
1083 $this->tabs->activateSubTab('objectives');
1085 $this->showObjectiveCreation($form);
1086 }
1087
1088 protected function saveSorting(): void
1089 {
1090 $post_position = $this->http->wrapper()->post()->retrieve(
1091 'position',
1092 $this->refinery->kindlyTo()->dictOf(
1093 $this->refinery->kindlyTo()->string()
1094 )
1095 );
1096 asort($post_position, SORT_NUMERIC);
1097 $counter = 1;
1098 foreach ($post_position as $objective_id => $position) {
1099 $objective = new ilCourseObjective($this->getParentObject(), $objective_id);
1100 $objective->writePosition($counter++);
1101 }
1102 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('crs_objective_saved_sorting'));
1103 $this->listObjectives();
1104 }
1105
1106 protected function askDeleteObjectives(): void
1107 {
1108 $this->tabs->activateSubTab('objectives');
1109
1110 $confirm = new ilConfirmationGUI();
1111 $confirm->setFormAction($this->ctrl->getFormAction($this));
1112 $confirm->setHeaderText($this->lng->txt('crs_delete_objectve_sure'));
1113 $confirm->setConfirm($this->lng->txt('delete'), 'deleteObjectives');
1114 $confirm->setCancel($this->lng->txt('cancel'), 'listObjectives');
1115
1116 $objective_ids = [];
1117 if ($this->http->wrapper()->post()->has('objective')) {
1118 $objective_ids = $this->http->wrapper()->post()->retrieve(
1119 'objective',
1120 $this->refinery->kindlyTo()->dictOf(
1121 $this->refinery->kindlyTo()->int()
1122 )
1123 );
1124 }
1125 foreach ($objective_ids as $objective_id) {
1126 $obj = new ilCourseObjective($this->getParentObject(), $objective_id);
1127 $name = $obj->getTitle();
1128
1129 $confirm->addItem(
1130 'objective_ids[]',
1131 (string) $objective_id,
1132 $name
1133 );
1134 }
1135 $this->tpl->setContent($confirm->getHTML());
1137 }
1138
1139 protected function activateObjectives(): void
1140 {
1141 $enabled = $this->initObjectiveIdsFromPost();
1143 foreach ($objectives as $objective_id) {
1144 $objective = new ilCourseObjective($this->getParentObject(), $objective_id);
1145 if (in_array($objective_id, $enabled)) {
1146 $objective->setActive(true);
1147 $objective->update();
1148 }
1149 }
1151 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1152 $this->ctrl->redirect($this, 'listObjectives');
1153 }
1154
1155 protected function deactivateObjectives(): void
1156 {
1157 $disabled = $this->initObjectiveIdsFromPost();
1159 foreach ($objectives as $objective_id) {
1160 $objective = new ilCourseObjective($this->getParentObject(), $objective_id);
1161 if (in_array($objective_id, $disabled)) {
1162 $objective->setActive(false);
1163 $objective->update();
1164 }
1165 }
1167 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
1168 $this->ctrl->redirect($this, 'listObjectives');
1169 }
1170
1171 protected function deleteObjectives(): void
1172 {
1173 $objective_ids = [];
1174 if ($this->http->wrapper()->post()->has('objective_ids')) {
1175 $objective_ids = $this->http->wrapper()->post()->retrieve(
1176 'objective_ids',
1177 $this->refinery->kindlyTo()->dictOf(
1178 $this->refinery->kindlyTo()->int()
1179 )
1180 );
1181 }
1182 foreach ($objective_ids as $objective_id) {
1183 $objective_obj = new ilCourseObjective($this->getParentObject(), $objective_id);
1184 $objective_obj->delete();
1185 }
1187 $this->tpl->setOnScreenMessage('success', $this->lng->txt('crs_objectives_deleted'), true);
1188 $this->ctrl->redirect($this, 'listObjectives');
1189 }
1190
1191 protected function showStatus(int $a_section): void
1192 {
1193 $status = new ilLOEditorStatus($this->getParentObject());
1194 $status->setSection($a_section);
1195 $status->setCmdClass($this);
1196 $this->tpl->setRightContent($status->getHTML());
1197 }
1198
1199 protected function setTabs(string $a_section = ''): void
1200 {
1201 // objective settings
1202 $this->tabs->addSubTab(
1203 'settings',
1204 $this->lng->txt('settings'),
1205 $this->ctrl->getLinkTarget($this, 'settings')
1206 );
1207 // learning objectives
1208 $this->tabs->addSubTab(
1209 'objectives',
1210 $this->lng->txt('crs_loc_tab_objectives'),
1211 $this->ctrl->getLinkTarget($this, 'listObjectives')
1212 );
1213 // materials
1214 // tests
1216 if ($settings->worksWithInitialTest()) {
1217 if (
1220 ) {
1221 $this->ctrl->setParameter($this, 'tt', ilLOSettings::TYPE_TEST_INITIAL);
1222 $this->tabs->addSubTab(
1223 'itest',
1224 $this->lng->txt('crs_loc_tab_itest'),
1225 $this->ctrl->getLinkTarget($this, 'testOverview')
1226 );
1227 } else {
1228 $this->ctrl->setParameter($this, 'tt', ilLOSettings::TYPE_TEST_INITIAL);
1229 $this->tabs->addSubTab(
1230 'itests',
1231 $this->lng->txt('crs_loc_tab_itests'),
1232 $this->ctrl->getLinkTarget($this, 'testsOverview')
1233 );
1234 }
1235 }
1236
1238 $this->ctrl->setParameter($this, 'tt', ilLOSettings::TYPE_TEST_QUALIFIED);
1239 $this->tabs->addSubTab(
1240 'qtest',
1241 $this->lng->txt('crs_loc_tab_qtest'),
1242 $this->ctrl->getLinkTarget($this, 'testOverview')
1243 );
1244 } else {
1245 $this->ctrl->setParameter($this, 'tt', ilLOSettings::TYPE_TEST_QUALIFIED);
1246 $this->tabs->addSubTab(
1247 'qtests',
1248 $this->lng->txt('crs_loc_tab_qtests'),
1249 $this->ctrl->getLinkTarget($this, 'testsOverview')
1250 );
1251 }
1252
1254 $this->tabs->addSubTab(
1255 'start',
1256 $this->lng->txt('crs_loc_tab_start'),
1257 $this->ctrl->getLinkTargetByClass('ilcontainerstartobjectsgui', '')
1258 );
1259 }
1260
1261 // Member view
1262 #ilMemberViewGUI::showMemberViewSwitch($this->getParentObject()->getRefId());
1263 }
1264}
Builds data types.
Definition: Factory.php:36
External facade for object content styles.
This class represents a checkbox property in a property form.
class ilConditionHandlerGUI
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilContainerStartObjectsGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
class ilCourseObjectiveMaterials
class ilcourseobjective
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
static _getObjectiveIds(int $course_id, bool $a_activated_only=false)
class ilobjcourseobjectivesgui
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilLOEditorGUI.
ilCtrlInterface $ctrl
testOverview()
Show test overview.
ilLOSettings $settings
showObjectiveCreation(?ilPropertyFormGUI $form=null)
ilToolbarGUI $toolbar
showStatus(int $a_section)
updateTestAssignments(ilLOSettings $settings)
ilGlobalTemplateInterface $tpl
settings(?ilPropertyFormGUI $form=null)
ObjectFacade $content_style_domain
__construct(ilObjCourseGUI $parent_gui)
initSettingsForm()
Init settings form.
confirmDeleteTests()
Show delete test confirmation.
testSettings(?ilPropertyFormGUI $form=null)
updateMaterialAssignments(ilObjTest $test)
setTestType(int $a_type)
ilGlobalTemplateInterface $main_tpl
GlobalHttpState $http
confirmDeleteTest()
Show delete confirmation screen.
ilObjCourseGUI $parent_gui
deleteAssignments(int $a_type)
testAssignment(?ilPropertyFormGUI $form=null)
setTabs(string $a_section='')
Presentation of the status of single steps during the configuration process.
static getInstance(ilObject $a_parent)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
(Course) learning objective page GUI class
(Course) learning objective page object
Settings for LO courses.
const TYPE_INITIAL_QUALIFYING_ALL
const TYPE_INITIAL_PLACEMENT_SELECTED
static getInstanceByObjId(int $a_obj_id)
const HIDE_PASSED_OBJECTIVE_QST
setQualifyingTestAsStart(bool $a_type)
setQualifyingTestType(int $a_type)
const TYPE_INITIAL_PLACEMENT_ALL
worksWithStartObjects()
Check if start objects are enabled.
getTestByType(int $a_type)
const MARK_PASSED_OBJECTIVE_QST
resetResults(bool $a_status)
worksWithInitialTest()
Check if the loc is configured for initial tests.
setInitialTest(int $a_id)
setQualifiedTest(int $a_id)
const TYPE_QUALIFYING_SELECTED
const TYPE_INITIAL_QUALIFYING_SELECTED
setInitialTestType(int $a_type)
setInitialTestAsStart(bool $a_type)
setPassedObjectiveMode(int $a_mode)
Class ilLOTestAssignmentTableGUI.
Settings for LO courses.
static getInstance(int $a_container_id)
static _refreshStatus(int $a_obj_id, ?array $a_users=null)
language handling
Component logger with individual log levels by component id.
Class ilObjCourseGUI.
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
Class ilObject Basic functions for all objects.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
static set(string $a_var, $a_val)
Set a value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text wizard property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$txt
Definition: error.php:31
Interface GlobalHttpState.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26
$counter
$objectives