AdministrationController::checkEventAccess()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 12
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\Controller;
13
14
use DERHANSEN\SfEventMgt\Domain\Model\Dto\CustomNotification;
15
use DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand;
16
use DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand;
17
use DERHANSEN\SfEventMgt\Domain\Model\Event;
18
use DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository;
19
use DERHANSEN\SfEventMgt\Event\InitAdministrationModuleTemplateEvent;
0 ignored issues
show
Bug introduced by
The type DERHANSEN\SfEventMgt\Eve...tionModuleTemplateEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use DERHANSEN\SfEventMgt\Event\ModifyAdministrationIndexNotifyViewVariablesEvent;
21
use DERHANSEN\SfEventMgt\Event\ModifyAdministrationListViewVariablesEvent;
22
use DERHANSEN\SfEventMgt\Service\BeUserSessionService;
23
use DERHANSEN\SfEventMgt\Service\ExportService;
24
use DERHANSEN\SfEventMgt\Service\MaintenanceService;
25
use DERHANSEN\SfEventMgt\Service\SettingsService;
26
use DERHANSEN\SfEventMgt\Utility\PageUtility;
27
use Psr\Http\Message\ResponseInterface;
28
use TYPO3\CMS\Backend\Routing\UriBuilder;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Routing\UriBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Template\Components\ButtonBar was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use TYPO3\CMS\Backend\Template\ModuleTemplate;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Template\ModuleTemplate was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Template\ModuleTemplateFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use TYPO3\CMS\Backend\Utility\BackendUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Backend\Utility\BackendUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
34
use TYPO3\CMS\Core\Imaging\IconFactory;
35
use TYPO3\CMS\Core\Imaging\IconSize;
36
use TYPO3\CMS\Core\Localization\LanguageService;
37
use TYPO3\CMS\Core\Page\PageRenderer;
38
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
39
use TYPO3\CMS\Core\Utility\GeneralUtility;
40
41
class AdministrationController extends AbstractController
42
{
43
    private const LANG_FILE = 'LLL:EXT:sf_event_mgt/Resources/Private/Language/locallang_be.xlf:';
44
45
    protected ModuleTemplateFactory $moduleTemplateFactory;
46
    protected CustomNotificationLogRepository $customNotificationLogRepository;
47
    protected ExportService $exportService;
48
    protected SettingsService $settingsService;
49
    protected BeUserSessionService $beUserSessionService;
50
    protected MaintenanceService $maintenanceService;
51
    protected IconFactory $iconFactory;
52
    protected PageRenderer $pageRenderer;
53
    protected int $pid = 0;
54
55
    public function injectCustomNotificationLogRepository(
56
        CustomNotificationLogRepository $customNotificationLogRepository
57
    ): void {
58
        $this->customNotificationLogRepository = $customNotificationLogRepository;
59
    }
60
61
    public function injectExportService(ExportService $exportService): void
62
    {
63
        $this->exportService = $exportService;
64
    }
65
66
    public function injectSettingsService(SettingsService $settingsService): void
67
    {
68
        $this->settingsService = $settingsService;
69
    }
70
71
    public function injectBeUserSessionService(BeUserSessionService $beUserSessionService): void
72
    {
73
        $this->beUserSessionService = $beUserSessionService;
74
    }
75
76
    public function injectIconFactory(IconFactory $iconFactory): void
77
    {
78
        $this->iconFactory = $iconFactory;
79
    }
80
81
    public function injectMaintenanceService(MaintenanceService $maintenanceService): void
82
    {
83
        $this->maintenanceService = $maintenanceService;
84
    }
85
86
    public function injectModuleTemplateFactory(ModuleTemplateFactory $moduleTemplateFactory): void
87
    {
88
        $this->moduleTemplateFactory = $moduleTemplateFactory;
89
    }
90
91
    public function injectPageRenderer(PageRenderer $pageRenderer): void
92
    {
93
        $this->pageRenderer = $pageRenderer;
94
    }
95
96
    /**
97
     * Register docHeaderButtons
98
     */
99
    protected function registerDocHeaderButtons(ModuleTemplate $moduleTemplate): void
100
    {
101
        $buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();
102
103
        if ($this->request->getControllerActionName() === 'list') {
104
            $buttons = [
105
                [
106
                    'label' => 'administration.newEvent',
107
                    'link' => $this->getCreateNewRecordUri('tx_sfeventmgt_domain_model_event'),
108
                    'icon' => 'ext-sfeventmgt-event',
109
                    'group' => 1,
110
                ],
111
                [
112
                    'label' => 'administration.newLocation',
113
                    'link' => $this->getCreateNewRecordUri('tx_sfeventmgt_domain_model_location'),
114
                    'icon' => 'ext-sfeventmgt-location',
115
                    'group' => 1,
116
                ],
117
                [
118
                    'label' => 'administration.newOrganisator',
119
                    'link' => $this->getCreateNewRecordUri('tx_sfeventmgt_domain_model_organisator'),
120
                    'icon' => 'ext-sfeventmgt-organisator',
121
                    'group' => 1,
122
                ],
123
                [
124
                    'label' => 'administration.newSpeaker',
125
                    'link' => $this->getCreateNewRecordUri('tx_sfeventmgt_domain_model_speaker'),
126
                    'icon' => 'ext-sfeventmgt-speaker',
127
                    'group' => 1,
128
                ],
129
                [
130
                    'label' => 'administration.handleExpiredRegistrations',
131
                    'link' => $this->uriBuilder->reset()->setRequest($this->request)
132
                        ->uriFor('handleExpiredRegistrations', [], 'Administration'),
133
                    'icon' => 'ext-sfeventmgt-action-handle-expired',
134
                    'group' => 2,
135
                ],
136
            ];
137
            foreach ($buttons as $tableConfiguration) {
138
                if ($this->isButtonDisabledBySetting($tableConfiguration['label'])) {
139
                    continue;
140
                }
141
142
                $title = $this->getLanguageService()->sL(self::LANG_FILE . $tableConfiguration['label']);
143
                $icon = $this->iconFactory->getIcon($tableConfiguration['icon'], IconSize::SMALL);
144
                $viewButton = $buttonBar->makeLinkButton()
145
                    ->setHref($tableConfiguration['link'])
146
                    ->setDataAttributes([
147
                        'toggle' => 'tooltip',
148
                        'placement' => 'bottom',
149
                        'title' => $title,
150
                    ])
151
                    ->setTitle($title)
152
                    ->setIcon($icon);
153
                $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, $tableConfiguration['group']);
154
            }
155
        }
156
    }
