Passed
Push — typo3_11 ( 05e136 )
by Torben
43:39
created

removePossibleSpamCheckFieldsFromArguments()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 5
nop 0
dl 0
loc 19
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.txt file that was distributed with this source code.
8
 */
9
10
namespace DERHANSEN\SfEventMgt\Controller;
11
12
use DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand;
13
use DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand;
14
use DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand;
15
use DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand;
16
use DERHANSEN\SfEventMgt\Domain\Model\Event;
17
use DERHANSEN\SfEventMgt\Domain\Model\Registration;
18
use DERHANSEN\SfEventMgt\Event\AfterRegistrationConfirmedEvent;
19
use DERHANSEN\SfEventMgt\Event\AfterRegistrationSavedEvent;
20
use DERHANSEN\SfEventMgt\Event\EventPidCheckFailedEvent;
21
use DERHANSEN\SfEventMgt\Event\ModifyCalendarViewVariablesEvent;
22
use DERHANSEN\SfEventMgt\Event\ModifyCancelRegistrationViewVariablesEvent;
23
use DERHANSEN\SfEventMgt\Event\ModifyConfirmRegistrationViewVariablesEvent;
24
use DERHANSEN\SfEventMgt\Event\ModifyCreateDependingRegistrationsEvent;
25
use DERHANSEN\SfEventMgt\Event\ModifyDetailViewVariablesEvent;
26
use DERHANSEN\SfEventMgt\Event\ModifyListViewVariablesEvent;
27
use DERHANSEN\SfEventMgt\Event\ModifyRegistrationViewVariablesEvent;
28
use DERHANSEN\SfEventMgt\Event\ModifySearchViewVariablesEvent;
29
use DERHANSEN\SfEventMgt\Event\WaitlistMoveUpEvent;
30
use DERHANSEN\SfEventMgt\Service\EventCacheService;
31
use DERHANSEN\SfEventMgt\Utility\MessageType;
32
use DERHANSEN\SfEventMgt\Utility\Page;
33
use DERHANSEN\SfEventMgt\Utility\RegistrationResult;
34
use Psr\Http\Message\ServerRequestInterface;
35
use TYPO3\CMS\Core\Context\Context;
36
use TYPO3\CMS\Core\Http\ImmediateResponseException;
37
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
38
use TYPO3\CMS\Core\Utility\ArrayUtility;
39
use TYPO3\CMS\Core\Utility\GeneralUtility;
40
use TYPO3\CMS\Core\Utility\HttpUtility;
41
use TYPO3\CMS\Extbase\Annotation as Extbase;
42
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
43
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
44
use TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter;
45
use TYPO3\CMS\Fluid\View\StandaloneView;
46
use TYPO3\CMS\Frontend\Controller\ErrorController;
47
48
/**
49
 * EventController
50
 */
51
class EventController extends AbstractController
52
{
53
    /**
54
     * @var EventCacheService
55
     */
56
    protected $eventCacheService;
57
58
    /**
59
     * @param EventCacheService $cacheService
60
     */
61
    public function injectEventCacheService(EventCacheService $cacheService)
62
    {
63
        $this->eventCacheService = $cacheService;
64
    }
65
66
    /**
67
     * Assign contentObjectData and pageData to earch view
68
     *
69
     * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view
70
     */
71
    protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view)
72
    {
73
        // @extensionScannerIgnoreLine
74
        $view->assign('contentObjectData', $this->configurationManager->getContentObject()->data);
75
        if (is_object($GLOBALS['TSFE'])) {
76
            $view->assign('pageData', $GLOBALS['TSFE']->page);
77
        }
78
        parent::initializeView($view);
79
    }
80
81
    /**
82
     * Initializes the current action
83
     */
84
    public function initializeAction()
85
    {
86
        $typoScriptFrontendController = $this->getTypoScriptFrontendController();
87
        if ($typoScriptFrontendController !== null) {
88
            static $cacheTagsSet = false;
89
90
            if (!$cacheTagsSet) {
91
                $typoScriptFrontendController->addCacheTags(['tx_sfeventmgt']);
92
                $cacheTagsSet = true;
93
            }
94
        }
95
    }
96
97
    /**
98
     * Creates an event demand object with the given settings
99
     *
100
     * @param array $settings The settings
101
     *
102
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand
103
     */
104
    public function createEventDemandObjectFromSettings(array $settings)
