ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAccessibilityDocumentGUI.php
Go to the documentation of this file.
1<?php
2
24
29{
33 protected ilCtrl $ctrl;
34 protected ilLanguage $lng;
37 protected ilObjUser $user;
38 protected ilLogger $log;
47
48 public function __construct(
66 ) {
67 $this->accs = $accs;
68 $this->criterionTypeFactory = $criterionTypeFactory;
69 $this->tpl = $tpl;
70 $this->ctrl = $ctrl;
71 $this->lng = $lng;
72 $this->rbacsystem = $rbacsystem;
73 $this->error = $error;
74 $this->user = $user;
75 $this->log = $log;
76 $this->toolbar = $toolbar;
77 $this->httpState = $httpState;
78 $this->uiFactory = $uiFactory;
79 $this->uiRenderer = $uiRenderer;
80 $this->fileSystems = $fileSystems;
81 $this->fileUpload = $fileUpload;
82 $this->tableDataProviderFactory = $tableDataProviderFactory;
83 $this->documentPurifier = $documentPurifier;
84 }
85
86 public function executeCommand(): void
87 {
88 $cmd = $this->ctrl->getCmd();
89
90 if (!$this->rbacsystem->checkAccess('read', $this->accs->getRefId())) {
91 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
92 }
93
94 if ($cmd == '' || !method_exists($this, $cmd)) {
95 $cmd = 'showDocuments';
96 }
97 $this->$cmd();
98 }
99
100
105 protected function showDocuments(): void
106 {
107 if ($this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
108 $addDocumentBtn = $this->uiFactory->button()->primary(
109 $this->lng->txt('acc_add_document_btn_label'),
110 $this->ctrl->getLinkTarget($this, 'showAddDocumentForm')
111 );
112 $this->toolbar->addStickyItem($addDocumentBtn);
113 }
114
115 $documentTableGui = new ilAccessibilityDocumentTableGUI(
116 $this,
117 'showDocuments',
118 $this->criterionTypeFactory,
119 $this->uiFactory,
120 $this->uiRenderer,
121 $this->rbacsystem->checkAccess('write', $this->accs->getRefId())
122 );
123 $documentTableGui->setProvider($this->tableDataProviderFactory->getByContext(ilAccessibilityTableDataProviderFactory::CONTEXT_DOCUMENTS));
124 $documentTableGui->populate();
125
126 $this->tpl->setContent($documentTableGui->getHTML());
127 }
128
133 {
134 if ($document->getId() > 0) {
135 $this->ctrl->setParameter($this, 'acc_id', $document->getId());
136 }
137
138 $formAction = $this->ctrl->getFormAction($this, 'saveAddDocumentForm');
139 $saveCommand = 'saveAddDocumentForm';
140
141 if ($document->getId() > 0) {
142 $formAction = $this->ctrl->getFormAction($this, 'saveEditDocumentForm');
143 $saveCommand = 'saveEditDocumentForm';
144 }
145
147 $document,
148 $this->documentPurifier,
149 $this->user,
150 $this->fileSystems->temp(),
151 $this->fileUpload,
152 $formAction,
153 $saveCommand,
154 'showDocuments',
155 $this->rbacsystem->checkAccess('write', $this->accs->getRefId())
156 );
157
158 return $form;
159 }
160
161 protected function saveAddDocumentForm(): void
162 {
163 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
164 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
165 }
166
167 $form = $this->getDocumentForm(new ilAccessibilityDocument());
168 if ($form->saveObject()) {
169 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
170 if ($form->hasTranslatedInfo()) {
171 $this->tpl->setOnScreenMessage('info', $form->getTranslatedInfo(), true);
172 }
173 $this->ctrl->redirect($this, 'showDocuments');
174 } elseif ($form->hasTranslatedError()) {
175 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError());
176 }
177
178 $this->tpl->setContent($form->getHTML());
179 }
180
181 protected function showAddDocumentForm(): void
182 {
183 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
184 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
185 }
186
187 $form = $this->getDocumentForm(new ilAccessibilityDocument());
188 $this->tpl->setContent($form->getHTML());
189 }
190
191 protected function showEditDocumentForm(): void
192 {
193 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
194 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
195 }
196
197 $document = $this->getFirstDocumentFromList($this->getDocumentsByServerRequest());
198
199 $form = $this->getDocumentForm($document);
200 $this->tpl->setContent($form->getHTML());
201 }
202
203 protected function saveEditDocumentForm(): void
204 {
205 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
206 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
207 }
208
209 $document = $this->getFirstDocumentFromList($this->getDocumentsByServerRequest());
210
211 $form = $this->getDocumentForm($document);
212 if ($form->saveObject()) {
213 $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
214 if ($form->hasTranslatedInfo()) {
215 $this->tpl->setOnScreenMessage('info', $form->getTranslatedInfo(), true);
216 }
217 $this->ctrl->redirect($this, 'showDocuments');
218 } elseif ($form->hasTranslatedError()) {
219 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError());
220 }
221
222 $this->tpl->setContent($form->getHTML());
223 }
224
228 protected function getDocumentsByServerRequest(): array
229 {
230 $documents = [];
231
232 $documentIds = $this->httpState->request()->getParsedBody()['acc_id'] ?? [];
233 if (!is_array($documentIds) || 0 === count($documentIds)) {
234 $documentIds = $this->httpState->request()->getQueryParams()['acc_id'] ? [$this->httpState->request()->getQueryParams()['acc_id']] : [];
235 }
236
237 if (0 === count($documentIds)) {
238 return $documents;
239 }
240
242 ['id' => array_filter(array_map('intval', $documentIds))],
243 ['id' => 'IN']
244 )->getArray();
245
246 return $documents;
247 }
248
254 protected function getFirstDocumentFromList(array $documents): ilAccessibilityDocument
255 {
256 if (1 !== count($documents)) {
257 throw new UnexpectedValueException('Expected exactly one document in list');
258 }
259
260 $document = new ilAccessibilityDocument(0);
262 $document = $document->buildFromArray(current($documents));
263
264 return $document;
265 }
266
267 protected function deleteDocuments(): void
268 {
269 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
270 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
271 }
272
273 $documents = $this->getDocumentsByServerRequest();
274 if (0 === count($documents)) {
275 $this->showDocuments();
276 return;
277 } else {
278 $documents = array_map(function (array $data) {
279 $document = new ilAccessibilityDocument(0);
280 $document = $document->buildFromArray($data);
281
282 return $document;
283 }, $documents);
284 }
285
286 $isDeletionRequest = (bool) ($this->httpState->request()->getQueryParams()['delete'] ?? false);
287 if ($isDeletionRequest) {
288 $this->processDocumentDeletion($documents);
289
290 $this->ctrl->redirect($this);
291 } else {
292 $this->ctrl->setParameter($this, 'delete', 1);
293 $confirmation = new ilConfirmationGUI();
294 $confirmation->setFormAction($this->ctrl->getFormAction($this, 'deleteDocuments'));
295 $confirmation->setConfirm($this->lng->txt('confirm'), 'deleteDocuments');
296 $confirmation->setCancel($this->lng->txt('cancel'), 'showDocuments');
297
298 $confirmation->setHeaderText($this->lng->txt('acc_sure_delete_documents_p'));
299 if (1 === count($documents)) {
300 $confirmation->setHeaderText($this->lng->txt('acc_sure_delete_documents_s'));
301 }
302
303 foreach ($documents as $document) {
305 $confirmation->addItem('acc_id[]', $document->getId(), implode(' | ', [
306 $document->getTitle()
307 ]));
308 }
309
310 $this->tpl->setContent($confirmation->getHTML());
311 }
312 }
313
314 protected function processDocumentDeletion(array $documents): void
315 {
316 foreach ($documents as $document) {
318 $document->delete();
319 }
320
321 $this->tpl->setOnScreenMessage('success', $this->lng->txt('acc_deleted_documents_p'), true);
322 if (1 === count($documents)) {
323 $this->tpl->setOnScreenMessage('success', $this->lng->txt('acc_deleted_documents_s'), true);
324 }
325 }
326
327 protected function deleteDocument(): void
328 {
329 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
330 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
331 }
332
333 $document = $this->getFirstDocumentFromList($this->getDocumentsByServerRequest());
334
335 $this->processDocumentDeletion([$document]);
336
337 $this->ctrl->redirect($this);
338 }
339
340 protected function saveDocumentSorting(): void
341 {
342 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
343 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
344 }
345
346 $sorting = $this->httpState->request()->getParsedBody()['sorting'] ?? [];
347 if (!is_array($sorting) || 0 === count($sorting)) {
348 $this->showDocuments();
349 return;
350 }
351
352 asort($sorting, SORT_NUMERIC);
353
354 $position = 0;
355 foreach ($sorting as $documentId => $ignoredSortValue) {
356 if (!is_numeric($documentId)) {
357 continue;
358 }
359
360 try {
361 $document = new ilAccessibilityDocument((int) $documentId);
362 $document->setSorting(++$position);
363 $document->store();
364 } catch (ilException $e) {
365 // Empty catch block
366 }
367 }
368
369 $this->tpl->setOnScreenMessage('success', $this->lng->txt('acc_saved_sorting'), true);
370 $this->ctrl->redirect($this);
371 }
372
376 protected function getCriterionForm(
377 ilAccessibilityDocument $document,
380 $this->ctrl->setParameter($this, 'acc_id', $document->getId());
381
382 if ($criterionAssignment->getId() > 0) {
383 $this->ctrl->setParameter($this, 'crit_id', $criterionAssignment->getId());
384 }
385
386 $formAction = $this->ctrl->getFormAction($this, 'saveAttachCriterionForm');
387 $saveCommand = 'saveAttachCriterionForm';
388
389 if ($criterionAssignment->getId() > 0) {
390 $formAction = $this->ctrl->getFormAction($this, 'saveChangeCriterionForm');
391 $saveCommand = 'saveChangeCriterionForm';
392 }
393
395 $document,
396 $criterionAssignment,
397 $this->criterionTypeFactory,
398 $this->user,
399 $formAction,
400 $saveCommand,
401 'showDocuments'
402 );
403
404 return $form;
405 }
406
407 protected function saveAttachCriterionForm(): void
408 {
409 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
410 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
411 }
412
413 $document = $this->getFirstDocumentFromList($this->getDocumentsByServerRequest());
414
415 $form = $this->getCriterionForm($document, new ilAccessibilityDocumentCriterionAssignment());
416 if ($form->saveObject()) {
417 $this->tpl->setOnScreenMessage('success', $this->lng->txt('acc_doc_crit_attached'), true);
418 $this->ctrl->redirect($this, 'showDocuments');
419 } elseif ($form->hasTranslatedError()) {
420 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError());
421 }
422
423 $this->tpl->setContent($form->getHTML());
424 }
425
426 protected function showAttachCriterionForm(): void
427 {
428 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
429 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
430 }
431
432 $document = $this->getFirstDocumentFromList($this->getDocumentsByServerRequest());
433
434 $form = $this->getCriterionForm($document, new ilAccessibilityDocumentCriterionAssignment());
435 $this->tpl->setContent($form->getHTML());
436 }
437
438 protected function showChangeCriterionForm(): void
439 {
440 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
441 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
442 }
443
444 $document = $this->getFirstDocumentFromList($this->getDocumentsByServerRequest());
445
446 $criterionId = $this->httpState->request()->getQueryParams()['crit_id'] ?? 0;
447 if (!is_numeric($criterionId) || $criterionId < 1) {
448 $this->showDocuments();
449 return;
450 }
451
452 $criterionAssignment = array_values(array_filter(
453 $document->criteria(),
454 function (ilAccessibilityDocumentCriterionAssignment $criterionAssignment) use ($criterionId) {
455 return $criterionAssignment->getId() == $criterionId;
456 }
457 ))[0];
458
459 $form = $this->getCriterionForm($document, $criterionAssignment);
460 $this->tpl->setContent($form->getHTML());
461 }
462
463 protected function saveChangeCriterionForm(): void
464 {
465 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
466 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
467 }
468
469 $document = $this->getFirstDocumentFromList($this->getDocumentsByServerRequest());
470
471 $criterionId = $this->httpState->request()->getQueryParams()['crit_id'] ?? 0;
472 if (!is_numeric($criterionId) || $criterionId < 1) {
473 $this->showDocuments();
474 return;
475 }
476
477 $criterionAssignment = array_values(array_filter(
478 $document->criteria(),
479 function (ilAccessibilityDocumentCriterionAssignment $criterionAssignment) use ($criterionId) {
480 return $criterionAssignment->getId() == $criterionId;
481 }
482 ))[0];
483
484 $form = $this->getCriterionForm($document, $criterionAssignment);
485 if ($form->saveObject()) {
486 $this->tpl->setOnScreenMessage('success', $this->lng->txt('acc_doc_crit_changed'), true);
487 $this->ctrl->redirect($this, 'showDocuments');
488 } elseif ($form->hasTranslatedError()) {
489 $this->tpl->setOnScreenMessage('failure', $form->getTranslatedError());
490 }
491
492 $this->tpl->setContent($form->getHTML());
493 }
494
495 public function detachCriterionAssignment(): void
496 {
497 if (!$this->rbacsystem->checkAccess('write', $this->accs->getRefId())) {
498 $this->error->raiseError($this->lng->txt('permission_denied'), $this->error->MESSAGE);
499 }
500
501 $document = $this->getFirstDocumentFromList($this->getDocumentsByServerRequest());
502
503 $criterionId = $this->httpState->request()->getQueryParams()['crit_id'] ?? 0;
504 if (!is_numeric($criterionId) || $criterionId < 1) {
505 $this->showDocuments();
506 return;
507 }
508
509 $criterionAssignment = array_values(array_filter(
510 $document->criteria(),
511 function (ilAccessibilityDocumentCriterionAssignment $criterionAssignment) use ($criterionId) {
512 return $criterionAssignment->getId() == $criterionId;
513 }
514 ))[0];
515
516 $document->detachCriterion($criterionAssignment);
517 $document->update();
518
519 $this->tpl->setOnScreenMessage('success', $this->lng->txt('acc_doc_crit_detached'), true);
520 $this->ctrl->redirect($this, 'showDocuments');
521 }
522}
static where($where, $operator=null)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Class Services.
Definition: Services.php:38
error(string $a_errmsg)
Class ilAccessibilityCriterionFormGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilAccessibilityDocumentFormGUI.
Class ilAccessibilityDocumentGUI.
getCriterionForm(ilAccessibilityDocument $document, ilAccessibilityDocumentCriterionAssignment $criterionAssignment)
executeCommand()
The implemented class should be ilCtrl enabled and execute or forward the given command.
__construct(ilObjAccessibilitySettings $accs, ilAccessibilityCriterionTypeFactoryInterface $criterionTypeFactory, ilGlobalTemplateInterface $tpl, ilObjUser $user, ilCtrl $ctrl, ilLanguage $lng, ilRbacSystem $rbacsystem, ilErrorHandling $error, ilLogger $log, ilToolbarGUI $toolbar, Services $httpState, Factory $uiFactory, Renderer $uiRenderer, Filesystems $fileSystems, FileUpload $fileUpload, ilAccessibilityTableDataProviderFactory $tableDataProviderFactory, ilHtmlPurifierInterface $documentPurifier)
getDocumentForm(ilAccessibilityDocument $document)
ilAccessibilityTableDataProviderFactory $tableDataProviderFactory
ilAccessibilityCriterionTypeFactoryInterface $criterionTypeFactory
Class ilAccessibilityDocumentTableGUI.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
detachCriterion(ilAccessibilityDocumentCriterionAssignment $criterionAssignment)
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...
Class ilCtrl provides processing control methods.
Error Handling & global info handling.
Base class for ILIAS Exception handling.
language handling
Component logger with individual log levels by component id.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
The Filesystems interface defines the access methods which can be used to fetch the different filesys...
Definition: Filesystems.php:30
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
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...
Interface for html sanitizing functionality.