157
158
    /**
159
     * Returns, if the given button is disabled by the setting
160
     */
161
    private function isButtonDisabledBySetting(string $buttonLabel): bool
162
    {
163
        $disabledButtons = $this->settings['disableButtons'] ?? [];
164
        $buttonIdentifier = str_replace('administration.', '', $buttonLabel);
165
        return isset($disabledButtons[$buttonIdentifier]) && (int)($disabledButtons[$buttonIdentifier]) === 1;
166
    }
167
168
    /**
169
     * Returns the create new record URL for the given table
170
     */
171
    private function getCreateNewRecordUri(string $table): string
172
    {
173
        $pid = $this->pid;
174
        $tsConfig = BackendUtility::getPagesTSconfig(0);
175
        if ($pid === 0 && isset($tsConfig['defaultPid.'])
176
            && is_array($tsConfig['defaultPid.'])
177
            && isset($tsConfig['defaultPid.'][$table])
178
        ) {
179
            $pid = (int)$tsConfig['defaultPid.'][$table];
180
        }
181
182
        $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
183
184
        return (string)$uriBuilder->buildUriFromRoute('record_edit', [
185
            'edit[' . $table . '][' . $pid . ']' => 'new',
186
            'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI'),
187
        ]);
188
    }
189
190
    /**
191
     * Initializes module template and returns a response which must be used as response for any extbase action
192
     * that should render a view.
193
     */
194
    protected function initModuleTemplateAndReturnResponse(string $templateFileName, array $variables = []): ResponseInterface
195
    {
196
        $moduleTemplate = $this->moduleTemplateFactory->create($this->request);
197
        $this->pageRenderer->addCssFile('EXT:sf_event_mgt/Resources/Public/Css/administration.css');
198
199
        $this->pageRenderer->loadJavaScriptModule('@derhansen/sf_event_mgt/administration-module.js');
200
201
        $this->registerDocHeaderButtons($moduleTemplate);
202
203
        $moduleTemplate->setFlashMessageQueue($this->getFlashMessageQueue());
204
205
        $initAdministrationModuleTemplateEvent = new InitAdministrationModuleTemplateEvent(
206
            $moduleTemplate,
207
            $this->uriBuilder,
208
            $this,
209
            $this->request
210
        );
211
        $this->eventDispatcher->dispatch($initAdministrationModuleTemplateEvent);
212
213
        $variables['settings'] = $this->settings;
214
        $moduleTemplate->assignMultiple($variables);
215
216
        return $moduleTemplate->renderResponse($templateFileName);
217
    }
