Passed
Push — master ( da5c3a...138f6a )
by Torben
132:09 queued 128:49
created

EventController::processRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 6
ccs 1
cts 1
cp 1
crap 2
rs 10
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\Mvc\RequestInterface;
43
use TYPO3\CMS\Extbase\Mvc\ResponseInterface;
44
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
45
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
46
use TYPO3\CMS\Extbase\Property\TypeConverter\PersistentObjectConverter;
47
use TYPO3\CMS\Fluid\View\StandaloneView;
48
use TYPO3\CMS\Frontend\Controller\ErrorController;
49
50
/**
51
 * EventController
52
 */
53
class EventController extends AbstractController
54
{
55
    /**
56
     * @var EventCacheService
57
     */
58
    protected $eventCacheService;
59
60
    /**
61
     * @param EventCacheService $cacheService
62
     */
63
    public function injectEventCacheService(EventCacheService $cacheService)
64
    {
65
        $this->eventCacheService = $cacheService;
66
    }
67
68
    /**
69
     * Assign contentObjectData and pageData to earch view
70
     *
71
     * @param \TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view
72
     */
73
    protected function initializeView(\TYPO3\CMS\Extbase\Mvc\View\ViewInterface $view)
74
    {
75
        $view->assign('contentObjectData', $this->configurationManager->getContentObject()->data);
76
        if (is_object($GLOBALS['TSFE'])) {
77
            $view->assign('pageData', $GLOBALS['TSFE']->page);
78
        }
79
        parent::initializeView($view);
80
    }
81
82
    /**
83
     * Initializes the current action
84
     */
85
    public function initializeAction()
86
    {
87
        $typoScriptFrontendController = $this->getTypoScriptFrontendController();
88
        if ($typoScriptFrontendController !== null) {
89
            static $cacheTagsSet = false;
90
91
            if (!$cacheTagsSet) {
92
                $typoScriptFrontendController->addCacheTags(['tx_sfeventmgt']);
93
                $cacheTagsSet = true;
94
            }
95
        }
96
    }
97
98
    /**
99
     * Creates an event demand object with the given settings
100
     *
101
     * @param array $settings The settings
102
     *
103
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand
104
     */
105
    public function createEventDemandObjectFromSettings(array $settings)
106
    {
107
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand */
108
        $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

108
        $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...
109
        $demand->setDisplayMode($settings['displayMode']);
110
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
111
        $demand->setCategoryConjunction($settings['categoryConjunction']);
112
        $demand->setCategory($settings['category']);
113
        $demand->setIncludeSubcategories($settings['includeSubcategories']);
114
        $demand->setTopEventRestriction((int)$settings['topEventRestriction']);
115
        $demand->setOrderField($settings['orderField']);
116
        $demand->setOrderFieldAllowed($settings['orderFieldAllowed']);
117
        $demand->setOrderDirection($settings['orderDirection']);
118
        $demand->setQueryLimit($settings['queryLimit']);
119
        $demand->setLocation($settings['location']);
120
        $demand->setOrganisator($settings['organisator']);
121
        $demand->setSpeaker($settings['speaker']);
122
        $demand->setTimeRestrictionLow($settings['timeRestrictionLow']);
123
        $demand->setTimeRestrictionHigh($settings['timeRestrictionHigh']);
124
        $demand->setIncludeCurrent($settings['includeCurrent']);
125
126
        return $demand;
127
    }
128
129
    /**
130
     * Creates a foreign record demand object with the given settings
131
     *
132
     * @param array $settings The settings
133
     *
134
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand
135
     */
136
    public function createForeignRecordDemandObjectFromSettings(array $settings)
137 2
    {
138
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand $demand */
139
        $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

139
        $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...
140 2
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
141 2
        $demand->setRestrictForeignRecordsToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']);
142 2
143 2
        return $demand;
144 2
    }
145 2
146 2
    /**
147 2
     * Creates a category demand object with the given settings
148 2
     *
149 2
     * @param array $settings The settings
150 2
     *
151 2
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand
152
     */
153
    public function createCategoryDemandObjectFromSettings(array $settings)
154
    {
155
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand $demand */
156
        $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

156
        $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...
157
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
158
        $demand->setRestrictToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']);
159
        $demand->setCategories($settings['categoryMenu']['categories']);
160
        $demand->setIncludeSubcategories($settings['categoryMenu']['includeSubcategories']);
161
        $demand->setOrderField($settings['categoryMenu']['orderField'] ?? 'uid');
162
        $demand->setOrderDirection($settings['categoryMenu']['orderDirection'] ?? 'asc');
163
164
        return $demand;
165
    }
166
167
    /**
168
     * Hook into request processing and catch exceptions
169
     *
170
     * @param RequestInterface $request
171
     * @param ResponseInterface $response
172
     * @throws \Exception
173
     */
174
    public function processRequest(RequestInterface $request, ResponseInterface $response)
175
    {
176
        try {
177 2
            parent::processRequest($request, $response);
178
        } catch (\Exception $exception) {
179
            $this->handleKnownExceptionsElseThrowAgain($exception);
180 2
        }
181 2
    }
182 2
183 2
    /**
184 2
     * Handle known exceptions
185 2
     *
186
     * @param \Exception $exception
187
     * @throws \Exception
188
     */
189
    private function handleKnownExceptionsElseThrowAgain(\Exception $exception)
190
    {
191
        $previousException = $exception->getPrevious();
192
        $actions = ['detailAction', 'registrationAction', 'icalDownloadAction'];
193
        if (in_array($this->actionMethodName, $actions, true)
194
            && $previousException instanceof \TYPO3\CMS\Extbase\Property\Exception
195
        ) {
196 4
            $this->handleEventNotFoundError($this->settings);
197
        } else {
198 4
            throw $exception;
199 4
        }
200 4
    }
201
202 4
    /**
203 4
     * Initialize list action and set format
204 2
     */
205
    public function initializeListAction()
206 4
    {
207 4
        if (isset($this->settings['list']['format'])) {
208 4
            $this->request->setFormat($this->settings['list']['format']);
209
        }
210
    }
211
212
    /**
213
     * List view
214
     *
215
     * @param array $overwriteDemand OverwriteDemand
216
     */
217
    public function listAction(array $overwriteDemand = [])
218
    {
219
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
220
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
221
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
222
        if ($this->isOverwriteDemand($overwriteDemand)) {
223
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
224
        }
225
        $events = $this->eventRepository->findDemanded($eventDemand);
226
        $categories = $this->categoryRepository->findDemanded($categoryDemand);
227
        $locations = $this->locationRepository->findDemanded($foreignRecordDemand);
228
        $organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand);
229
        $speakers = $this->speakerRepository->findDemanded($foreignRecordDemand);
230 6
231
        $modifyListViewVariablesEvent = new ModifyListViewVariablesEvent(
232 6
            [
233 6
                'events' => $events,
234 6
                'categories' => $categories,
235 6
                'locations' => $locations,
236 2
                'organisators' => $organisators,
237 2
                'speakers' => $speakers,
238 6
                'overwriteDemand' => $overwriteDemand,
239 6
                'eventDemand' => $eventDemand
240 6
            ],
241 6
            $this
242 6
        );
243 6
        $this->eventDispatcher->dispatch($modifyListViewVariablesEvent);
244 6
        $variables = $modifyListViewVariablesEvent->getVariables();
245 6
        $this->view->assignMultiple($variables);
246
247
        $this->eventCacheService->addPageCacheTagsByEventDemandObject($eventDemand);
248
    }
