Completed
Push — master ( c9d31b...4404d6 )
by Torben
07:34
created

EventController::saveRegistrationAction()   C

Complexity

Conditions 8
Paths 34

Size

Total Lines 86
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 65
CRAP Score 8

Importance

Changes 0
Metric Value
dl 0
loc 86
ccs 65
cts 65
cp 1
rs 5.7638
c 0
b 0
f 0
cc 8
eloc 56
nc 34
nop 2
crap 8

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', 'orderfieldallowed'];
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 2
    public function createEventDemandObjectFromSettings(array $settings)
138
    {
139
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand */
140 2
        $demand = $this->objectManager->get('DERHANSEN\\SfEventMgt\\Domain\\Model\\Dto\\EventDemand');
141 2
        $demand->setDisplayMode($settings['displayMode']);
142 2
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
143 2
        $demand->setCategory($settings['category']);
144 2
        $demand->setIncludeSubcategories($settings['includeSubcategories']);
145 2
        $demand->setTopEventRestriction((int)$settings['topEventRestriction']);
146 2
        $demand->setOrderField($settings['orderField']);
147 2
        $demand->setOrderFieldAllowed($settings['orderFieldAllowed']);
148 2
        $demand->setOrderDirection($settings['orderDirection']);
149 2
        $demand->setQueryLimit($settings['queryLimit']);
150 2
        $demand->setLocation($settings['location']);
151 2
        return $demand;
152
    }
153
154
    /**
155
     * Creates a foreign record demand object with the given settings
156
     *
157
     * @param array $settings The settings
158
     *
159
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand
160
     */
161
    public function createForeignRecordDemandObjectFromSettings(array $settings)
162
    {
163
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\ForeignRecordDemand $demand */
164
        $demand = $this->objectManager->get('DERHANSEN\\SfEventMgt\\Domain\\Model\\Dto\\ForeignRecordDemand');
165
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
166
        $demand->setRestrictForeignRecordsToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']);
167
        return $demand;
168
    }
169
170
    /**
171
     * Creates a category demand object with the given settings
172
     *
173
     * @param array $settings The settings
174
     *
175
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand
176
     */
177 2
    public function createCategoryDemandObjectFromSettings(array $settings)
178
    {
179
        /** @var \DERHANSEN\SfEventMgt\Domain\Model\Dto\CategoryDemand $demand */
180 2
        $demand = $this->objectManager->get('DERHANSEN\\SfEventMgt\\Domain\\Model\\Dto\\CategoryDemand');
181 2
        $demand->setStoragePage(Page::extendPidListByChildren($settings['storagePage'], $settings['recursive']));
182 2
        $demand->setRestrictToStoragePage((bool)$settings['restrictForeignRecordsToStoragePage']);
183 2
        $demand->setCategories($settings['categoryMenu']['categories']);
184 2
        $demand->setIncludeSubcategories($settings['categoryMenu']['includeSubcategories']);
185 2
        return $demand;
186
    }
187
188
    /**
189
     * Overwrites a given demand object by an propertyName =>  $propertyValue array
190
     *
191
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand Demand
192
     * @param array $overwriteDemand OwerwriteDemand
193
     *
194
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand
195
     */
196 4
    protected function overwriteEventDemandObject(EventDemand $demand, array $overwriteDemand)
197
    {
198 4
        foreach ($this->ignoredSettingsForOverwriteDemand as $property) {
199 4
            unset($overwriteDemand[$property]);
200 4
        }
201
202 4
        foreach ($overwriteDemand as $propertyName => $propertyValue) {
203 4
            if (in_array(strtolower($propertyName), $this->ignoredSettingsForOverwriteDemand, true)) {
204 2
                continue;
205
            }
206 4
            \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($demand, $propertyName, $propertyValue);
207 4
        }
208 4
        return $demand;
209
    }
210
211
    /**
212
     * Initialize list action and set format
213
     *
214
     * @return void
215
     */
216
    public function initializeListAction()
217
    {
218
        if (isset($this->settings['list']['format'])) {
219
            $this->request->setFormat($this->settings['list']['format']);
220
        }
221
    }
222
223
    /**
224
     * List view
225
     *
226
     * @param array $overwriteDemand OverwriteDemand
227
     *
228
     * @return void
229
     */
230 6
    public function listAction(array $overwriteDemand = [])
231
    {
232 6
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
233 6
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
234 6
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
235 6
        if ($this->isOverwriteDemand($overwriteDemand)) {
236 2
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
237 2
        }
238 6
        $events = $this->eventRepository->findDemanded($eventDemand);
239 6
        $categories = $this->categoryRepository->findDemanded($categoryDemand);
240 6
        $locations = $this->locationRepository->findDemanded($foreignRecordDemand);
241 6
        $this->view->assign('events', $events);
242 6
        $this->view->assign('categories', $categories);
243 6
        $this->view->assign('locations', $locations);
244 6
        $this->view->assign('overwriteDemand', $overwriteDemand);
245 6
    }
246
247
    /**
248
     * Detail view for an event
249
     *
250
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
251
     *
252
     * @return void
253
     */
254 2
    public function detailAction(Event $event = null)
255
    {
256 2
        $this->view->assign('event', $event);
257 2
    }
258
259
    /**
260
     * Initiates the iCalendar download for the given event
261
     *
262
     * @param Event $event The event
263
     *
264
     * @return bool
265
     */
266 2
    public function icalDownloadAction(Event $event)
267
    {
268 2
        $this->icalendarService->downloadiCalendarFile($event);
269 2
        return false;
270
    }
271
272
    /**
273
     * Registration view for an event
274
     *
275
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
276
     *
277
     * @return void
278
     */
279 2
    public function registrationAction(Event $event)
280
    {
281 2
        if ($event->getRestrictPaymentMethods()) {
282
            $paymentMethods = $this->paymentService->getRestrictedPaymentMethods($event);
283
        } else {
284 2
            $paymentMethods = $this->paymentService->getPaymentMethods();
285
        }
286 2
        $this->view->assign('event', $event);
287 2
        $this->view->assign('paymentMethods', $paymentMethods);
288 2
    }
289
290
    /**
291
     * Set date format for field dateOfBirth
292
     *
293
     * @return void
294
     */
295 2
    public function initializeSaveRegistrationAction()
296
    {
297 2
        $this->arguments->getArgument('registration')
298 2
            ->getPropertyMappingConfiguration()->forProperty('dateOfBirth')
299 2
            ->setTypeConverterOption(
300 2
                'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
301 2
                DateTimeConverter::CONFIGURATION_DATE_FORMAT,
302 2
                $this->settings['registration']['formatDateOfBirth']
303 2
            );
304 2
    }
305
306
    /**
307
     * Saves the registration
308
     *
309
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Registration $registration Registration
310
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
311
     * @validate $registration \DERHANSEN\SfEventMgt\Validation\Validator\RegistrationValidator
312
     *
313
     * @return void
314
     */
315 22
    public function saveRegistrationAction(Registration $registration, Event $event)