218
219
    public function initializeAction(): void
220
    {
221
        $this->pid = (int)($this->request->getQueryParams()['id'] ?? 0);
222
    }
223
224
    /**
225
     * Set date format for fields startDate and endDate
226
     */
227
    public function initializeListAction(): void
228
    {
229
        // Static format needed for date picker (flatpickr), see BackendController::generateJavascript() and #91606
230
        if (!empty($this->settings)) {
231
            $this->settings['search']['dateFormat'] = 'H:i d-m-Y';
0 ignored issues
show
Bug Best Practice introduced by
The property settings does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
232
        }
233
    }
234
235
    /**
236
     * List action for backend module
237
     */
238
    public function listAction(?SearchDemand $searchDemand = null, array $overwriteDemand = []): ResponseInterface
239
    {
240
        if (empty($this->settings)) {
241
            return $this->redirect('settingsError');
242
        }
243
244
        if ($searchDemand !== null) {
245
            $searchDemand->setFields($this->settings['search']['fields'] ?? 'title');
246
247
            $sessionData = [];
248
            $sessionData['searchDemand'] = $searchDemand->toArray();
249
            $sessionData['overwriteDemand'] = $overwriteDemand;
250
            $this->beUserSessionService->saveSessionData($sessionData);
251
        } else {
252
            // Try to restore search demand from Session
253
            $sessionSearchDemand = $this->beUserSessionService->getSessionDataByKey('searchDemand') ?? [];
254
            $searchDemand = SearchDemand::fromArray($sessionSearchDemand);
255
            $overwriteDemand = $this->beUserSessionService->getSessionDataByKey('overwriteDemand');
256
        }
257
258
        if ($this->isResetFilter()) {
259
            $searchDemand = GeneralUtility::makeInstance(SearchDemand::class);
260
            $overwriteDemand = [];
261
262
            $sessionData = [];
263
            $sessionData['searchDemand'] = $searchDemand->toArray();
264
            $sessionData['overwriteDemand'] = $overwriteDemand;
265
            $this->beUserSessionService->saveSessionData($sessionData);
266
        }
267
268
        // Initialize default ordering when no overwriteDemand is available
269
        if (empty($overwriteDemand)) {
270
            $overwriteDemand = [
271
                'orderField' => $this->settings['defaultSorting']['orderField'] ?? 'title',
272
                'orderDirection' => $this->settings['defaultSorting']['orderDirection'] ?? 'asc',
273
            ];
274
        }
275
276
        $events = [];
277
        $pagination = null;
278
        $pageUids = $this->resolveSearchPageUids((int)($overwriteDemand['recursive'] ?? 0));
279
        if ($pageUids !== '' &&
280
            $this->getBackendUser()->check('tables_select', 'tx_sfeventmgt_domain_model_event')
281
        ) {
282
            $eventDemand = GeneralUtility::makeInstance(EventDemand::class);
283
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
0 ignored issues
show
Bug introduced by
It seems like $overwriteDemand can also be of type null; however, parameter $overwriteDemand of DERHANSEN\SfEventMgt\Con...riteEventDemandObject() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

283
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, /** @scrutinizer ignore-type */ $overwriteDemand);
Loading history...
284
            $eventDemand->setOrderFieldAllowed($this->settings['orderFieldAllowed'] ?? '');
285
            $eventDemand->setSearchDemand($searchDemand);
286
            $eventDemand->setIgnoreEnableFields(true);
287
            $eventDemand->setStoragePage($pageUids);
288
289
            $events = $this->eventRepository->findDemanded($eventDemand);
290
            $pagination = $this->getPagination($events, $this->settings['pagination'] ?? []);
291
        }
292
293
        $modifyAdministrationListViewVariablesEvent = new ModifyAdministrationListViewVariablesEvent(
294
            [
295
                'pid' => $this->pid,
296
                'events' => $events,
297
                'searchDemand' => $searchDemand,
298
                'orderByFields' => $this->getOrderByFields(),
299
                'orderDirections' => $this->getOrderDirections(),
300
                'recursiveLevels' => $this->getRecursiveLevels(),
301
                'overwriteDemand' => $overwriteDemand,
302
                'pagination' => $pagination,
303
            ],
304
            $this,
305
            $this->request
306
        );
307
        $this->eventDispatcher->dispatch($modifyAdministrationListViewVariablesEvent);
308
        $variables = $modifyAdministrationListViewVariablesEvent->getVariables();
309
310
        return $this->initModuleTemplateAndReturnResponse('Administration/List', $variables);
311
    }
312
313
    /**
314
     * Resolves the page UIDs to search in respecting the given recursive option and additionally checking, if
315
     * the current backend user is allowed to affected pages
316
     */
317
    private function resolveSearchPageUids(int $recursive): string
318
    {
319
        $extendedPageUids = PageUtility::extendPidListByChildren(
320
            (string)$this->pid,
321
            $recursive
322
        );
323
        $extendedPageUids = GeneralUtility::intExplode(',', $extendedPageUids, true);
324
325
        $pageUids = [];
326
        foreach ($extendedPageUids as $extendedPageUid) {
327
            if (!in_array($extendedPageUid, $pageUids, true) &&
328
                $this->getBackendUser()->isInWebMount($extendedPageUid)
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getBackendUser()-...Mount($extendedPageUid) of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
329
            ) {
330
                $pageUids[] = $extendedPageUid;
331
            }
332
        }
333
334
        return implode(',', $pageUids);
335
    }
336
337
    /**
338
     * Returns, if reset filter operation has been used
339
     */
340
    private function isResetFilter(): bool
341
    {
342
        $resetFilter = false;
343
        if ($this->request->hasArgument('operation')) {
344
            $resetFilter = $this->request->getArgument('operation') === 'reset-filters';
345
        }
346
347
        return $resetFilter;
348
    }
349
350
    /**
351
     * Export registrations for a given event
352
     */
353
    public function exportAction(int $eventUid): void
354
    {
355
        /** @var Event $event */
356
        $event = $this->eventRepository->findByUidIncludeHidden($eventUid);
357
        if ($event !== null && $this->checkEventAccess($event)) {
358
            $this->exportService->downloadRegistrationsCsv($eventUid, $this->settings['csvExport'] ?? []);
359
        }
360
        exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
361
    }
362
363
    /**
364
     * Handles expired registrations
365
     */
366
    public function handleExpiredRegistrationsAction(): ResponseInterface
367
    {
368
        $delete = (bool)($this->settings['registration']['deleteExpiredRegistrations'] ?? false);
369
        $this->maintenanceService->handleExpiredRegistrations($delete);
370
371
        $this->addFlashMessage(
372
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.message-1.content'),
373
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.message-1.title')
374
        );
375
376
        return $this->redirect('list');
377
    }
378
379
    /**
380
     * The index notify action
381
     */
382
    public function indexNotifyAction(Event $event): ResponseInterface
383
    {
384
        if (!$this->checkEventAccess($event)) {
385
            return $this->redirect('list');
386
        }
387
388
        $customNotification = GeneralUtility::makeInstance(CustomNotification::class);
389
        $customNotifications = $this->settingsService->getCustomNotifications($this->settings);
390
        $logEntries = $this->customNotificationLogRepository->findBy(['event' => $event]);
391
392
        $modifyAdministrationIndexNotifyViewVariablesEvent = new ModifyAdministrationIndexNotifyViewVariablesEvent(
393
            [
394
                'event' => $event,
395
                'recipients' => $this->getNotificationRecipients(),
396
                'customNotification' => $customNotification,
397
                'customNotifications' => $customNotifications,
398
                'logEntries' => $logEntries,
399
            ],
400
            $this,
401
            $this->request
402
        );
403
        $this->eventDispatcher->dispatch($modifyAdministrationIndexNotifyViewVariablesEvent);
404
        $variables = $modifyAdministrationIndexNotifyViewVariablesEvent->getVariables();
405
406
        return $this->initModuleTemplateAndReturnResponse('Administration/IndexNotify', $variables);
407
    }
408
409
    /**
410
     * Returns an array of recipient option for the indexNotify action
411
     */
412
    public function getNotificationRecipients(): array
