ILIAS  release_8 Revision v8.24
class.ilObjTermsOfServiceGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
32
36 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
37 {
38 global $DIC;
39
40 $this->dic = $DIC;
41 $this->lng = $DIC->language();
42 $this->error = $DIC['ilErr'];
43
44 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
45
46 $this->lng->loadLanguageModule('tos');
47 $this->lng->loadLanguageModule('meta');
48 }
49
50 public function getType(): string
51 {
52 return 'tos';
53 }
54
55 public function executeCommand(): void
56 {
57 $this->prepareOutput();
58
59 $nextClass = $this->ctrl->getNextClass($this);
60 $cmd = $this->ctrl->getCmd();
61
62 $tableDataProviderFactory = new ilTermsOfServiceTableDataProviderFactory();
63 $tableDataProviderFactory->setDatabaseAdapter($this->dic->database());
64
65 switch (strtolower($nextClass)) {
66 case strtolower(ilTermsOfServiceDocumentGUI::class):
68 $obj = $this->object;
69 $documentGui = new ilTermsOfServiceDocumentGUI(
70 $obj,
71 $this->dic['tos.criteria.type.factory'],
72 $this->dic->ui()->mainTemplate(),
73 $this->dic->user(),
74 $this->dic->ctrl(),
75 $this->dic->language(),
76 $this->dic->rbac()->system(),
77 $this->dic['ilErr'],
78 $this->dic->logger()->tos(),
79 $this->dic->toolbar(),
80 $this->dic->http(),
81 $this->dic->ui()->factory(),
82 $this->dic->ui()->renderer(),
83 $this->dic->filesystem(),
84 $this->dic->upload(),
85 $tableDataProviderFactory,
87 $this->dic->refinery()
88 );
89 $this->ctrl->forwardCommand($documentGui);
90 break;
91
92 case strtolower(ilTermsOfServiceAcceptanceHistoryGUI::class):
94 $obj = $this->object;
95 $documentGui = new ilTermsOfServiceAcceptanceHistoryGUI(
96 $obj,
97 $this->dic['tos.criteria.type.factory'],
98 $this->dic->ui()->mainTemplate(),
99 $this->dic->ctrl(),
100 $this->dic->language(),
101 $this->dic->rbac()->system(),
102 $this->dic['ilErr'],
103 $this->dic->http(),
104 $this->dic->refinery(),
105 $this->dic->ui()->factory(),
106 $this->dic->ui()->renderer(),
107 $tableDataProviderFactory,
108 );
109 $this->ctrl->forwardCommand($documentGui);
110 break;
111
112 case strtolower(ilPermissionGUI::class):
113 $perm_gui = new ilPermissionGUI($this);
114 $this->ctrl->forwardCommand($perm_gui);
115 break;
116
117 default:
118 if ($cmd === null || $cmd === '' || $cmd === 'view' || !method_exists($this, $cmd)) {
119 $cmd = 'settings';
120 }
121 $this->$cmd();
122 break;
123 }
124 }
125
126 public function getAdminTabs(): void
127 {
128 if ($this->rbac_system->checkAccess('read', $this->object->getRefId())) {
129 $this->tabs_gui->addTarget(
130 'tos_agreement_documents_tab_label',
131 $this->ctrl->getLinkTargetByClass(ilTermsOfServiceDocumentGUI::class),
132 '',
133 [strtolower(ilTermsOfServiceDocumentGUI::class)]
134 );
135 }
136
137 if ($this->rbac_system->checkAccess('read', $this->object->getRefId())) {
138 $this->tabs_gui->addTarget(
139 'settings',
140 $this->ctrl->getLinkTarget($this, 'settings'),
141 '',
142 [strtolower(self::class)]
143 );
144 }
145
146 if (
147 (defined('USER_FOLDER_ID') && $this->rbac_system->checkAccess('read', USER_FOLDER_ID)) &&
148 $this->rbac_system->checkAccess('read', $this->object->getRefId())
149 ) {
150 $this->tabs_gui->addTarget(
151 'tos_acceptance_history',
152 $this->ctrl->getLinkTargetByClass(ilTermsOfServiceAcceptanceHistoryGUI::class),
153 '',
154 [strtolower(ilTermsOfServiceAcceptanceHistoryGUI::class)]
155 );
156 }
157
158 if ($this->rbac_system->checkAccess('edit_permission', $this->object->getRefId())) {
159 $this->tabs_gui->addTarget(
160 'perm_settings',
161 $this->ctrl->getLinkTargetByClass([self::class, ilPermissionGUI::class], 'perm'),
162 '',
163 [strtolower(ilPermissionGUI::class), strtolower(ilObjectPermissionStatusGUI::class)]
164 );
165 }
166 }
167
168 protected function getSettingsForm(): ilTermsOfServiceSettingsFormGUI
169 {
171 $obj = $this->object;
173 $obj,
174 $this->ctrl->getFormAction($this, 'saveSettings'),
175 'saveSettings',
176 $this->rbac_system->checkAccess('write', $this->object->getRefId())
177 );
178
181 $form,
182 $this
183 );
184
185 return $form;
186 }
187
188 protected function saveSettings(): void
189 {
190 if (!$this->rbac_system->checkAccess('write', $this->object->getRefId())) {
191 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
192 }
193
194 $form = $this->getSettingsForm();
195 if ($form->saveObject()) {
196 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
197 $this->ctrl->redirect($this, 'settings');
198 } elseif ($form->hasTranslatedError()) {
199 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError());
200 }
201
202 $this->tpl->setContent($form->getHTML());
203 }
204
205 protected function showMissingDocuments(): void
206 {
207 if ($this->object->getStatus()) {
208 return;
209 }
210
211 if (0 === ilTermsOfServiceDocument::where([])->count()) {
212 $this->tpl->setOnScreenMessage('info', $this->lng->txt('tos_no_documents_exist'));
213 }
214 }
215
216 protected function settings(): void
217 {
218 if (!$this->rbac_system->checkAccess('read', $this->object->getRefId())) {
219 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
220 }
221
222 $this->showMissingDocuments();
223
224 $form = $this->getSettingsForm();
225 $this->tpl->setContent($form->getHTML());
226 }
227}
static where($where, $operator=null)
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
error(string $a_errmsg)
static addFieldsToForm(int $a_form_id, ilPropertyFormGUI $a_form, ilObjectGUI $a_parent_gui)
Error Handling & global info handling uses PEAR error class.
__construct($a_id=0, $a_id_type=self::REPOSITORY_NODE_ID, $a_parent_node_id=0)
getType()
Functions that must be overwritten.
getAdminTabs()
administration tabs show only permissions and trash folder
New implementation of ilObjectGUI.
executeCommand()
execute command
prepareOutput(bool $show_sub_objects=true)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
Class ilTermsOfServiceDocumentGUI.
Class ilTermsOfServiceSettingsFormGUI.
const USER_FOLDER_ID
Definition: constants.php:33
global $DIC
Definition: feed.php:28
Interface ilTermsOfServiceControllerEnabled.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc