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