105
    {
106
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand */
107
        $demand = $this->objectManager->get(EventDemand::class);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

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

107
        $demand = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(EventDemand::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The property TYPO3\CMS\Extbase\Mvc\Co...troller::$objectManager has been deprecated: since v11, will be removed in v12 ( Ignorable by Annotation )

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

107
        $demand = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(EventDemand::class);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
108
        $demand->setDisplayMode($settings['displayMode']);
109
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
110
        $demand->setCategoryConjunction($settings['categoryConjunction']);
111
        $demand->setCategory($settings['category']);
112
        $demand->setIncludeSubcategories($settings['includeSubcategories']);
113
        $demand->setTopEventRestriction((int)$settings['topEventRestriction']);
114
        $demand->setOrderField($settings['orderField']);
115
        $demand->setOrderFieldAllowed($settings['orderFieldAllowed']);
116
        $demand->setOrderDirection($settings['orderDirection']);
117
        $demand->setQueryLimit($settings['queryLimit']);
118
        $demand->setLocation($settings['location']);
119
        $demand->setOrganisator($settings['organisator']);
120
        $demand->setSpeaker($settings['speaker']);
121
        $demand->setTimeRestrictionLow($settings['timeRestrictionLow']);
122
        $demand->setTimeRestrictionHigh($settings['timeRestrictionHigh']);
123
        $demand->setIncludeCurrent($settings['includeCurrent']);
124
125
        return $demand;
126
    }
127
128
    /**
129
     * Creates a foreign record demand object with the given settings
130
     *
131
     * @param array $settings The settings
132
     *
133
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand
134
     */
135
    public function createForeignRecordDemandObjectFromSettings(array $settings)
136
    {
137
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand $demand */
138
        $demand = $this->objectManager->get(ForeignRecordDemand::class);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

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

138
        $demand = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(ForeignRecordDemand::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The property TYPO3\CMS\Extbase\Mvc\Co...troller::$objectManager has been deprecated: since v11, will be removed in v12 ( Ignorable by Annotation )

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

138
        $demand = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(ForeignRecordDemand::class);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
139
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
140
        $demand->setRestrictForeignRecordsToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']);
141
142
        return $demand;
143
    }
144
145
    /**
146
     * Creates a category demand object with the given settings
147
     *
148
     * @param array $settings The settings
149
     *
150
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand
151
     */
152
    public function createCategoryDemandObjectFromSettings(array $settings)
153
    {
154
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand $demand */
155
        $demand = $this->objectManager->get(CategoryDemand::class);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

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

155
        $demand = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(CategoryDemand::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The property TYPO3\CMS\Extbase\Mvc\Co...troller::$objectManager has been deprecated: since v11, will be removed in v12 ( Ignorable by Annotation )

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

155
        $demand = /** @scrutinizer ignore-deprecated */ $this->objectManager->get(CategoryDemand::class);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
156
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
157
        $demand->setRestrictToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']);
158
        $demand->setCategories($settings['categoryMenu']['categories']);
159
        $demand->setIncludeSubcategories($settings['categoryMenu']['includeSubcategories']);
160
        $demand->setOrderField($settings['categoryMenu']['orderField'] ?? 'uid');
161
        $demand->setOrderDirection($settings['categoryMenu']['orderDirection'] ?? 'asc');
162
163
        return $demand;
164
    }
165
166
    /**
167
     * Initialize list action and set format
168
     */
169
    public function initializeListAction()
170
    {
171
        if (isset($this->settings['list']['format'])) {
172
            $this->request->setFormat($this->settings['list']['format']);
173
        }
174
    }
175
176
    /**
177
     * List view
178
     *
179
     * @param array $overwriteDemand OverwriteDemand
180
     */
181
    public function listAction(array $overwriteDemand = [])
182
    {
183
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
184
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
185
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
186
        if ($this->isOverwriteDemand($overwriteDemand)) {
187
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
188
        }
189
        $events = $this->eventRepository->findDemanded($eventDemand);
190
        $categories = $this->categoryRepository->findDemanded($categoryDemand);
191
        $locations = $this->locationRepository->findDemanded($foreignRecordDemand);
192
        $organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand);
193
        $speakers = $this->speakerRepository->findDemanded($foreignRecordDemand);
194
195
        $modifyListViewVariablesEvent = new ModifyListViewVariablesEvent(
196
            [
197
                'events' => $events,
198
                'categories' => $categories,
199
                'locations' => $locations,
200
                'organisators' => $organisators,
201
                'speakers' => $speakers,
202
                'overwriteDemand' => $overwriteDemand,
203
                'eventDemand' => $eventDemand
204
            ],
205
            $this
206
        );
207
        $this->eventDispatcher->dispatch($modifyListViewVariablesEvent);
208
        $variables = $modifyListViewVariablesEvent->getVariables();
209
        $this->view->assignMultiple($variables);
210
211
        $this->eventCacheService->addPageCacheTagsByEventDemandObject($eventDemand);
212
    }
213
214
    /**
215
     * Calendar view
216
     *
217
     * @param array $overwriteDemand OverwriteDemand
218
     */
219
    public function calendarAction(array $overwriteDemand = [])
220
    {
221
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
222
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
223
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
224
        if ($this->isOverwriteDemand($overwriteDemand)) {
225
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
226
        }
227
228
        // Set month/year to demand if not given
229
        if (!$eventDemand->getMonth()) {
230
            $currentMonth = date('n');
231
            $eventDemand->setMonth($currentMonth);
0 ignored issues
show
Bug introduced by
$currentMonth of type string is incompatible with the type integer expected by parameter $month of DERHANSEN\SfEventMgt\Dom...EventDemand::setMonth(). ( Ignorable by Annotation )

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

231
            $eventDemand->setMonth(/** @scrutinizer ignore-type */ $currentMonth);
Loading history...
232
        } else {
233
            $currentMonth = $eventDemand->getMonth();
234
        }
235
        if (!$eventDemand->getYear()) {
236
            $currentYear = date('Y');
237
            $eventDemand->setYear($currentYear);
0 ignored issues
show
Bug introduced by
$currentYear of type string is incompatible with the type integer expected by parameter $year of DERHANSEN\SfEventMgt\Dom...\EventDemand::setYear(). ( Ignorable by Annotation )

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

237
            $eventDemand->setYear(/** @scrutinizer ignore-type */ $currentYear);
Loading history...
238
        } else {
239
            $currentYear = $eventDemand->getYear();
240
        }
241
242
        // Set demand from calendar date range instead of month / year
243
        if ((bool)$this->settings['calendar']['includeEventsForEveryDayOfAllCalendarWeeks']) {
244
            $eventDemand = $this->changeEventDemandToFullMonthDateRange($eventDemand);
245
        }
246
247
        $events = $this->eventRepository->findDemanded($eventDemand);
248
        $weeks = $this->calendarService->getCalendarArray(
249
            $currentMonth,
0 ignored issues
show
Bug introduced by
It seems like $currentMonth can also be of type string; however, parameter $month of DERHANSEN\SfEventMgt\Ser...ice::getCalendarArray() does only seem to accept integer, 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

249
            /** @scrutinizer ignore-type */ $currentMonth,
Loading history...
250
            $currentYear,
0 ignored issues
show
Bug introduced by
It seems like $currentYear can also be of type string; however, parameter $year of DERHANSEN\SfEventMgt\Ser...ice::getCalendarArray() does only seem to accept integer, 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

250
            /** @scrutinizer ignore-type */ $currentYear,
Loading history...
251
            strtotime('today midnight'),
252
            (int)$this->settings['calendar']['firstDayOfWeek'],
253
            $events
254
        );
255
256
        $modifyCalendarViewVariablesEvent = new ModifyCalendarViewVariablesEvent(
257
            [
258
                'events' => $events,
259
                'weeks' => $weeks,
260
                'categories' => $this->categoryRepository->findDemanded($categoryDemand),
261
                'locations' => $this->locationRepository->findDemanded($foreignRecordDemand),
262
                'organisators' => $this->organisatorRepository->findDemanded($foreignRecordDemand),
263
                'eventDemand' => $eventDemand,
264
                'overwriteDemand' => $overwriteDemand,
265
                'currentPageId' => $GLOBALS['TSFE']->id,
266
                'firstDayOfMonth' => \DateTime::createFromFormat(
267
                    'd.m.Y',
268
                    sprintf('1.%s.%s', $currentMonth, $currentYear)
269
                ),
270
                'previousMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '-1 month'),
0 ignored issues
show
Bug introduced by
It seems like $currentMonth can also be of type string; however, parameter $month of DERHANSEN\SfEventMgt\Ser...ervice::getDateConfig() does only seem to accept integer, 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

270
                'previousMonthConfig' => $this->calendarService->getDateConfig(/** @scrutinizer ignore-type */ $currentMonth, $currentYear, '-1 month'),
Loading history...
Bug introduced by
It seems like $currentYear can also be of type string; however, parameter $year of DERHANSEN\SfEventMgt\Ser...ervice::getDateConfig() does only seem to accept integer, 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

270
                'previousMonthConfig' => $this->calendarService->getDateConfig($currentMonth, /** @scrutinizer ignore-type */ $currentYear, '-1 month'),
Loading history...
271
                'nextMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '+1 month')
272
            ],
273
            $this
274
        );
275
        $this->eventDispatcher->dispatch($modifyCalendarViewVariablesEvent);
276
        $variables = $modifyCalendarViewVariablesEvent->getVariables();
277
278
        $this->view->assignMultiple($variables);
279
    }
280
281
    /**
282
     * Changes the given event demand object to select a date range for a calendar month including days of the previous
283
     * month for the first week and they days for the next month for the last week
284
     *
285
     * @param EventDemand $eventDemand
286
     * @return EventDemand
287
     */
288
    protected function changeEventDemandToFullMonthDateRange(EventDemand $eventDemand)
289
    {
290
        $calendarDateRange = $this->calendarService->getCalendarDateRange(
291
            $eventDemand->getMonth(),
292
            $eventDemand->getYear(),
293
            $this->settings['calendar']['firstDayOfWeek']
294
        );
295
296
        $eventDemand->setMonth(0);
297
        $eventDemand->setYear(0);
298
299
        $startDate = new \DateTime();
300
        $startDate->setTimestamp($calendarDateRange['firstDayOfCalendar']);
301
        $endDate = new \DateTime();
302
        $endDate->setTimestamp($calendarDateRange['lastDayOfCalendar']);
303
        $endDate->setTime(23, 59, 59);
304
305
        $searchDemand = new SearchDemand();
306
        $searchDemand->setStartDate($startDate);
307
        $searchDemand->setEndDate($endDate);
308
        $eventDemand->setSearchDemand($searchDemand);
309
310
        return $eventDemand;
311
    }
312
313
    /**
314
     * Detail view for an event
315
     *
316
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
317
     * @return mixed string|void
318
     */
319
    public function detailAction(Event $event = null)
320
    {
321
        $event = $this->evaluateSingleEventSetting($event);
322
        $event = $this->evaluateIsShortcutSetting($event);
323
        if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) {
324
            $event = $this->checkPidOfEventRecord($event);
325
        }
326
327
        if (is_null($event) && isset($this->settings['event']['errorHandling'])) {
328
            return $this->handleEventNotFoundError($this->settings);
329
        }
330
331
        $modifyDetailViewVariablesEvent = new ModifyDetailViewVariablesEvent(['event' => $event], $this);
332
        $this->eventDispatcher->dispatch($modifyDetailViewVariablesEvent);
333
        $variables = $modifyDetailViewVariablesEvent->getVariables();
334
335
        $this->view->assignMultiple($variables);
336
        if ($event !== null) {
337
            $this->eventCacheService->addCacheTagsByEventRecords([$event]);
338
        }
339
    }
340
341
    /**
342
     * Error handling if event is not found
343
     *
344
     * @param array $settings
345
     */
346
    protected function handleEventNotFoundError($settings)
347
    {
348
        if (empty($settings['event']['errorHandling'])) {
349
            return null;
350
        }
351
352
        $configuration = GeneralUtility::trimExplode(',', $settings['event']['errorHandling'], true);
353
354
        switch ($configuration[0]) {
355
            case 'redirectToListView':
356
                $listPid = (int)$settings['listPid'] > 0 ? (int)$settings['listPid'] : 1;
357
                $this->redirect('list', null, null, null, $listPid);
358
                break;
359
            case 'pageNotFoundHandler':
360
                $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
361
                    $GLOBALS['TYPO3_REQUEST'],
362
                    'Event not found.'
363
                );
364
                throw new ImmediateResponseException($response, 1549896549);
365
            case 'showStandaloneTemplate':
366
                if (isset($configuration[2])) {
367
                    $statusCode = constant(HttpUtility::class . '::HTTP_STATUS_' . $configuration[2]);
368
                    HttpUtility::setResponseCode($statusCode);
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Core\Utility\H...lity::setResponseCode() has been deprecated: since v11, will be removed in v12. ( Ignorable by Annotation )

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

368
                    /** @scrutinizer ignore-deprecated */ HttpUtility::setResponseCode($statusCode);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
369
                }
370
                $standaloneTemplate = GeneralUtility::makeInstance(StandaloneView::class);
371
                $standaloneTemplate->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($configuration[1]));
372
373
                return $standaloneTemplate->render();
374
            default:
375
        }
376
    }
377
378
    /**
379
     * Initiates the iCalendar download for the given event
380
     *
381
     * @param Event $event The event
382
     *
383
     * @return string|false
384
     */
385
    public function icalDownloadAction(Event $event = null)
386
    {
387
        if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) {
388
            $event = $this->checkPidOfEventRecord($event);
389
        }
390
        if (is_null($event) && isset($this->settings['event']['errorHandling'])) {
391
            return $this->handleEventNotFoundError($this->settings);
392
        }
393
        $this->icalendarService->downloadiCalendarFile($event);
0 ignored issues
show
Bug introduced by
It seems like $event can also be of type null; however, parameter $event of DERHANSEN\SfEventMgt\Ser...downloadiCalendarFile() does only seem to accept DERHANSEN\SfEventMgt\Domain\Model\Event, 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

393
        $this->icalendarService->downloadiCalendarFile(/** @scrutinizer ignore-type */ $event);
Loading history...
394
        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...
395
    }
396
397
    /**
398
     * Registration view for an event
399
     *
400
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
401
     *
402
     * @return mixed string|void
403
     */
404
    public function registrationAction(Event $event = null)
405
    {
406
        $event = $this->evaluateSingleEventSetting($event);
407
        if (is_a($event, Event::class) && $this->settings['registration']['checkPidOfEventRecord']) {
408
            $event = $this->checkPidOfEventRecord($event);
409
        }
410
        if (is_null($event) && isset($this->settings['event']['errorHandling'])) {
411
            return $this->handleEventNotFoundError($this->settings);
412
        }
413
        if ($event->getRestrictPaymentMethods()) {
414
            $paymentMethods = $this->paymentService->getRestrictedPaymentMethods($event);
415
        } else {
416
            $paymentMethods = $this->paymentService->getPaymentMethods();
417
        }
418
419
        $modifyRegistrationViewVariablesEvent = new ModifyRegistrationViewVariablesEvent(
420
            [
421
                'event' => $event,
422
                'paymentMethods' => $paymentMethods,
423
            ],
424
            $this
425
        );
426
        $this->eventDispatcher->dispatch($modifyRegistrationViewVariablesEvent);
427
        $variables = $modifyRegistrationViewVariablesEvent->getVariables();
428
        $this->view->assignMultiple($variables);
429
    }
430
431
    /**
432
     * Removes all possible spamcheck fields (which do not belong to the domain model) from arguments.
433
     */
434
    protected function removePossibleSpamCheckFieldsFromArguments()
435
    {
436
        $arguments = $this->request->getArguments();
437
        if (!isset($arguments['event'])) {
438
            return;
439
        }
440
441
        // Remove a possible honeypot field
442
        $honeypotField = 'hp' . (int)$arguments['event'];
443
        if (isset($arguments['registration'][$honeypotField])) {
444
            unset($arguments['registration'][$honeypotField]);
445
        }
446
447
        // Remove a possible challenge/response field
448
        if (isset($arguments['registration']['cr-response'])) {
449
            unset($arguments['registration']['cr-response']);
450
        }
451
452
        $this->request->setArguments($arguments);
453
    }
454
455
    /**
456
     * Processes incoming registrations fields and adds field values to arguments
457
     */
458
    protected function setRegistrationFieldValuesToArguments()
459
    {
460
        $arguments = $this->request->getArguments();
461
        if (!isset($arguments['event'])) {
462
            return;
463
        }
464
465
        /** @var Event $event */
466
        $event = $this->eventRepository->findByUid((int)$this->request->getArgument('event'));
467
        if (!$event || $event->getRegistrationFields()->count() === 0) {
0 ignored issues
show
introduced by
$event is of type DERHANSEN\SfEventMgt\Domain\Model\Event, thus it always evaluated to true.
Loading history...
468
            return;
469
        }
470
471
        $registrationMvcArgument = $this->arguments->getArgument('registration');
472
        $propertyMapping = $registrationMvcArgument->getPropertyMappingConfiguration();
473
        $propertyMapping->allowProperties('fieldValues');
474
        $propertyMapping->allowCreationForSubProperty('fieldValues');
475
        $propertyMapping->allowModificationForSubProperty('fieldValues');
476
477
        // allow creation of new objects (for validation)
478
        $propertyMapping->setTypeConverterOptions(
479
            PersistentObjectConverter::class,
480
            [
481
                PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED => true,
482
                PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED => true
483
            ]
484
        );
485
486
        // Set event to registration (required for validation)
487
        $propertyMapping->allowProperties('event');
488
        $propertyMapping->allowCreationForSubProperty('event');
489
        $propertyMapping->allowModificationForSubProperty('event');
490
        $arguments['registration']['event'] = (int)$this->request->getArgument('event');
491
492
        $index = 0;
493
        foreach ((array)$arguments['registration']['fields'] as $fieldUid => $value) {
494
            // Only accept registration fields of the current event
495
            if (!in_array((int)$fieldUid, $event->getRegistrationFieldsUids(), true)) {
496
                continue;
497
            }
498
499
            // allow subvalues in new property mapper
500
            $propertyMapping->forProperty('fieldValues')->allowProperties($index);
501
            $propertyMapping->forProperty('fieldValues.' . $index)->allowAllProperties();
502
            $propertyMapping->allowCreationForSubProperty('fieldValues.' . $index);
503
            $propertyMapping->allowModificationForSubProperty('fieldValues.' . $index);
504
505
            if (is_array($value)) {
506
                if (empty($value)) {
507
                    $value = '';
508
                } else {
509
                    $value = json_encode($value);
510
                }
511
            }
512
513
            /** @var Registration\Field $field */
514
            $field = $this->fieldRepository->findByUid((int)$fieldUid);
515
516
            $arguments['registration']['fieldValues'][$index] = [
517
                'pid' => $field->getPid(),
518
                'value' => $value,
519
                'field' => (string)$fieldUid,
520
                'valueType' => $field->getValueType()
521
            ];
522
523
            $index++;
524
        }
525
526
        // Remove temporary "fields" field
527
        if (isset($arguments['registration']['fields'])) {
528
            $arguments = ArrayUtility::removeByPath($arguments, 'registration/fields');
529
        }
530
        $this->request->setArguments($arguments);
531
    }