249
250
    /**
251
     * Calendar view
252
     *
253
     * @param array $overwriteDemand OverwriteDemand
254 2
     */
255
    public function calendarAction(array $overwriteDemand = [])
256 2
    {
257 2
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
258
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
259
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
260
        if ($this->isOverwriteDemand($overwriteDemand)) {
261
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
262
        }
263
264
        // Set month/year to demand if not given
265
        if (!$eventDemand->getMonth()) {
266 2
            $currentMonth = date('n');
267
            $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

267
            $eventDemand->setMonth(/** @scrutinizer ignore-type */ $currentMonth);
Loading history...
268 2
        } else {
269 2
            $currentMonth = $eventDemand->getMonth();
270
        }
271
        if (!$eventDemand->getYear()) {
272
            $currentYear = date('Y');
273
            $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

273
            $eventDemand->setYear(/** @scrutinizer ignore-type */ $currentYear);
Loading history...
274
        } else {
275
            $currentYear = $eventDemand->getYear();
276
        }
277
278
        // Set demand from calendar date range instead of month / year
279 2
        if ((bool)$this->settings['calendar']['includeEventsForEveryDayOfAllCalendarWeeks']) {
280
            $eventDemand = $this->changeEventDemandToFullMonthDateRange($eventDemand);
281 2
        }
282
283
        $events = $this->eventRepository->findDemanded($eventDemand);
284 2
        $weeks = $this->calendarService->getCalendarArray(
285
            $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

285
            /** @scrutinizer ignore-type */ $currentMonth,
Loading history...
286 2
            $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

286
            /** @scrutinizer ignore-type */ $currentYear,
Loading history...
287 2
            strtotime('today midnight'),
288 2
            (int)$this->settings['calendar']['firstDayOfWeek'],
289
            $events
290
        );
291
292
        $modifyCalendarViewVariablesEvent = new ModifyCalendarViewVariablesEvent(
293
            [
294
                'events' => $events,
295 2
                'weeks' => $weeks,
296
                'categories' => $this->categoryRepository->findDemanded($categoryDemand),
297 2
                'locations' => $this->locationRepository->findDemanded($foreignRecordDemand),
298 2
                'organisators' => $this->organisatorRepository->findDemanded($foreignRecordDemand),
299 2
                'eventDemand' => $eventDemand,
300 2
                'overwriteDemand' => $overwriteDemand,
301 2
                'currentPageId' => $GLOBALS['TSFE']->id,
302 2
                'firstDayOfMonth' => \DateTime::createFromFormat(
303 2
                    'd.m.Y',
304 2
                    sprintf('1.%s.%s', $currentMonth, $currentYear)
305
                ),
306
                'previousMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '-1 month'),
0 ignored issues
show
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

306
                'previousMonthConfig' => $this->calendarService->getDateConfig($currentMonth, /** @scrutinizer ignore-type */ $currentYear, '-1 month'),
Loading history...
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

306
                'previousMonthConfig' => $this->calendarService->getDateConfig(/** @scrutinizer ignore-type */ $currentMonth, $currentYear, '-1 month'),
Loading history...
307
                'nextMonthConfig' => $this->calendarService->getDateConfig($currentMonth, $currentYear, '+1 month')
308
            ],
309
            $this
310
        );
311
        $this->eventDispatcher->dispatch($modifyCalendarViewVariablesEvent);
312
        $variables = $modifyCalendarViewVariablesEvent->getVariables();
313
314
        $this->view->assignMultiple($variables);
315 22
    }