316
    {
317 22
        $autoConfirmation = (bool)$this->settings['registration']['autoConfirmation'];
318 22
        $result = RegistrationResult::REGISTRATION_SUCCESSFUL;
319 22
        $success = $this->registrationService->checkRegistrationSuccess($event, $registration, $result);
320
321
        // Save registration if no errors
322 22
        if ($success) {
323 8
            $isWaitlistRegistration = $this->registrationService->isWaitlistRegistration(
324 8
                $event,
325 8
                $registration->getAmountOfRegistrations()
326 8
            );
327 8
            $linkValidity = (int)$this->settings['confirmation']['linkValidity'];
328 8
            if ($linkValidity === 0) {
329
                // Use 3600 seconds as default value if not set
330 8
                $linkValidity = 3600;
331 8
            }
332 8
            $confirmationUntil = new \DateTime();
333 8
            $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S'));
334
335 8
            $registration->setEvent($event);
336 8
            $registration->setPid($event->getPid());
337 8
            $registration->setConfirmationUntil($confirmationUntil);
338 8
            $registration->setLanguage($GLOBALS['TSFE']->config['config']['language']);
339 8
            $registration->setFeUser($this->registrationService->getCurrentFeUserObject());
340 8
            $registration->setWaitlist($isWaitlistRegistration);
341 8
            $registration->_setProperty('_languageUid', $GLOBALS['TSFE']->sys_language_uid);
342 8
            $this->registrationRepository->add($registration);
343
344
            // Persist registration, so we have an UID
345 8
            $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager')->persistAll();
346
347
            // Add new registration (or waitlist registration) to event
348 8
            if ($isWaitlistRegistration) {
349 2
                $event->addRegistrationWaitlist($registration);
350 2
                $messageType = MessageType::REGISTRATION_WAITLIST_NEW;
351 2
            } else {
352 6
                $event->addRegistration($registration);
353 6
                $messageType = MessageType::REGISTRATION_NEW;
354
            }
355 8
            $this->eventRepository->update($event);
356
357
            // Send notifications to user and admin if confirmation link should be sent
358 8
            if (!$autoConfirmation) {
359 6
                $this->notificationService->sendUserMessage(
360 6
                    $event,
361 6
                    $registration,
362 6
                    $this->settings,
363
                    $messageType
364 6
                );
365 6
                $this->notificationService->sendAdminMessage(
366 6
                    $event,
367 6
                    $registration,
368 6
                    $this->settings,
369
                    $messageType
370 6
                );
371 6
            }
372
373
            // Create given amount of registrations if necessary
374 8
            if ($registration->getAmountOfRegistrations() > 1) {
375 2
                $this->registrationService->createDependingRegistrations($registration);
376 2
            }
377
378
            // Clear cache for configured pages
379 8
            $this->utilityService->clearCacheForConfiguredUids($this->settings);
380 8
        }
381
382 22
        if ($autoConfirmation && $success) {
383 2
            $this->redirect(
384 2
                'confirmRegistration',
385 2
                null,
386 2
                null,
387
                [
388 2
                    'reguid' => $registration->getUid(),
389 2
                    'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid())
390 2
                ]
391 2
            );
392 2
        } else {
393 20
            $this->redirect(
394 20
                'saveRegistrationResult',
395 20
                null,
396 20
                null,
397 20
                ['result' => $result]
398 20
            );
399
        }
400 22
    }
401
402
    /**
403
     * Shows the result of the saveRegistrationAction
404
     *
405
     * @param int $result Result
406
     *
407
     * @return void
408
     */
409 18
    public function saveRegistrationResultAction($result)
410
    {
411
        switch ($result) {
412 18
            case RegistrationResult::REGISTRATION_SUCCESSFUL:
413 2
                $messageKey = 'event.message.registrationsuccessful';
414 2
                $titleKey = 'registrationResult.title.successful';
415 2
                break;
416 16
            case RegistrationResult::REGISTRATION_SUCCESSFUL_WAITLIST:
417
                $messageKey = 'event.message.registrationwaitlistsuccessful';
418
                $titleKey = 'registrationWaitlistResult.title.successful';
419
                break;
420 16
            case RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED:
421 2
                $messageKey = 'event.message.registrationfailedeventexpired';
422 2
                $titleKey = 'registrationResult.title.failed';
423 2
                break;
424 14
            case RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS:
425 2
                $messageKey = 'event.message.registrationfailedmaxparticipants';
426 2
                $titleKey = 'registrationResult.title.failed';
427 2
                break;
428 12
            case RegistrationResult::REGISTRATION_NOT_ENABLED:
429 2
                $messageKey = 'event.message.registrationfailednotenabled';
430 2
                $titleKey = 'registrationResult.title.failed';
431 2
                break;
432 10
            case RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED:
433 2
                $messageKey = 'event.message.registrationfaileddeadlineexpired';
434 2
                $titleKey = 'registrationResult.title.failed';
435 2
                break;
436 8
            case RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES:
437 2
                $messageKey = 'event.message.registrationfailednotenoughfreeplaces';
438 2
                $titleKey = 'registrationResult.title.failed';
439 2
                break;
440 6
            case RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED:
441 2
                $messageKey = 'event.message.registrationfailedmaxamountregistrationsexceeded';
442 2
                $titleKey = 'registrationResult.title.failed';
443 2
                break;
444 4
            case RegistrationResult::REGISTRATION_FAILED_EMAIL_NOT_UNIQUE:
445 2
                $messageKey = 'event.message.registrationfailedemailnotunique';
446 2
                $titleKey = 'registrationResult.title.failed';
447 2
                break;
448 2
            default:
449 2
                $messageKey = '';
450 2
                $titleKey = '';
451 2
        }
452
453 18
        $this->view->assign('messageKey', $messageKey);
454 18
        $this->view->assign('titleKey', $titleKey);
455 18
    }