532
533
    /**
534
     * Set date format for field dateOfBirth
535
     */
536
    public function initializeSaveRegistrationAction()
537
    {
538
        $this->arguments->getArgument('registration')
539
            ->getPropertyMappingConfiguration()->forProperty('dateOfBirth')
540
            ->setTypeConverterOption(
541
                DateTimeConverter::class,
542
                DateTimeConverter::CONFIGURATION_DATE_FORMAT,
543
                $this->settings['registration']['formatDateOfBirth']
544
            );
545
        $this->removePossibleSpamCheckFieldsFromArguments();
546
        $this->setRegistrationFieldValuesToArguments();
547
    }
548
549
    /**
550
     * Saves the registration
551
     *
552
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
553
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
554
     * @Extbase\Validate("DERHANSEN\SfEventMgt\Validation\Validator\RegistrationFieldValidator", param="registration")
555
     * @Extbase\Validate("DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator", param="registration")
556
     *
557
     * @return mixed string|void
558
     */
559
    public function saveRegistrationAction(Registration $registration, Event $event)
560
    {
561
        if (is_a($event, Event::class) && $this->settings['registration']['checkPidOfEventRecord']) {
562
            $event = $this->checkPidOfEventRecord($event);
563
        }
564
        if (is_null($event) && isset($this->settings['event']['errorHandling'])) {
565
            return $this->handleEventNotFoundError($this->settings);
566
        }
567
        $autoConfirmation = (bool)$this->settings['registration']['autoConfirmation'] || $event->getEnableAutoconfirm();
568
        $result = RegistrationResult::REGISTRATION_SUCCESSFUL;
569
        list($success, $result) = $this->registrationService->checkRegistrationSuccess($event, $registration, $result);
570
571
        // Save registration if no errors
572
        if ($success) {
573
            $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration(
574
                $event,
575
                $registration->getAmountOfRegistrations()
576
            );
577
            $linkValidity = (int)$this->settings['confirmation']['linkValidity'];
578
            if ($linkValidity === 0) {
579
                // Use 3600 seconds as default value if not set
580
                $linkValidity = 3600;
581
            }
582
            $confirmationUntil = new \DateTime();
583
            $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S'));
584
585
            $registration->setEvent($event);
586
            $registration->setPid($event->getPid());
587
            $registration->setRegistrationDate(new \DateTime());
588
            $registration->setConfirmationUntil($confirmationUntil);
589
            $registration->setLanguage($this->getCurrentLanguageTwoLetterIsoCode());
590
            $registration->setFeUser($this->registrationService->getCurrentFeUserObject());
591
            $registration->setWaitlist($isWaitlistRegistration);
592
            $this->registrationRepository->add($registration);
593
594
            // Persist registration, so we have an UID
595
            $this->persistAll();
596
597
            if ($isWaitlistRegistration) {
598
                $messageType = MessageType::REGISTRATION_WAITLIST_NEW;
599
            } else {
600
                $messageType = MessageType::REGISTRATION_NEW;
601
            }
602
603
            $this->eventDispatcher->dispatch(new AfterRegistrationSavedEvent($registration, $this));
604
605
            // Send notifications to user and admin if confirmation link should be sent
606
            if (!$autoConfirmation) {
607
                $this->notificationService->sendUserMessage(
608
                    $event,
609
                    $registration,
610
                    $this->settings,
611
                    $messageType
612
                );
613
                $this->notificationService->sendAdminMessage(
614
                    $event,
615
                    $registration,
616
                    $this->settings,
617
                    $messageType
618
                );
619
            }
620
621
            // Create given amount of registrations if necessary
622
            $modifyCreateDependingRegistrationsEvent = new ModifyCreateDependingRegistrationsEvent(
623
                $registration,
624
                ($registration->getAmountOfRegistrations() > 1),
625
                $this
626
            );
627
            $this->eventDispatcher->dispatch($modifyCreateDependingRegistrationsEvent);
628
            $createDependingRegistrations = $modifyCreateDependingRegistrationsEvent->getCreateDependingRegistrations();
629
            if ($createDependingRegistrations) {
630
                $this->registrationService->createDependingRegistrations($registration);
631
            }
632
633
            // Flush page cache for event, since new registration has been added
634
            $this->eventCacheService->flushEventCache($event->getUid(), $event->getPid());
635
        }
636
637
        if ($autoConfirmation && $success) {
638
            $this->redirect(
639
                'confirmRegistration',
640
                null,
641
                null,
642
                [
643
                    'reguid' => $registration->getUid(),
644
                    'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid())
645
                ]
646
            );
647
        } else {
648
            $this->redirect(
649
                'saveRegistrationResult',
650
                null,
651
                null,
652
                [
653
                    'result' => $result,
654
                    'eventuid' => $event->getUid(),
655
                    'hmac' => $this->hashService->generateHmac('event-' . $event->getUid())
656
                ]
657
            );
658
        }
659
    }