316
317 22
    /**
318 22
     * Changes the given event demand object to select a date range for a calendar month including days of the previous
319 22
     * month for the first week and they days for the next month for the last week
320
     *
321
     * @param EventDemand $eventDemand
322 22
     * @return EventDemand
323 8
     */
324 8
    protected function changeEventDemandToFullMonthDateRange(EventDemand $eventDemand)
325 8
    {
326 8
        $calendarDateRange = $this->calendarService->getCalendarDateRange(
327 8
            $eventDemand->getMonth(),
328 8
            $eventDemand->getYear(),
329
            $this->settings['calendar']['firstDayOfWeek']
330 8
        );
331 8
332 8
        $eventDemand->setMonth(0);
333 8
        $eventDemand->setYear(0);
334
335 8
        $startDate = new \DateTime();
336 8
        $startDate->setTimestamp($calendarDateRange['firstDayOfCalendar']);
337 8
        $endDate = new \DateTime();
338 8
        $endDate->setTimestamp($calendarDateRange['lastDayOfCalendar']);
339 8
        $endDate->setTime(23, 59, 59);
340 8
341 8
        $searchDemand = new SearchDemand();
342 8
        $searchDemand->setStartDate($startDate);
343
        $searchDemand->setEndDate($endDate);
344
        $eventDemand->setSearchDemand($searchDemand);
345 8
346
        return $eventDemand;
347
    }