456
457
    /**
458
     * Confirms the registration if possible and sends e-mails to admin and user
459
     *
460
     * @param int $reguid UID of registration
461
     * @param string $hmac HMAC for parameters
462
     *
463
     * @return void
464
     */
465 6
    public function confirmRegistrationAction($reguid, $hmac)
466
    {
467
        /* @var $registration Registration */
468 6
        list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkConfirmRegistration($reguid, $hmac);
469
470 6
        if ($failed === false) {
471 4
            $registration->setConfirmed(true);
472 4
            $this->registrationRepository->update($registration);
473
474 4
            $messageType = MessageType::REGISTRATION_CONFIRMED;
475 4
            if ($registration->getWaitlist()) {
476 2
                $messageType = MessageType::REGISTRATION_WAITLIST_CONFIRMED;
477 2
            }
478
479
            // Send notifications to user and admin
480 4
            $this->notificationService->sendUserMessage(
481 4
                $registration->getEvent(),
482 4
                $registration,
483 4
                $this->settings,
484
                $messageType
485 4
            );
486 4
            $this->notificationService->sendAdminMessage(
487 4
                $registration->getEvent(),
488 4
                $registration,
489 4
                $this->settings,
490
                $messageType
491 4
            );
492
493
            // Confirm registrations depending on main registration if necessary
494 4
            if ($registration->getAmountOfRegistrations() > 1) {
495 4
                $this->registrationService->confirmDependingRegistrations($registration);
496 4
            }
497 4
        }
498
499
        // Redirect to payment provider if payment/redirect is enabled
500 6
        $paymentPid = (int)$this->settings['paymentPid'];
501 6
        if (!$failed && $paymentPid > 0 && $this->registrationService->redirectPaymentEnabled($registration)) {
502
            $this->uriBuilder->reset()
503
                ->setTargetPageUid($paymentPid)
504
                ->setUseCacheHash(false);
505
            $uri =  $this->uriBuilder->uriFor(
506
                'redirect',
507
                [
508
                    'registration' => $registration,
509
                    'hmac' => $this->hashService->generateHmac('redirectAction-' . $registration->getUid())
510
                ],
511
                'Payment',
512
                'sfeventmgt',
513
                'Pipayment'
514
            );
515
            $this->redirectToUri($uri);
516
        }
517
518 6
        $this->view->assign('messageKey', $messageKey);
519 6
        $this->view->assign('titleKey', $titleKey);
520 6
    }
521
522
    /**
523
     * Cancels the registration if possible and sends e-mails to admin and user
524
     *
525
     * @param int $reguid UID of registration
526
     * @param string $hmac HMAC for parameters
527
     *
528
     * @return void
529
     */
530 4
    public function cancelRegistrationAction($reguid, $hmac)
