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