348 8
349 2
    /**
350 2
     * Detail view for an event
351 2
     *
352 6
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
353 6
     * @return mixed string|void
354
     */
355 8
    public function detailAction(Event $event = null)
356
    {
357
        $event = $this->evaluateSingleEventSetting($event);
358 8
        $event = $this->evaluateIsShortcutSetting($event);
359 6
        if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) {
360 6
            $event = $this->checkPidOfEventRecord($event);
361 6
        }
362 6
363
        if (is_null($event) && isset($this->settings['event']['errorHandling'])) {
364 6
            return $this->handleEventNotFoundError($this->settings);
365 6
        }
366 6
367 6
        $modifyDetailViewVariablesEvent = new ModifyDetailViewVariablesEvent(['event' => $event], $this);
368 6
        $this->eventDispatcher->dispatch($modifyDetailViewVariablesEvent);
369
        $variables = $modifyDetailViewVariablesEvent->getVariables();
370 6
371 6
        $this->view->assignMultiple($variables);
372
        if ($event !== null) {
373
            $this->eventCacheService->addCacheTagsByEventRecords([$event]);
374 8
        }
375 2
    }
376 2
377
    /**
378
     * Error handling if event is not found
379 8
     *
380 8
     * @param array $settings
381
     */
382 22
    protected function handleEventNotFoundError($settings)
383 2
    {
384 2
        if (empty($settings['event']['errorHandling'])) {
385 2
            return null;
386 2
        }
387
388 2
        $configuration = GeneralUtility::trimExplode(',', $settings['event']['errorHandling'], true);
389 2
390 2
        switch ($configuration[0]) {
391 2
            case 'redirectToListView':
392 2
                $listPid = (int)$settings['listPid'] > 0 ? (int)$settings['listPid'] : 1;
393 20
                $this->redirect('list', null, null, null, $listPid);
394 20
                break;
395 20
            case 'pageNotFoundHandler':
396 20
                $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
397 20
                    $GLOBALS['TYPO3_REQUEST'],
398 20
                    'Event not found.'
399
                );
400 22
                throw new ImmediateResponseException($response, 1549896549734);
401
                break;
402
            case 'showStandaloneTemplate':
403
                if (isset($configuration[2])) {
404
                    $statusCode = constant(HttpUtility::class . '::HTTP_STATUS_' . $configuration[2]);
405
                    HttpUtility::setResponseCode($statusCode);
406
                }
407
                $standaloneTemplate = GeneralUtility::makeInstance(StandaloneView::class);
408
                $standaloneTemplate->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($configuration[1]));
409 18
410
                return $standaloneTemplate->render();
411
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
412 18
            default:
413 2
        }
414 2
    }
415 2
416 16
    /**
417
     * Initiates the iCalendar download for the given event
418
     *
419
     * @param Event $event The event
420 16
     *
421 2
     * @return string|false
422 2
     */
423 2
    public function icalDownloadAction(Event $event = null)
424 14
    {
425 2
        if (is_a($event, Event::class) && $this->settings['detail']['checkPidOfEventRecord']) {
426 2
            $event = $this->checkPidOfEventRecord($event);
427 2
        }
428 12
        if (is_null($event) && isset($this->settings['event']['errorHandling'])) {
429 2
            return $this->handleEventNotFoundError($this->settings);
430 2
        }
431 2
        $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

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

902
            $this->eventCacheService->flushEventCache($event->getUid(), /** @scrutinizer ignore-type */ $event->getPid());
Loading history...
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

902
            $this->eventCacheService->flushEventCache(/** @scrutinizer ignore-type */ $event->getUid(), $event->getPid());
Loading history...
903
        }
