Completed
Push — master ( ec29fe...2e5711 )
by Torben
09:02 queued 07:11
created

EventController::confirmRegistrationAction()   B

Complexity

Conditions 7
Paths 10

Size

Total Lines 56
Code Lines 35

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 8.5623

Importance

Changes 0
Metric Value
dl 0
loc 56
ccs 28
cts 41
cp 0.6828
rs 7.7489
c 0
b 0
f 0
cc 7
eloc 35
nc 10
nop 2
crap 8.5623

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace DERHANSEN\SfEventMgt\Controller;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
use DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand;
18
use DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand;
19
use DERHANSEN\SfEventMgt\Domain\Model\Event;
20
use DERHANSEN\SfEventMgt\Domain\Model\Registration;
21
use DERHANSEN\SfEventMgt\Utility\RegistrationResult;
22
use DERHANSEN\SfEventMgt\Utility\MessageType;
23
use DERHANSEN\SfEventMgt\Utility\Page;
24
use TYPO3\CMS\Core\Utility\DebugUtility;
25
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
26
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
27
28
/**
29
 * EventController
30
 *
31
 * @author Torben Hansen <[email protected]>
32
 */
33
class EventController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
34
{
35
36
    /**
37
     * Configuration Manager
38
     *
39
     * @var ConfigurationManagerInterface
40
     */
41
    protected $configurationManager;
42
43
    /**
44
     * EventRepository
45
     *
46
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\EventRepository
47
     * @inject
48
     */
49
    protected $eventRepository = null;
50
51
    /**
52
     * Registration repository
53
     *
54
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository
55
     * @inject
56
     */
57
    protected $registrationRepository = null;
58
59
    /**
60
     * Category repository
61
     *
62
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\CategoryRepository
63
     * @inject
64
     */
65
    protected $categoryRepository = null;
66
67
    /**
68
     * Location repository
69
     *
70
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\LocationRepository
71
     * @inject
72
     */
73
    protected $locationRepository = null;
74
75
    /**
76
     * Notification Service
77
     *
78
     * @var \DERHANSEN\SfEventMgt\Service\NotificationService
79
     * @inject
80
     */
81
    protected $notificationService = null;
82
83
    /**
84
     * ICalendar Service
85
     *
86
     * @var \DERHANSEN\SfEventMgt\Service\ICalendarService
87
     * @inject
88
     */
89
    protected $icalendarService = null;
90
91
    /**
92
     * Hash Service
93
     *
94
     * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService
95
     * @inject
96
     */
97
    protected $hashService;
98
99
    /**
100
     * RegistrationService
101
     *
102
     * @var \DERHANSEN\SfEventMgt\Service\RegistrationService
103
     * @inject
104
     */
105
    protected $registrationService = null;
106
107
    /**
108
     * UtilityService
109
     *
110
     * @var \DERHANSEN\SfEventMgt\Service\UtilityService
111
     * @inject
112
     */
113
    protected $utilityService = null;
114
115
    /**
116
     * PaymentMethodService
117
     *
118
     * @var \DERHANSEN\SfEventMgt\Service\PaymentService
119
     * @inject
120
     */
121
    protected $paymentService = null;
122
    
123
    /**
124
     * Properties in this array will be ignored by overwriteDemandObject()
125
     *
126
     * @var array
127
     */
128
    protected $ignoredSettingsForOverwriteDemand = ['storagePage'];
129
130
    /**
131
     * Creates an event demand object with the given settings
132
     *
133
     * @param array $settings The settings
134
     *
135
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand
136
     */
137 1
    public function createEventDemandObjectFromSettings(array $settings)
138
    {
139
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand */
140 1
        $demand = $this->objectManager->get('DERHANSEN\\SfEventMgt\\Domain\\Model\\Dto\\EventDemand');
141 1
        $demand->setDisplayMode($settings['displayMode']);
142 1
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
143 1
        $demand->setCategory($settings['category']);
144 1
        $demand->setIncludeSubcategories($settings['includeSubcategories']);
145 1
        $demand->setTopEventRestriction((int)$settings['topEventRestriction']);
146 1
        $demand->setOrderField($settings['orderField']);
147 1
        $demand->setOrderDirection($settings['orderDirection']);
148 1
        $demand->setQueryLimit($settings['queryLimit']);
149 1
        $demand->setLocation($settings['location']);
150 1
        return $demand;
151
    }
152
153
    /**
154
     * Creates a foreign record demand object with the given settings
155
     *
156
     * @param array $settings The settings
157
     *
158
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand
159
     */
160
    public function createForeignRecordDemandObjectFromSettings(array $settings)
161
    {
162
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand $demand */
163
        $demand = $this->objectManager->get('DERHANSEN\\SfEventMgt\\Domain\\Model\\Dto\\ForeignRecordDemand');
164
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
165
        $demand->setRestrictForeignRecordsToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']);
166
        return $demand;
167
    }
168
169
    /**
170
     * Creates a category demand object with the given settings
171
     *
172
     * @param array $settings The settings
173
     *
174
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand
175
     */
176 1
    public function createCategoryDemandObjectFromSettings(array $settings)
177
    {
178
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand $demand */
179 1
        $demand = $this->objectManager->get('DERHANSEN\\SfEventMgt\\Domain\\Model\\Dto\\CategoryDemand');
180 1
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
181 1
        $demand->setRestrictToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']);
182 1
        $demand->setCategories($settings['categoryMenu']['categories']);
183 1
        $demand->setIncludeSubcategories($settings['categoryMenu']['includeSubcategories']);
184 1
        return $demand;
185
    }
186
187
    /**
188
     * Overwrites a given demand object by an propertyName =>  $propertyValue array
189
     *
190
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand Demand
191
     * @param array $overwriteDemand OwerwriteDemand
192
     *
193
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand
194
     */
195 2
    protected function overwriteEventDemandObject(EventDemand $demand, array $overwriteDemand)
196
    {
197 2
        foreach ($this->ignoredSettingsForOverwriteDemand as $property) {
198 2
            unset($overwriteDemand[$property]);
199 2
        }
200
201 2
        foreach ($overwriteDemand as $propertyName => $propertyValue) {
202 2
            \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($demand, $propertyName, $propertyValue);
203 2
        }
204 2
        return $demand;
205
    }
206
207
    /**
208
     * List view
209
     *
210
     * @param array $overwriteDemand OverwriteDemand
211
     *
212
     * @return void
213
     */
214 3
    public function listAction(array $overwriteDemand = [])
215
    {
216 3
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
217 3
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
218 3
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
219 3
        if ($this->isOverwriteDemand($overwriteDemand)) {
220 1
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
221 1
        }
222 3
        $events = $this->eventRepository->findDemanded($eventDemand);
223 3
        $categories = $this->categoryRepository->findDemanded($categoryDemand);
224 3
        $locations = $this->locationRepository->findDemanded($foreignRecordDemand);
225 3
        $this->view->assign('events', $events);
226 3
        $this->view->assign('categories', $categories);
227 3
        $this->view->assign('locations', $locations);
228 3
        $this->view->assign('overwriteDemand', $overwriteDemand);
229 3
    }
230
231
    /**
232
     * Detail view for an event
233
     *
234
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
235
     *
236
     * @return void
237
     */
238 1
    public function detailAction(Event $event = null)
239
    {
240 1
        $this->view->assign('event', $event);
241 1
    }
242
243
    /**
244
     * Initiates the iCalendar download for the given event
245
     *
246
     * @param Event $event The event
247
     *
248
     * @return bool
249
     */
250 1
    public function icalDownloadAction(Event $event)
251
    {
252 1
        $this->icalendarService->downloadiCalendarFile($event);
253 1
        return false;
254
    }
255
256
    /**
257
     * Registration view for an event
258
     *
259
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
260
     *
261
     * @return void
262
     */
263 1
    public function registrationAction(Event $event)
264
    {
265 1
        if ($event->getRestrictPaymentMethods()) {
266
            $paymentMethods = $this->paymentService->getRestrictedPaymentMethods($event);
267
        } else {
268 1
            $paymentMethods = $this->paymentService->getPaymentMethods();
269
        }
270 1
        $this->view->assign('event', $event);
271 1
        $this->view->assign('paymentMethods', $paymentMethods);
272 1
    }
273
274
    /**
275
     * Set date format for field dateOfBirth
276
     *
277
     * @return void
278
     */
279 1
    public function initializeSaveRegistrationAction()
280
    {
281 1
        $this->arguments->getArgument('registration')
282 1
            ->getPropertyMappingConfiguration()->forProperty('dateOfBirth')
283 1
            ->setTypeConverterOption(
284 1
                'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
285 1
                DateTimeConverter::CONFIGURATION_DATE_FORMAT,
286 1
                $this->settings['registration']['formatDateOfBirth']
287 1
            );
288 1
    }
289
290
    /**
291
     * Saves the registration
292
     *
293
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
294
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
295
     * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator
296
     *
297
     * @return void
298
     */
299 11
    public function saveRegistrationAction(Registration $registration, Event $event)
300
    {
301 11
        $autoConfirmation = (bool)$this->settings['registration']['autoConfirmation'];
302 11
        $result = RegistrationResult::REGISTRATION_SUCCESSFUL;
303 11
        $success = $this->registrationService->checkRegistrationSuccess($event, $registration, $result);
304
305
        // Save registration if no errors
306 11
        if ($success) {
307 4
            $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration(
308 4
                $event,
309 4
                $registration->getAmountOfRegistrations()
310 4
            );
311 4
            $linkValidity = (int)$this->settings['confirmation']['linkValidity'];
312 4
            if ($linkValidity === 0) {
313
                // Use 3600 seconds as default value if not set
314 4
                $linkValidity = 3600;
315 4
            }
316 4
            $confirmationUntil = new \DateTime();
317 4
            $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S'));
318
319 4
            $registration->setEvent($event);
320 4
            $registration->setPid($event->getPid());
321 4
            $registration->setConfirmationUntil($confirmationUntil);
322 4
            $registration->setLanguage($GLOBALS['TSFE']->config['config']['language']);
323 4
            $registration->setFeUser($this->registrationService->getCurrentFeUserObject());
324 4
            $registration->setWaitlist($isWaitlistRegistration);
325 4
            $registration->_setProperty('_languageUid', $GLOBALS['TSFE']->sys_language_uid);
326 4
            $this->registrationRepository->add($registration);
327
328
            // Persist registration, so we have an UID
329 4
            $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager')->persistAll();
330
331
            // Add new registration (or waitlist registration) to event
332 4
            if ($isWaitlistRegistration) {
333 1
                $event->addRegistrationWaitlist($registration);
334 1
                $messageType = MessageType::REGISTRATION_WAITLIST_NEW;
335 1
            } else {
336 3
                $event->addRegistration($registration);
337 3
                $messageType = MessageType::REGISTRATION_NEW;
338
            }
339 4
            $this->eventRepository->update($event);
340
341
            // Send notifications to user and admin if confirmation link should be sent
342 4
            if (!$autoConfirmation) {
343 3
                $this->notificationService->sendUserMessage(
344 3
                    $event,
345 3
                    $registration,
346 3
                    $this->settings,
347
                    $messageType
348 3
                );
349 3
                $this->notificationService->sendAdminMessage(
350 3
                    $event,
351 3
                    $registration,
352 3
                    $this->settings,
353
                    $messageType
354 3
                );
355 3
            }
356
357
            // Create given amount of registrations if necessary
358 4
            if ($registration->getAmountOfRegistrations() > 1) {
359 1
                $this->registrationService->createDependingRegistrations($registration);
360 1
            }
361
362
            // Clear cache for configured pages
363 4
            $this->utilityService->clearCacheForConfiguredUids($this->settings);
364 4
        }
365
366 11
        if ($autoConfirmation && $success) {
367 1
            $this->redirect(
368 1
                'confirmRegistration',
369 1
                null,
370 1
                null,
371
                [
372 1
                    'reguid' => $registration->getUid(),
373 1
                    'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid())
374 1
                ]
375 1
            );
376 1
        } else {
377 10
            $this->redirect(
378 10
                'saveRegistrationResult',
379 10
                null,
380 10
                null,
381 10
                ['result' => $result]
382 10
            );
383
        }
384 11
    }
385
386
    /**
387
     * Shows the result of the saveRegistrationAction
388
     *
389
     * @param int $result Result
390
     *
391
     * @return void
392
     */
393 9
    public function saveRegistrationResultAction($result)
394
    {
395
        switch ($result) {
396 9
            case RegistrationResult::REGISTRATION_SUCCESSFUL:
397 1
                $messageKey = 'event.message.registrationsuccessful';
398 1
                $titleKey = 'registrationResult.title.successful';
399 1
                break;
400 8
            case RegistrationResult::REGISTRATION_SUCCESSFUL_WAITLIST:
401
                $messageKey = 'event.message.registrationwaitlistsuccessful';
402
                $titleKey = 'registrationWaitlistResult.title.successful';
403
                break;
404 8
            case RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED:
405 1
                $messageKey = 'event.message.registrationfailedeventexpired';
406 1
                $titleKey = 'registrationResult.title.failed';
407 1
                break;
408 7
            case RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS:
409 1
                $messageKey = 'event.message.registrationfailedmaxparticipants';
410 1
                $titleKey = 'registrationResult.title.failed';
411 1
                break;
412 6
            case RegistrationResult::REGISTRATION_NOT_ENABLED:
413 1
                $messageKey = 'event.message.registrationfailednotenabled';
414 1
                $titleKey = 'registrationResult.title.failed';
415 1
                break;
416 5
            case RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED:
417 1
                $messageKey = 'event.message.registrationfaileddeadlineexpired';
418 1
                $titleKey = 'registrationResult.title.failed';
419 1
                break;
420 4
            case RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES:
421 1
                $messageKey = 'event.message.registrationfailednotenoughfreeplaces';
422 1
                $titleKey = 'registrationResult.title.failed';
423 1
                break;
424 3
            case RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED:
425 1
                $messageKey = 'event.message.registrationfailedmaxamountregistrationsexceeded';
426 1
                $titleKey = 'registrationResult.title.failed';
427 1
                break;
428 2
            case RegistrationResult::REGISTRATION_FAILED_EMAIL_NOT_UNIQUE:
429 1
                $messageKey = 'event.message.registrationfailedemailnotunique';
430 1
                $titleKey = 'registrationResult.title.failed';
431 1
                break;
432 1
            default:
433 1
                $messageKey = '';
434 1
                $titleKey = '';
435 1
        }
436
437 9
        $this->view->assign('messageKey', $messageKey);
438 9
        $this->view->assign('titleKey', $titleKey);
439 9
    }
440
441
    /**
442
     * Confirms the registration if possible and sends e-mails to admin and user
443
     *
444
     * @param int $reguid UID of registration
445
     * @param string $hmac HMAC for parameters
446
     *
447
     * @return void
448
     */
449 3
    public function confirmRegistrationAction($reguid, $hmac)
450
    {
451
        /* @var $registration Registration */
452 3
        list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkConfirmRegistration($reguid, $hmac);
453
454 3
        if ($failed === false) {
455 2
            $registration->setConfirmed(true);
456 2
            $this->registrationRepository->update($registration);
457
458 2
            $messageType = MessageType::REGISTRATION_CONFIRMED;
459 2
            if ($registration->getWaitlist()) {
460 1
                $messageType = MessageType::REGISTRATION_WAITLIST_CONFIRMED;
461 1
            }
462
463
            // Send notifications to user and admin
464 2
            $this->notificationService->sendUserMessage(
465 2
                $registration->getEvent(),
466 2
                $registration,
467 2
                $this->settings,
468
                $messageType
469 2
            );
470 2
            $this->notificationService->sendAdminMessage(
471 2
                $registration->getEvent(),
472 2
                $registration,
473 2
                $this->settings,
474
                $messageType
475 2
            );
476
477
            // Confirm registrations depending on main registration if necessary
478 2
            if ($registration->getAmountOfRegistrations() > 1) {
479 2
                $this->registrationService->confirmDependingRegistrations($registration);
480 2
            }
481 2
        }
482
483
        // Redirect to payment provider if payment/redirect is enabled
484 3
        $paymentPid = (int)$this->settings['paymentPid'];
485 3
        if (!$failed && $paymentPid > 0 && $this->registrationService->redirectPaymentEnabled($registration)) {
486
            $this->uriBuilder->reset()
487
                ->setTargetPageUid($paymentPid)
488
                ->setUseCacheHash(false);
489
            $uri =  $this->uriBuilder->uriFor(
490
                'redirect',
491
                [
492
                    'registration' => $registration,
493
                    'hmac' => $this->hashService->generateHmac('redirectAction-' . $registration->getUid())
494
                ],
495
                'Payment',
496
                'sfeventmgt',
497
                'Pipayment'
498
            );
499
            $this->redirectToUri($uri);
500
        }
501
502 3
        $this->view->assign('messageKey', $messageKey);
503 3
        $this->view->assign('titleKey', $titleKey);
504 3
    }
505
506
    /**
507
     * Cancels the registration if possible and sends e-mails to admin and user
508
     *
509
     * @param int $reguid UID of registration
510
     * @param string $hmac HMAC for parameters
511
     *
512
     * @return void
513
     */
514 2
    public function cancelRegistrationAction($reguid, $hmac)
515
    {
516
        /* @var $registration Registration */
517 2
        list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkCancelRegistration($reguid, $hmac);
518
519 2
        if ($failed === false) {
520
            // Send notifications (must run before cancelling the registration)
521 1
            $this->notificationService->sendUserMessage(
522 1
                $registration->getEvent(),
523 1
                $registration,
524 1
                $this->settings,
525
                MessageType::REGISTRATION_CANCELLED
526 1
            );
527 1
            $this->notificationService->sendAdminMessage(
528 1
                $registration->getEvent(),
529 1
                $registration,
530 1
                $this->settings,
531
                MessageType::REGISTRATION_CANCELLED
532 1
            );
533
534
            // First cancel depending registrations
535 1
            if ($registration->getAmountOfRegistrations() > 1) {
536 1
                $this->registrationService->cancelDependingRegistrations($registration);
537 1
            }
538
539
            // Finally cancel registration
540 1
            $this->registrationRepository->remove($registration);
541
542
            // Clear cache for configured pages
543 1
            $this->utilityService->clearCacheForConfiguredUids($this->settings);
544 1
        }
545 2
        $this->view->assign('messageKey', $messageKey);
546 2
        $this->view->assign('titleKey', $titleKey);
547 2
    }
548
549
    /**
550
     * Set date format for field startDate and endDate
551
     *
552
     * @return void
553
     */
554 1
    public function initializeSearchAction()
555
    {
556 1
        if ($this->settings !== null && $this->settings['search']['dateFormat']) {
557 1
            $this->arguments->getArgument('searchDemand')
558 1
                ->getPropertyMappingConfiguration()->forProperty('startDate')
559 1
                ->setTypeConverterOption(
560 1
                    'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
561 1
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
562 1
                    $this->settings['search']['dateFormat']
563 1
                );
564 1
            $this->arguments->getArgument('searchDemand')
565 1
                ->getPropertyMappingConfiguration()->forProperty('endDate')
566 1
                ->setTypeConverterOption(
567 1
                    'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
568 1
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
569 1
                    $this->settings['search']['dateFormat']
570 1
                );
571 1
        }
572 1
    }
573
574
    /**
575
     * Search view
576
     *
577
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand
578
     * @param array $overwriteDemand OverwriteDemand
579
     *
580
     * @return void
581
     */
582 6
    public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = [])