660
661
    /**
662
     * Shows the result of the saveRegistrationAction
663
     *
664
     * @param int $result Result
665
     * @param int $eventuid
666
     * @param string $hmac
667
     */
668
    public function saveRegistrationResultAction($result, $eventuid, $hmac)
669
    {
670
        $event = null;
671
672
        switch ($result) {
673
            case RegistrationResult::REGISTRATION_SUCCESSFUL:
674
                $messageKey = 'event.message.registrationsuccessful';
675
                $titleKey = 'registrationResult.title.successful';
676
                break;
677
            case RegistrationResult::REGISTRATION_SUCCESSFUL_WAITLIST:
678
                $messageKey = 'event.message.registrationwaitlistsuccessful';
679
                $titleKey = 'registrationWaitlistResult.title.successful';
680
                break;
681
            case RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED:
682
                $messageKey = 'event.message.registrationfailedeventexpired';
683
                $titleKey = 'registrationResult.title.failed';
684
                break;
685
            case RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS:
686
                $messageKey = 'event.message.registrationfailedmaxparticipants';
687
                $titleKey = 'registrationResult.title.failed';
688
                break;
689
            case RegistrationResult::REGISTRATION_NOT_ENABLED:
690
                $messageKey = 'event.message.registrationfailednotenabled';
691
                $titleKey = 'registrationResult.title.failed';
692
                break;
693
            case RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED:
694
                $messageKey = 'event.message.registrationfaileddeadlineexpired';
695
                $titleKey = 'registrationResult.title.failed';
696
                break;
697
            case RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES:
698
                $messageKey = 'event.message.registrationfailednotenoughfreeplaces';
699
                $titleKey = 'registrationResult.title.failed';
700
                break;
701
            case RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED:
702
                $messageKey = 'event.message.registrationfailedmaxamountregistrationsexceeded';
703
                $titleKey = 'registrationResult.title.failed';
704
                break;
705
            case RegistrationResult::REGISTRATION_FAILED_EMAIL_NOT_UNIQUE:
706
                $messageKey = 'event.message.registrationfailedemailnotunique';
707
                $titleKey = 'registrationResult.title.failed';
708
                break;
709
            default:
710
                $messageKey = '';
711
                $titleKey = '';
712
        }
713
714
        if (!$this->hashService->validateHmac('event-' . $eventuid, $hmac)) {
715
            $messageKey = 'event.message.registrationsuccessfulwrongeventhmac';
716
            $titleKey = 'registrationResult.title.failed';
717
        } else {
718
            $event = $this->eventRepository->findByUid((int)$eventuid);
719
        }
720
721
        $this->view->assignMultiple([
722
            'messageKey' => $messageKey,
723
            'titleKey' => $titleKey,
724
            'event' => $event,
725
        ]);
726
    }
727
728
    /**
729
     * Confirms the registration if possible and sends emails to admin and user
730
     *
731
     * @param int $reguid UID of registration
732
     * @param string $hmac HMAC for parameters
733
     */
734
    public function confirmRegistrationAction($reguid, $hmac)
735
    {
736
        $event = null;
737
738
        /* @var $registration Registration */
739
        list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkConfirmRegistration(
740
            $reguid,
741
            $hmac
742
        );
743
744
        if ($failed === false) {
745
            $registration->setConfirmed(true);
746
            $event = $registration->getEvent();
747
            $this->registrationRepository->update($registration);
748
749
            $this->eventDispatcher->dispatch(new AfterRegistrationConfirmedEvent($registration, $this));
750
751
            $messageType = MessageType::REGISTRATION_CONFIRMED;
752
            if ($registration->getWaitlist()) {
753
                $messageType = MessageType::REGISTRATION_WAITLIST_CONFIRMED;
754
            }
755
756
            // Send notifications to user and admin
757
            $this->notificationService->sendUserMessage(
758
                $registration->getEvent(),
759
                $registration,
760
                $this->settings,
761
                $messageType
762
            );
763
            $this->notificationService->sendAdminMessage(
764
                $registration->getEvent(),
765
                $registration,
766
                $this->settings,
767
                $messageType
768
            );
769
770
            // Confirm registrations depending on main registration if necessary
771
            if ($registration->getAmountOfRegistrations() > 1) {
772
                $this->registrationService->confirmDependingRegistrations($registration);
773
            }
774
        }
775
776
        // Redirect to payment provider if payment/redirect is enabled
777
        $paymentPid = (int)$this->settings['paymentPid'];
778
        if (!$failed && $paymentPid > 0 && $this->registrationService->redirectPaymentEnabled($registration)) {
779
            $this->uriBuilder->reset()
780
                ->setTargetPageUid($paymentPid);
781
            $uri = $this->uriBuilder->uriFor(
782
                'redirect',
783
                [
784
                    'registration' => $registration,
785
                    'hmac' => $this->hashService->generateHmac('redirectAction-' . $registration->getUid())
786
                ],
787
                'Payment',
788
                'sfeventmgt',
789
                'Pipayment'
790
            );
791
            $this->redirectToUri($uri);
792
        }
793
794
        $modifyConfirmRegistrationViewVariablesEvent = new ModifyConfirmRegistrationViewVariablesEvent(
795
            [
796
                'failed' => $failed,
797
                'messageKey' => $messageKey,
798
                'titleKey' => $titleKey,
799
                'event' => $event,
800
                'registration' => $registration,
801
            ],
802
            $this
803
        );
804
        $this->eventDispatcher->dispatch($modifyConfirmRegistrationViewVariablesEvent);
805
        $variables = $modifyConfirmRegistrationViewVariablesEvent->getVariables();
806
        $this->view->assignMultiple($variables);
807
    }
