ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjDataProtectionGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
32use ILIAS\Data\Factory as DataFactory;
35
42{
44 private readonly Container $container;
45 private readonly Config $config;
47 private readonly UI $ui;
48
49 public function __construct()
50 {
51 parent::__construct(...func_get_args());
52 global $DIC;
53 $this->container = $DIC;
54 $config = new Config($DIC['legalDocuments']->provide(Consumer::ID));
55 if ($this->rbac_system->checkAccess('write', $this->object->getRefId())) {
57 }
58 $this->config = $config;
59 $this->legal_documents = new ilLegalDocumentsAdministrationGUI(self::class, $config, $this->afterDocumentDeletion(...));
60
61 $this->data_protection_settings = $this->createDataProtectionSettings();
62 $this->ui = new UI($this->getType(), $this->container->ui(), $this->container->language());
63 }
64
65 public function getType(): string
66 {
67 return 'dpro';
68 }
69
70 public function executeCommand(): void
71 {
72 $this->requireReadable();
73 $this->prepareOutput();
74
75 $this->container->language()->loadLanguageModule('dpro');
76 $this->container->language()->loadLanguageModule('ldoc');
77
78 $next_class = $this->ctrl->getNextClass($this) ?? '';
79 $cmd = $this->ctrl->getCmd('settings');
80
81 switch (strtolower($next_class)) {
82 case strtolower(ilLegalDocumentsAdministrationGUI::class):
83 if ($cmd === 'documents') {
84 $this->documents();
85 }
86 $this->ctrl->forwardCommand($this->legal_documents);
87 return;
88 case strtolower(ilPermissionGUI::class):
89 $this->tabs_gui->activateTab('permissions');
90 $this->ctrl->forwardCommand(new ilPermissionGUI($this));
91 return;
92 default:
93 switch ($cmd) {
94 case 'documents':
95 $this->ctrl->redirectByClass(ilLegalDocumentsAdministrationGUI::class, 'documents');
96 break;
97
98 default:
99 $reflection = new ReflectionClass(self::class);
100 if (!$reflection->hasMethod($cmd) || !$reflection->getMethod($cmd)->isPublic()) {
101 throw new Exception('Undefined command.');
102 }
103 $this->$cmd();
104 }
105 }
106 }
107
108 public function view(): void
109 {
110 $this->settings();
111 }
112
113 public function settings(): void
114 {
115 $this->container->tabs()->activateTab('settings');
116
117 $components = [];
118
119 if ($this->data_protection_settings->enabled()->value() && $this->config->legalDocuments()->document()->repository()->countAll() === 0) {
120 $components[] = $this->ui->create()->messageBox()->info(
121 $this->ui->txt('no_documents_exist')
122 );
123 }
124
125 $components[] = $this->legal_documents->admin()->externalSettingsMessage($this->data_protection_settings->deleteUserOnWithdrawal()->value());
126
127 $components[] = $this->form();
128 $this->tpl->setContent($this->container->ui()->renderer()->render($components));
129 }
130
131 public function confirmReset(): void
132 {
133 $this->container->tabs()->activateTab('documents');
134 $this->legal_documents->admin()->requireEditable();
135 $this->legal_documents->admin()->setContent((new Confirmation($this->lng))->render(
136 $this->ctrl->getFormAction($this, 'resetNow'),
137 'resetNow',
138 'documents',
139 $this->ui->txt('sure_reset_tos')
140 ));
141 }
142
143 public function resetNow(): void
144 {
145 $this->legal_documents->admin()->requireEditable();
146
147 $in = $this->container->database()->in('usr_id', [ANONYMOUS_USER_ID, SYSTEM_USER_ID], true, 'integer');
148 $this->container->database()->manipulate("delete from usr_pref WHERE keyword = 'dpro_agree_date' AND $in");
149 $this->data_protection_settings->lastResetDate()->update((new DataFactory())->clock()->system()->now());
150 $this->ctrl->redirect($this->legal_documents, 'documents');
151 }
152
153 public function getAdminTabs(): void
154 {
155 $this->container->language()->loadLanguageModule('tos');
156 $this->legal_documents->tabs([
157 'documents' => fn() => $this->tabs_gui->addTab('settings', $this->ui->txt('settings'), $this->ctrl->getLinkTarget($this, 'settings')),
158 ]);
159 $this->tabs_gui->addTab('permissions', $this->ui->txt('perm_settings'), $this->ctrl->getLinkTargetByClass([self::class, ilPermissionGUI::class], 'perm'));
160 }
161
162 public function afterDocumentDeletion(): void
163 {
164 if ($this->config->legalDocuments()->document()->repository()->countAll() === 0) {
165 $this->data_protection_settings->enabled()->update(false);
166 }
167 }
168
169 private function requireReadable(): void
170 {
171 if (!$this->rbac_system->checkAccess('read', $this->object->getRefId())) {
172 $this->error->raiseError($this->container->language()->txt('msg_no_perm_read'), $this->error->WARNING);
173 }
174 }
175
176 private function form(): Component
177 {
178 $no_documents = $this->config->legalDocuments()->document()->repository()->countAll() === 0;
179 if ($no_documents) {
180 $this->tpl->setOnScreenMessage('info', $this->ui->txt('no_documents_exist'), true);
181 }
182
183 $enabled = $this->optionalGroup('status_enable', 'status_enable_desc', [
184 'type' => $this->radio('mode', [
185 'once' => 'once',
186 'eval_on_login' => 'reevaluate_on_login',
187 'no_acceptance' => 'no_acceptance',
188 ])->withValue(
189 $this->data_protection_settings->validateOnLogin()->value() ?
190 'eval_on_login' :
191 ($this->data_protection_settings->noAcceptance()->value() ? 'no_acceptance' : 'once')
192 )->withRequired(true),
193 ]);
194
195 $enabled = $enabled->withValue($this->data_protection_settings->enabled()->value() ? [
196 'type' => $this->data_protection_settings->validateOnLogin()->value() ?
197 'eval_on_login' :
198 ($this->data_protection_settings->noAcceptance()->value() ? 'no_acceptance' : 'once'),
199 ] : null);
200
201 $enabled = $enabled->withDisabled(!$this->config->editable())->withRequired(true);
202
203 $form = $this->ui->create()->input()->container()->form()->standard(
204 $this->ctrl->getFormAction($this, 'settings'),
205 ['enabled' => $enabled]
206 );
207
208 if (!$this->config->editable()) {
209 $form = $form->withSubmitLabel($this->lng->txt('refresh'));
210 return $this->legal_documents->admin()->withFormData($form, function () {
211 $this->ctrl->redirect($this, 'settings');
212 });
213 }
214
215 return $this->legal_documents->admin()->withFormData($form, function (array $data) use ($no_documents): void {
216 if ($no_documents && isset($data['enabled'])) {
217 $this->tpl->setOnScreenMessage('failure', $this->ui->txt('no_documents_exist_cant_save'), true);
218 $this->ctrl->redirect($this, 'settings');
219 }
220 $type = $data['enabled']['type'] ?? false;
221 $this->data_protection_settings->enabled()->update(isset($data['enabled']));
222 if (isset($data['enabled'])) {
223 $this->data_protection_settings->validateOnLogin()->update($type === 'eval_on_login');
224 $this->data_protection_settings->noAcceptance()->update($type === 'no_acceptance');
225 }
226
227 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
228 $this->ctrl->redirect($this, 'settings');
229 });
230 }
231
235 private function optionalGroup(string $label, string $description, array $fields): OptionalGroup
236 {
237 return $this->ui->create()->input()->field()->optionalGroup(
238 $fields,
239 $this->ui->txt($label),
240 $this->ui->txt($description)
241 );
242 }
243
247 private function radio(string $prefix, array $options): Component
248 {
249 $field = $this->ui->create()->input()->field()->radio($this->ui->txt($prefix), $this->ui->txt($prefix . '_desc'));
250 foreach ($options as $key => $label) {
251 $field = $field->withOption((string) $key, $this->ui->txt($label));
252 }
253 return $field;
254 }
255
257 {
258 $store = new ILIASSettingStore($this->container->settings());
259 return new Settings(new SelectSetting(
260 $this->config->editable() ? $store : new ReadOnlyStore($store),
261 new Marshal($this->container->refinery())
262 ));
263 }
264
265 private function documents(): void
266 {
267 $buttons = $this->config->editable() ?
268 [$this->legal_documents->admin()->resetButton($this->ctrl->getLinkTarget($this, 'confirmReset'))] :
269 [];
270
271 $reset_date = $this->data_protection_settings->lastResetDate()->value();
272 $this->tpl->setCurrentBlock('mess');
273 $this->legal_documents->admin()->setVariable('MESSAGE', $this->legal_documents->admin()->resetBox($reset_date, $buttons));
274 $this->tpl->parseCurrentBlock('mess');
275 }
276}
$components
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Builds data types.
Definition: Factory.php:36
error(string $a_errmsg)
@ilCtrl_isCalledBy ilObjDataProtectionGUI: ilAdministrationGUI @ilCtrl_Calls ilObjDataProtectionGUI: ...
optionalGroup(string $label, string $description, array $fields)
view()
view object content (repository/workspace switch)
getType()
Functions that must be overwritten.
readonly ilLegalDocumentsAdministrationGUI $legal_documents
radio(string $prefix, array $options)
getAdminTabs()
administration tabs show only permissions and trash folder
New implementation of ilObjectGUI.
prepareOutput(bool $show_sub_objects=true)
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
const ANONYMOUS_USER_ID
Definition: constants.php:27
A component is the most general form of an entity in the UI.
Definition: Component.php:28
This describes optional group inputs.
This describes commonalities between all inputs.
Definition: Input.php:47
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
global $DIC
Definition: shib_login.php:26