904
905
        $modifyCancelRegistrationViewVariablesEvent = new ModifyCancelRegistrationViewVariablesEvent(
906
            [
907
                'failed' => $failed,
908
                'messageKey' => $messageKey,
909
                'titleKey' => $titleKey,
910
                'event' => $event,
911
            ],
912
            $this
913
        );
914
        $this->eventDispatcher->dispatch($modifyCancelRegistrationViewVariablesEvent);
915
        $variables = $modifyCancelRegistrationViewVariablesEvent->getVariables();
916
        $this->view->assignMultiple($variables);
917
    }
918
919
    /**
920
     * Set date format for field startDate and endDate
921
     */
922
    public function initializeSearchAction()
923
    {
924
        if ($this->settings !== null && $this->settings['search']['dateFormat']) {
925
            $this->arguments->getArgument('searchDemand')
926
                ->getPropertyMappingConfiguration()->forProperty('startDate')
927
                ->setTypeConverterOption(
928
                    DateTimeConverter::class,
929
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
930
                    $this->settings['search']['dateFormat']
931
                );
932
            $this->arguments->getArgument('searchDemand')
933
                ->getPropertyMappingConfiguration()->forProperty('endDate')
934
                ->setTypeConverterOption(
935
                    DateTimeConverter::class,
936
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
937
                    $this->settings['search']['dateFormat']
938
                );
939
        }
940
        if ($this->arguments->hasArgument('searchDemand')) {
941
            $propertyMappingConfiguration = $this->arguments->getArgument('searchDemand')
942
                ->getPropertyMappingConfiguration();
943
            $propertyMappingConfiguration->allowAllProperties();
944
            $propertyMappingConfiguration->setTypeConverterOption(
945
                PersistentObjectConverter::class,
946
                PersistentObjectConverter::CONFIGURATION_CREATION_ALLOWED,
947
                true
948
            );
949
        }
950
    }
951
952
    /**
953
     * Search view
954
     *
955
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand
956
     * @param array $overwriteDemand OverwriteDemand
957
     */
958
    public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = [])
959
    {
960
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
961
        $eventDemand->setSearchDemand($searchDemand);
962
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
963
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
964
965
        if ($searchDemand !== null) {
966
            $searchDemand->setFields($this->settings['search']['fields']);
967
968
            if ($this->settings['search']['adjustTime'] && $searchDemand->getStartDate() !== null) {
969
                $searchDemand->getStartDate()->setTime(0, 0, 0);
970
            }
971
972
            if ($this->settings['search']['adjustTime'] && $searchDemand->getEndDate() !== null) {
973
                $searchDemand->getEndDate()->setTime(23, 59, 59);
974
            }
975
        }
976
977
        if ($this->isOverwriteDemand($overwriteDemand)) {
978
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
979
        }
980
981
        $categories = $this->categoryRepository->findDemanded($categoryDemand);
982
        $locations = $this->locationRepository->findDemanded($foreignRecordDemand);
983
        $organisators = $this->organisatorRepository->findDemanded($foreignRecordDemand);
984
        $speakers = $this->speakerRepository->findDemanded($foreignRecordDemand);
985
        $events = $this->eventRepository->findDemanded($eventDemand);
986
987
        $modifySearchViewVariablesEvent = new ModifySearchViewVariablesEvent(
988
            [
989
                'events' => $events,
990
                'categories' => $categories,
991
                'locations' => $locations,
992
                'organisators' => $organisators,
993
                'speakers' => $speakers,
994
                'searchDemand' => $searchDemand,
995
                'overwriteDemand' => $overwriteDemand,
996
            ],
997
            $this
998
        );
999
        $this->eventDispatcher->dispatch($modifySearchViewVariablesEvent);
1000
        $variables = $modifySearchViewVariablesEvent->getVariables();
1001
        $this->view->assignMultiple($variables);
1002
    }