808
809
    /**
810
     * Cancels the registration if possible and sends emails to admin and user
811
     *
812
     * @param int $reguid UID of registration
813
     * @param string $hmac HMAC for parameters
814
     */
815
    public function cancelRegistrationAction($reguid, $hmac)
816
    {
817
        $event = null;
818
819
        /* @var $registration Registration */
820
        list($failed, $registration, $messageKey, $titleKey) =
821
            $this->registrationService->checkCancelRegistration($reguid, $hmac);
822
823
        if ($failed === false) {
824
            $event = $registration->getEvent();
825
826
            // Send notifications (must run before cancelling the registration)
827
            $this->notificationService->sendUserMessage(
828
                $registration->getEvent(),
829
                $registration,
830
                $this->settings,
831
                MessageType::REGISTRATION_CANCELLED
832
            );
833
            $this->notificationService->sendAdminMessage(
834
                $registration->getEvent(),
835
                $registration,
836
                $this->settings,
837
                MessageType::REGISTRATION_CANCELLED
838
            );
839
840
            // First cancel depending registrations
841
            if ($registration->getAmountOfRegistrations() > 1) {
842
                $this->registrationService->cancelDependingRegistrations($registration);
843
            }
844
845
            // Finally cancel registration
846
            $this->registrationRepository->remove($registration);
847
848
            // Persist changes, so following functions can work with $event properties (e.g. amount of registrations)
849
            $this->persistAll();
850
851
            // Dispatch event, so waitlist registrations can be moved up and default move up process can be stopped
852
            $waitlistMoveUpEvent = new WaitlistMoveUpEvent($event, $this, true);
853
            $this->eventDispatcher->dispatch($waitlistMoveUpEvent);
854
855
            // Move up waitlist registrations if configured on event basis and if not disabled by $waitlistMoveUpEvent
856
            if ($waitlistMoveUpEvent->getProcessDefaultMoveUp()) {
857
                $this->registrationService->moveUpWaitlistRegistrations($event, $this->settings);
858
            }
859
860
            // Flush page cache for event, since amount of registrations has changed
861
            $this->eventCacheService->flushEventCache($event->getUid(), $event->getPid());
0 ignored issues
show
Bug introduced by
It seems like $event->getUid() can also be of type null; however, parameter $eventUid of DERHANSEN\SfEventMgt\Ser...vice::flushEventCache() does only seem to accept integer, 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

861
            $this->eventCacheService->flushEventCache(/** @scrutinizer ignore-type */ $event->getUid(), $event->getPid());
Loading history...
Bug introduced by
It seems like $event->getPid() can also be of type null; however, parameter $eventPid of DERHANSEN\SfEventMgt\Ser...vice::flushEventCache() does only seem to accept integer, 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

861
            $this->eventCacheService->flushEventCache($event->getUid(), /** @scrutinizer ignore-type */ $event->getPid());
Loading history...
862
        }
863
864
        $modifyCancelRegistrationViewVariablesEvent = new ModifyCancelRegistrationViewVariablesEvent(
865
            [
866
                'failed' => $failed,
867
                'messageKey' => $messageKey,
868
                'titleKey' => $titleKey,
869
                'event' => $event,
870
            ],
871
            $this
872
        );
873
        $this->eventDispatcher->dispatch($modifyCancelRegistrationViewVariablesEvent);
874
        $variables = $modifyCancelRegistrationViewVariablesEvent->getVariables();
875
        $this->view->assignMultiple($variables);
876
    }
877
878
    /**
879
     * Set date format for field startDate and endDate
880
     */
881
    public function initializeSearchAction()
882
    {
883
        if ($this->settings !== null && $this->settings['search']['dateFormat']) {
884
            $this->arguments->getArgument('searchDemand')
885
                ->getPropertyMappingConfiguration()->forProperty('startDate')
886
                ->setTypeConverterOption(
887
                    DateTimeConverter::class,
888
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
889
                    $this->settings['search']['dateFormat']
890
                );
891
            $this->arguments->getArgument('searchDemand')
892
                ->getPropertyMappingConfiguration()->forProperty('endDate')
893
                ->setTypeConverterOption(
894
                    DateTimeConverter::class,
895
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
896
                    $this->settings['search']['dateFormat']
897
                );
898
        }
899
        if ($this->arguments->hasArgument('searchDemand')) {
900
            $propertyMappingConfiguration = $this->arguments->getArgument('searchDemand')
901
                ->getPropertyMappingConfiguration();
902
            $propertyMappingConfiguration->allowAllProperties();
903
            $propertyMappingConfiguration->setTypeConverterOption(
904
                PersistentObjectConverter::class,
905
                PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
906
                true
907
            );
908
        }
909
    }
910
911
    /**
912
     * Search view
913
     *
914
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand
915
     * @param array $overwriteDemand OverwriteDemand
916
     */
917
    public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = [])