413
    {
414
        return [
415
            [
416
                'value' => CustomNotification::RECIPIENTS_ALL,
417
                'label' => $this->getLanguageService()->sL(
418
                    self::LANG_FILE . 'administration.notify.recipients.' . CustomNotification::RECIPIENTS_ALL
419
                ),
420
            ],
421
            [
422
                'value' => CustomNotification::RECIPIENTS_CONFIRMED,
423
                'label' => $this->getLanguageService()->sL(
424
                    self::LANG_FILE . 'administration.notify.recipients.' . CustomNotification::RECIPIENTS_CONFIRMED
425
                ),
426
            ],
427
            [
428
                'value' => CustomNotification::RECIPIENTS_UNCONFIRMED,
429
                'label' => $this->getLanguageService()->sL(
430
                    self::LANG_FILE . 'administration.notify.recipients.' . CustomNotification::RECIPIENTS_UNCONFIRMED
431
                ),
432
            ],
433
            [
434
                'value' => CustomNotification::RECIPIENTS_WAITLIST_CONFIRMED,
435
                'label' => $this->getLanguageService()->sL(
436
                    self::LANG_FILE . 'administration.notify.recipients.' . CustomNotification::RECIPIENTS_WAITLIST_CONFIRMED
437
                ),
438
            ],
439
            [
440
                'value' => CustomNotification::RECIPIENTS_WAITLIST_UNCONFIRMED,
441
                'label' => $this->getLanguageService()->sL(
442
                    self::LANG_FILE . 'administration.notify.recipients.' . CustomNotification::RECIPIENTS_WAITLIST_UNCONFIRMED
443
                ),
444
            ],
445
        ];
446
    }
447
448
    /**
449
     * Notify action
450
     */
451
    public function notifyAction(Event $event, CustomNotification $customNotification): ResponseInterface
452
    {
453
        if (!$this->checkEventAccess($event)) {
454
            return $this->redirect('list');
455
        }
456
457
        $customNotifications = $this->settingsService->getCustomNotifications($this->settings);
458
        $result = $this->notificationService->sendCustomNotification(
459
            $this->request,
460
            $event,
461
            $customNotification,
462
            $this->settings
463
        );
464
        $this->notificationService->createCustomNotificationLogentry(
465
            $event,
466
            $customNotifications[$customNotification->getTemplate()],
467
            $result,
468
            $customNotification
469
        );
470
        $this->addFlashMessage(
471
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.message-2.content'),
472
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.message-2.title')
473
        );
474
        return $this->redirect('list');
475
    }
476
477
    /**
478
     * Checks if the current backend user has access to the PID of the event and if not, enqueue an
479
     * access denied flash message
480
     */
481
    public function checkEventAccess(Event $event): bool
482
    {
483
        if ($this->getBackendUser()->isInWebMount($event->getPid()) === null) {
484
            $this->addFlashMessage(
485
                $this->getLanguageService()->sL(self::LANG_FILE . 'administration.accessdenied.content'),
486
                $this->getLanguageService()->sL(self::LANG_FILE . 'administration.accessdenied.title'),
487
                ContextualFeedbackSeverity::ERROR
488
            );
489
            return false;
490
        }
491
492
        return true;
493
    }
494
495
    /**
496
     * Shows the settings error view
497
     */
498
    public function settingsErrorAction(): ResponseInterface
499
    {
500
        return $this->initModuleTemplateAndReturnResponse('Administration/SettingsError');
501
    }
502
503
    /**
504
     * Suppress default validation messages
505
     */
506
    protected function getErrorFlashMessage(): bool
507
    {
508
        return false;
509
    }
510
511
    /**
512
     * Returns an array with possible order directions
513
     */
514
    public function getOrderDirections(): array
515
    {
516
        return [
517
            'asc' => $this->getLanguageService()->sL(self::LANG_FILE . 'administration.sortOrder.asc'),
518
            'desc' => $this->getLanguageService()->sL(self::LANG_FILE . 'administration.sortOrder.desc'),
519
        ];
520
    }
521
522
    /**
523
     * Returns an array with possible recursive levels
524
     */
525
    public function getRecursiveLevels(): array
526
    {
527
        return [
528
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.current'),
529
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level1'),
530
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level2'),
531
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level3'),
532
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level4'),
533
            $this->getLanguageService()->sL(self::LANG_FILE . 'administration.recursiveLevel.level5'),
534
        ];
535
    }
536
537
    /**
538
     * Returns an array with possible orderBy fields
539
     */
540
    public function getOrderByFields(): array
541
    {
542
        return [
543
            'title' => $this->getLanguageService()->sL(self::LANG_FILE . 'administration.orderBy.title'),
544
            'startdate' => $this->getLanguageService()->sL(self::LANG_FILE . 'administration.orderBy.startdate'),
545
            'enddate' => $this->getLanguageService()->sL(self::LANG_FILE . 'administration.orderBy.enddate'),
546
        ];
547
    }
548
549
    protected function getLanguageService(): LanguageService
550
    {
551
        return $GLOBALS['LANG'];
552
    }
553
554
    protected function getBackendUser(): BackendUserAuthentication
555
    {
556
        return $GLOBALS['BE_USER'];
557
    }
558
}
559