531
    {
532
        /* @var $registration Registration */
533 4
        list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkCancelRegistration($reguid, $hmac);
534
535 4
        if ($failed === false) {
536
            // Send notifications (must run before cancelling the registration)
537 2
            $this->notificationService->sendUserMessage(
538 2
                $registration->getEvent(),
539 2
                $registration,
540 2
                $this->settings,
541
                MessageType::REGISTRATION_CANCELLED
542 2
            );
543 2
            $this->notificationService->sendAdminMessage(
544 2
                $registration->getEvent(),
545 2
                $registration,
546 2
                $this->settings,
547
                MessageType::REGISTRATION_CANCELLED
548 2
            );
549
550
            // First cancel depending registrations
551 2
            if ($registration->getAmountOfRegistrations() > 1) {
552 2
                $this->registrationService->cancelDependingRegistrations($registration);
553 2
            }
554
555
            // Finally cancel registration
556 2
            $this->registrationRepository->remove($registration);
557
558
            // Clear cache for configured pages
559 2
            $this->utilityService->clearCacheForConfiguredUids($this->settings);
560 2
        }
561 4
        $this->view->assign('messageKey', $messageKey);
562 4
        $this->view->assign('titleKey', $titleKey);
563 4
    }
564
565
    /**
566
     * Set date format for field startDate and endDate
567
     *
568
     * @return void
569
     */
570 2
    public function initializeSearchAction()
571
    {
572 2
        if ($this->settings !== null && $this->settings['search']['dateFormat']) {
573 2
            $this->arguments->getArgument('searchDemand')
574 2
                ->getPropertyMappingConfiguration()->forProperty('startDate')
575 2
                ->setTypeConverterOption(
576 2
                    'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
577 2
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
578 2
                    $this->settings['search']['dateFormat']
579 2
                );
580 2
            $this->arguments->getArgument('searchDemand')
581 2
                ->getPropertyMappingConfiguration()->forProperty('endDate')
582 2
                ->setTypeConverterOption(
583 2
                    'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
584 2
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
585 2
                    $this->settings['search']['dateFormat']
586 2
                );
587 2
        }
588 2
    }
589
590
    /**
591
     * Search view
592
     *
593
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand
594
     * @param array $overwriteDemand OverwriteDemand
595
     *
596
     * @return void
597
     */
598 12
    public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = [])
599
    {
600 12
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
601 12
        $eventDemand->setSearchDemand($searchDemand);
602 12
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
603 12
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
604
605 12
        if ($searchDemand !== null) {
606 10
            $searchDemand->setFields($this->settings['search']['fields']);
607
608 10
            if ($this->settings['search']['adjustTime'] && $searchDemand->getStartDate() !== null) {
609 2
                $searchDemand->getStartDate()->setTime(0, 0, 0);
610 2
            }
611
612 10
            if ($this->settings['search']['adjustTime'] && $searchDemand->getEndDate() !== null) {
613 2
                $searchDemand->getEndDate()->setTime(23, 59, 59);
614 2
            }
615 10
        }
616
617 12
        if ($this->isOverwriteDemand($overwriteDemand)) {
618 2
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
619 2
        }
620
621 12
        $categories = $this->categoryRepository->findDemanded($categoryDemand);
622 12
        $locations = $this->locationRepository->findDemanded($foreignRecordDemand);
623
624 12
        $events = $this->eventRepository->findDemanded($eventDemand);
625
626 12
        $this->view->assign('events', $events);
627 12
        $this->view->assign('categories', $categories);
628 12
        $this->view->assign('locations', $locations);
629 12
        $this->view->assign('searchDemand', $searchDemand);
630 12
        $this->view->assign('overwriteDemand', $overwriteDemand);
631 12
    }
632
633
    /**
634
     * Returns if a demand object can be overwritten with the given overwriteDemand array
635
     *
636
     * @param array $overwriteDemand
637
     * @return bool
638
     */
639 18
    protected function isOverwriteDemand($overwriteDemand)
640
    {
641 18
        return $this->settings['disableOverrideDemand'] != 1 && $overwriteDemand !== [];
642
    }
643
644
}
645