ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjDataProtectionGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
36 
43 {
45  private readonly Container $container;
46  private readonly Config $config;
48  private readonly UI $ui;
49 
50  public function __construct()
51  {
52  parent::__construct(...func_get_args());
53  global $DIC;
54  $this->container = $DIC;
55  $config = new Config($DIC['legalDocuments']->provide(Consumer::ID));
56  if ($this->rbac_system->checkAccess('write', $this->object->getRefId())) {
57  $config = $config->allowEditing();
58  }
59  $this->config = $config;
60  $this->legal_documents = new ilLegalDocumentsAdministrationGUI(self::class, $config, $this->afterDocumentDeletion(...));
61 
62  $this->data_protection_settings = $this->createDataProtectionSettings();
63  $this->ui = new UI($this->getType(), $this->container->ui(), $this->container->language());
64  }
65 
66  public function getType(): string
67  {
68  return 'dpro';
69  }
70 
71  public function executeCommand(): void
72  {
73  $this->requireReadable();
74  $this->prepareOutput();
75 
76  $this->container->language()->loadLanguageModule('dpro');
77  $this->container->language()->loadLanguageModule('ldoc');
78 
79  $next_class = $this->ctrl->getNextClass($this);
80  $cmd = $this->ctrl->getCmd('settings');
81 
82  switch (strtolower($next_class)) {
83  case strtolower(ilLegalDocumentsAdministrationGUI::class):
84  if ($cmd === 'documents') {
85  $this->documents();
86  }
87  $this->ctrl->forwardCommand($this->legal_documents);
88  return;
89  case strtolower(ilPermissionGUI::class):
90  $this->tabs_gui->activateTab('permissions');
91  $this->ctrl->forwardCommand(new ilPermissionGUI($this));
92  return;
93  default:
94  switch ($cmd) {
95  case 'documents':
96  $this->ctrl->redirectByClass(ilLegalDocumentsAdministrationGUI::class, 'documents');
97  break;
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  $enabled = $this->optionalGroup('status_enable', 'status_enable_desc', [
179  'type' => $this->radio('mode', [
180  'once' => 'once',
181  'eval_on_login' => 'reevaluate_on_login',
182  'no_acceptance' => 'no_acceptance',
183  ])->withValue(
184  $this->data_protection_settings->validateOnLogin()->value() ?
185  'eval_on_login' :
186  ($this->data_protection_settings->noAcceptance()->value() ? 'no_acceptance' : 'once')
187  )->withRequired(true),
188  ]);
189 
190  $enabled = $enabled->withValue($this->data_protection_settings->enabled()->value() ? [
191  'type' => $this->data_protection_settings->validateOnLogin()->value() ?
192  'eval_on_login' :
193  ($this->data_protection_settings->noAcceptance()->value() ? 'no_acceptance' : 'once'),
194  ] : null);
195 
196  $enabled = $enabled->withDisabled(!$this->config->editable())->withRequired(true);
197 
198  $form = $this->ui->create()->input()->container()->form()->standard(
199  $this->ctrl->getFormAction($this, 'settings'),
200  ['enabled' => $enabled]
201  );
202 
203  if (!$this->config->editable()) {
204  $form = $form->withSubmitLabel($this->lng->txt('refresh'));
205  return $this->legal_documents->admin()->withFormData($form, function () {
206  $this->ctrl->redirect($this, 'settings');
207  });
208  }
209 
210  return $this->legal_documents->admin()->withFormData($form, function (array $data): void {
211  $no_documents = $this->config->legalDocuments()->document()->repository()->countAll() === 0;
212  if ($no_documents && isset($data['enabled'])) {
213  $this->tpl->setOnScreenMessage('failure', $this->ui->txt('no_documents_exist_cant_save'), true);
214  $this->ctrl->redirect($this, 'settings');
215  }
216  $type = $data['enabled']['type'] ?? false;
217  $this->data_protection_settings->enabled()->update(isset($data['enabled']));
218  if (isset($data['enabled'])) {
219  $this->data_protection_settings->validateOnLogin()->update($type === 'eval_on_login');
220  $this->data_protection_settings->noAcceptance()->update($type === 'no_acceptance');
221  }
222 
223  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
224  $this->ctrl->redirect($this, 'settings');
225  });
226  }
227 
228  private function optionalGroup(string $label, string $description, array $fields): OptionalGroup
229  {
230  return $this->ui->create()->input()->field()->optionalGroup(
231  $fields,
232  $this->ui->txt($label),
233  $this->ui->txt($description)
234  );
235  }
236 
237  private function radio(string $prefix, array $options): Component
238  {
239  $field = $this->ui->create()->input()->field()->radio($this->ui->txt($prefix), $this->ui->txt($prefix . '_desc'));
240  foreach ($options as $key => $label) {
241  $field = $field->withOption((string) $key, $this->ui->txt($label));
242  }
243  return $field;
244  }
245 
247  {
248  $store = new ILIASSettingStore($this->container->settings());
249  return new Settings(new SelectSetting(
250  $this->config->editable() ? $store : new ReadOnlyStore($store),
251  new Marshal($this->container->refinery())
252  ));
253  }
254 
255  private function documents(): void
256  {
257  $buttons = $this->config->editable() ?
258  [$this->legal_documents->admin()->resetButton($this->ctrl->getLinkTarget($this, 'confirmReset'))] :
259  [];
260 
261  $reset_date = $this->data_protection_settings->lastResetDate()->value();
262  $this->tpl->setCurrentBlock('mess');
263  $this->legal_documents->admin()->setVariable('MESSAGE', $this->legal_documents->admin()->resetBox($reset_date, $buttons));
264  $this->tpl->parseCurrentBlock('mess');
265  }
266 }
bool $enabled
Whether the system instance is enabled to accept connection requests.
Definition: System.php:123
const ANONYMOUS_USER_ID
Definition: constants.php:27
New implementation of ilObjectGUI.
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes optional group inputs.
radio(string $prefix, array $options)
prepareOutput(bool $show_sub_objects=true)
ilObjDataProtectionGUI: ilAdministrationGUI ilObjDataProtectionGUI: ilLegalDocumentsAdministrationGU...
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
global $DIC
Definition: feed.php:28
readonly ilLegalDocumentsAdministrationGUI $legal_documents
__construct(VocabulariesInterface $vocabularies)
optionalGroup(string $label, string $description, array $fields)
string $key
Consumer key/client ID value.
Definition: System.php:193
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:58
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.