1003
1004
    /**
1005
     * Returns if a demand object can be overwritten with the given overwriteDemand array
1006
     *
1007
     * @param array $overwriteDemand
1008
     * @return bool
1009
     */
1010
    protected function isOverwriteDemand($overwriteDemand)
1011
    {
1012
        return $this->settings['disableOverrideDemand'] != 1 && $overwriteDemand !== [];
1013
    }
1014
1015
    /**
1016
     * If no event is given and the singleEvent setting is set, the configured single event is returned
1017
     *
1018
     * @param Event|null $event
1019
     * @return Event|null
1020
     */
1021
    protected function evaluateSingleEventSetting($event)
1022
    {
1023
        if ($event === null && (int)$this->settings['singleEvent'] > 0) {
1024
            $event = $this->eventRepository->findByUid((int)$this->settings['singleEvent']);
1025
        }
1026
1027
        return $event;
1028
    }
1029
1030
    /**
1031
     * If no event is given and the isShortcut setting is set, the event is displayed using the "Insert Record"
1032
     * content element and should be loaded from contect object data
1033
     *
1034
     * @param Event|null $event
1035
     * @return Event|null
1036
     */
1037
    protected function evaluateIsShortcutSetting($event)
1038
    {
1039
        if ($event === null && (bool)$this->settings['detail']['isShortcut']) {
1040
            $eventRawData = $this->configurationManager->getContentObject()->data;
1041
            $event = $this->eventRepository->findByUid($eventRawData['uid']);
1042
        }
1043
1044
        return $event;
1045
    }
1046
1047
    /**
1048
     * Checks if the event pid could be found in the storagePage settings of the detail plugin and
1049
     * if the pid could not be found it return null instead of the event object.
1050
     *
1051
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event
1052
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Event|null
1053
     */
1054
    protected function checkPidOfEventRecord(Event $event)
1055
    {
1056
        $allowedStoragePages = GeneralUtility::trimExplode(
1057
            ',',
1058
            Page::extendPidListByChildren(
1059
                $this->settings['storagePage'],
1060
                $this->settings['recursive']
1061
            ),
1062
            true
1063
        );
1064
        if (count($allowedStoragePages) > 0 && !in_array($event->getPid(), $allowedStoragePages)) {
1065
            $this->eventDispatcher->dispatch(new EventPidCheckFailedEvent($event, $this));
1066
            $event = null;
1067
        }
1068
1069
        return $event;
1070
    }
1071
1072
    /**
1073
     * Calls persistAll() of the persistenceManager
1074
     */
1075
    protected function persistAll()
1076
    {
1077
        $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

1077
        /** @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...
1078
    }
1079
1080
    /**
1081
     * Returns the current sys_language_uid
1082
     *
1083
     * @return int
1084
     */
1085
    protected function getSysLanguageUid(): int
1086
    {
1087
        $languageAspect = GeneralUtility::makeInstance(Context::class)->getAspect('language');
1088
1089
        return $languageAspect->getId();
1090
    }
1091
1092
    /**
1093
     * Returns the two letter ISO code for the current language
1094
     *
1095
     * @return string
1096
     */
1097
    protected function getCurrentLanguageTwoLetterIsoCode(): string
1098
    {
1099
        if ($GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface &&
1100
            $GLOBALS['TYPO3_REQUEST']->getAttribute('language') instanceof SiteLanguage
1101
        ) {
1102
            /** @var SiteLanguage $siteLanguage */
1103
            $siteLanguage = $GLOBALS['TYPO3_REQUEST']->getAttribute('language');
1104
            return $siteLanguage->getTwoLetterIsoCode();
1105
        }
1106
1107
        return '';
1108
    }
1109
}
1110