918
    {
919
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
920
        $eventDemand->setSearchDemand($searchDemand);
921
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
922
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
923
924
        if ($searchDemand !== null) {
925
            $searchDemand->setFields($this->settings['search']['fields']);
926
927
            if ($this->settings['search']['adjustTime'] && $searchDemand->getStartDate() !== null) {
928
                $searchDemand->getStartDate()->setTime(0, 0, 0);
929
            }
930
931
            if ($this->settings['search']['adjustTime'] && $searchDemand->getEndDate() !== null) {
932
                $searchDemand->getEndDate()->setTime(23, 59, 59);
933
            }
934
        }
935
936
        if ($this->isOverwriteDemand($overwriteDemand)) {
937
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
938
        }
939
940
        $categories = $this->categoryRepository->findDemanded($categoryDemand);
941
        $locations = $this->locationRepository->findDemanded($foreignRecordDemand);
942
        $organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand);
943
        $speakers = $this->speakerRepository->findDemanded($foreignRecordDemand);
944
        $events = $this->eventRepository->findDemanded($eventDemand);
945
946
        $modifySearchViewVariablesEvent = new ModifySearchViewVariablesEvent(
947
            [
948
                'events' => $events,
949
                'categories' => $categories,
950
                'locations' => $locations,
951
                'organisators' => $organisators,
952
                'speakers' => $speakers,
953
                'searchDemand' => $searchDemand,
954
                'overwriteDemand' => $overwriteDemand,
955
            ],
956
            $this
957
        );
958
        $this->eventDispatcher->dispatch($modifySearchViewVariablesEvent);
959
        $variables = $modifySearchViewVariablesEvent->getVariables();
960
        $this->view->assignMultiple($variables);
961
    }
962
963
    /**
964
     * Returns if a demand object can be overwritten with the given overwriteDemand array
965
     *
966
     * @param array $overwriteDemand
967
     * @return bool
968
     */
969
    protected function isOverwriteDemand($overwriteDemand)
970
    {
971
        return $this->settings['disableOverrideDemand'] != 1 && $overwriteDemand !== [];
972
    }
973
974
    /**
975
     * If no event is given and the singleEvent setting is set, the configured single event is returned
976
     *
977
     * @param Event|null $event
978
     * @return Event|null
979
     */
980
    protected function evaluateSingleEventSetting($event)
981
    {
982
        if ($event === null && (int)$this->settings['singleEvent'] > 0) {
983
            $event = $this->eventRepository->findByUid((int)$this->settings['singleEvent']);
984
        }
985
986
        return $event;
987
    }
988
989
    /**
990
     * If no event is given and the isShortcut setting is set, the event is displayed using the "Insert Record"
991
     * content element and should be loaded from contect object data
992
     *
993
     * @param Event|null $event
994
     * @return Event|null
995
     */
996
    protected function evaluateIsShortcutSetting($event)
997
    {
998
        if ($event === null && (bool)$this->settings['detail']['isShortcut']) {
999
            $eventRawData = $this->configurationManager->getContentObject()->data;
1000
            $event = $this->eventRepository->findByUid($eventRawData['uid']);
1001
        }
1002
1003
        return $event;
1004
    }
1005
1006
    /**
1007
     * Checks if the event pid could be found in the storagePage settings of the detail plugin and
1008
     * if the pid could not be found it return null instead of the event object.
1009
     *
1010
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event
1011
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Event|null
1012
     */
1013
    protected function checkPidOfEventRecord(Event $event)
1014
    {
1015
        $allowedStoragePages = GeneralUtility::trimExplode(
1016
            ',',
1017
            Page::extendPidListByChildren(
1018
                $this->settings['storagePage'],
1019
                $this->settings['recursive']
1020
            ),
1021
            true
1022
        );
1023
        if (count($allowedStoragePages) > 0 && !in_array($event->getPid(), $allowedStoragePages)) {
1024
            $this->eventDispatcher->dispatch(new EventPidCheckFailedEvent($event, $this));
1025
            $event = null;
1026
        }
1027
1028
        return $event;
1029
    }
1030
1031
    /**
1032
     * Calls persistAll() of the persistenceManager
1033
     */
1034
    protected function persistAll()
1035
    {
1036
        $this->objectManager->get(PersistenceManager::class)->persistAll();
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated: since TYPO3 10.4, will be removed in version 12.0 ( Ignorable by Annotation )

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

1036
        /** @scrutinizer ignore-deprecated */ $this->objectManager->get(PersistenceManager::class)->persistAll();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The property TYPO3\CMS\Extbase\Mvc\Co...troller::$objectManager has been deprecated: since v11, will be removed in v12 ( Ignorable by Annotation )

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

1036
        /** @scrutinizer ignore-deprecated */ $this->objectManager->get(PersistenceManager::class)->persistAll();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
1037
    }
1038
1039
    /**
1040
     * Returns the current sys_language_uid
1041
     *
1042
     * @return int
1043
     */
1044
    protected function getSysLanguageUid(): int
1045
    {
1046
        $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
1047
1048
        return $languageAspect->getId();
1049
    }
1050
1051
    /**
1052
     * Returns the two letter ISO code for the current language
1053
     *
1054
     * @return string
1055
     */
1056
    protected function getCurrentLanguageTwoLetterIsoCode(): string
1057
    {
1058
        if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface &&
1059
            $GLOBALS['TYPO3_REQUEST']->getAttribute('language') instanceof SiteLanguage
1060
        ) {
1061
            /** @var SiteLanguage $siteLanguage */
1062
            $siteLanguage = $GLOBALS['TYPO3_REQUEST']->getAttribute('language');
1063
            return $siteLanguage->getTwoLetterIsoCode();
1064
        }
1065
1066
        return '';
1067
    }
1068
}
1069