ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilMDOERSettingsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
23 protected ilCtrl $ctrl;
25 protected ilLanguage $lng;
28
29 protected ?ilMDSettings $md_settings = null;
30
32 {
33 global $DIC;
34
35 $this->ctrl = $DIC->ctrl();
36 $this->lng = $DIC->language();
37 $this->tpl = $DIC->ui()->mainTemplate();
38
39 $this->parent_obj_gui = $parent_obj_gui;
40 $this->access_service = new ilMDSettingsAccessService(
41 $this->parent_obj_gui->getRefId(),
42 $DIC->access()
43 );
44
45 $this->lng->loadLanguageModule("meta");
46 }
47
48 public function executeCommand(): void
49 {
50 $next_class = $this->ctrl->getNextClass($this);
51 $cmd = $this->ctrl->getCmd();
52
53 if (!$this->access_service->hasCurrentUserReadAccess()) {
54 throw new ilPermissionException($this->lng->txt('no_permission'));
55 }
56
57 switch ($next_class) {
58 default:
59 if (!$cmd || $cmd === 'view') {
60 $cmd = 'showOERSettings';
61 }
62
63 $this->$cmd();
64 break;
65 }
66 }
67
68 public function showOERSettings(?ilPropertyFormGUI $form = null): void
69 {
70 if (!$form instanceof ilPropertyFormGUI) {
71 $form = $this->initSettingsForm();
72 }
73 $this->tpl->setContent($form->getHTML());
74 }
75
76 public function saveOERSettings(): void
77 {
78 if (!$this->access_service->hasCurrentUserWriteAccess()) {
79 $this->ctrl->redirect($this, "showOERSettings");
80 }
81 $form = $this->initSettingsForm();
82 if ($form->checkInput()) {
83 $this->MDSettings()->activateCopyrightSelection((bool) $form->getInput('active'));
84 $this->tpl->setOnScreenMessage('success', $this->lng->txt('settings_saved'), true);
85 $this->ctrl->redirect($this, 'showOERSettings');
86 }
87 $this->tpl->setOnScreenMessage('failure', $this->lng->txt('err_check_input'), true);
88 $form->setValuesByPost();
89 $this->showOERSettings($form);
90 }
91
92 protected function initSettingsForm(): ilPropertyFormGUI
93 {
94 $form = new ilPropertyFormGUI();
95 $form->setFormAction($this->ctrl->getFormAction($this));
96
97 if ($this->access_service->hasCurrentUserWriteAccess()) {
98 $form->addCommandButton('saveOERSettings', $this->lng->txt('save'));
99 }
100
101 $header = new ilFormSectionHeaderGUI();
102 $header->setTitle($this->lng->txt('md_settings_licence'));
103 $form->addItem($header);
104
105 $check = new ilCheckboxInputGUI($this->lng->txt('md_copyright_enabled'), 'active');
106 $check->setChecked($this->MDSettings()->isCopyrightSelectionActive());
107 $check->setValue('1');
108 $check->setInfo($this->lng->txt('md_copyright_enable_info'));
109 $form->addItem($check);
110
111 return $form;
112 }
113
114 protected function MDSettings(): ilMDSettings
115 {
116 if (!isset($this->md_settings)) {
117 $this->md_settings = ilMDSettings::_getInstance();
118 }
119 return $this->md_settings;
120 }
121}
$check
Definition: buildRTE.php:81
This class represents a checkbox property in a property form.
Class ilCtrl provides processing control methods.
This class represents a section header in a property form.
language handling
__construct(ilObjMDSettingsGUI $parent_obj_gui)
ilObjMDSettingsGUI $parent_obj_gui
ilMDSettingsAccessService $access_service
showOERSettings(?ilPropertyFormGUI $form=null)
ilGlobalTemplateInterface $tpl
This class represents a property form user interface.
global $DIC
Definition: shib_login.php:26