583
    {
584 6
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
585 6
        $eventDemand->setSearchDemand($searchDemand);
586 6
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
587 6
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
588
589 6
        if ($searchDemand !== null) {
590 5
            $searchDemand->setFields($this->settings['search']['fields']);
591
592 5
            if ($this->settings['search']['adjustTime'] && $searchDemand->getStartDate() !== null) {
593 1
                $searchDemand->getStartDate()->setTime(0, 0, 0);
594 1
            }
595
596 5
            if ($this->settings['search']['adjustTime'] && $searchDemand->getEndDate() !== null) {
597 1
                $searchDemand->getEndDate()->setTime(23, 59, 59);
598 1
            }
599 5
        }
600
601 6
        if ($this->isOverwriteDemand($overwriteDemand)) {
602 1
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
603 1
        }
604
605 6
        $categories = $this->categoryRepository->findDemanded($categoryDemand);
606 6
        $locations = $this->locationRepository->findDemanded($foreignRecordDemand);
607
608 6
        $events = $this->eventRepository->findDemanded($eventDemand);
609
610 6
        $this->view->assign('events', $events);
611 6
        $this->view->assign('categories', $categories);
612 6
        $this->view->assign('locations', $locations);
613 6
        $this->view->assign('searchDemand', $searchDemand);
614 6
        $this->view->assign('overwriteDemand', $overwriteDemand);
615 6
    }
616
617
    /**
618
     * Returns if a demand object can be overwritten with the given overwriteDemand array
619
     *
620
     * @param array $overwriteDemand
621
     * @return bool
622
     */
623 9
    protected function isOverwriteDemand($overwriteDemand)
624
    {
625 9
        return $this->settings['disableOverrideDemand'] != 1 && $overwriteDemand !== [];
626
    }
627
628
}
629