Completed
Push — master ( 50fde4...1991d6 )
by Torben
61:08 queued 58:12
created

EventController   B

Complexity

Total Complexity 50

Size/Duplication

Total Lines 576
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 15

Test Coverage

Coverage 92.59%

Importance

Changes 26
Bugs 2 Features 13
Metric Value
wmc 50
c 26
b 2
f 13
lcom 3
cbo 15
dl 0
loc 576
ccs 250
cts 270
cp 0.9259
rs 7.2559

16 Methods

Rating   Name   Duplication   Size   Complexity  
A createEventDemandObjectFromSettings() 0 15 1
A createForeignRecordDemandObjectFromSettings() 0 8 1
A createCategoryDemandObjectFromSettings() 0 10 1
A overwriteEventDemandObject() 0 11 3
A listAction() 0 16 2
A detailAction() 0 4 1
A icalDownloadAction() 0 5 1
A registrationAction() 0 10 2
A initializeSaveRegistrationAction() 0 10 1
C saveRegistrationAction() 0 75 7
D saveRegistrationResultAction() 0 43 9
B confirmRegistrationAction() 0 51 6
B cancelRegistrationAction() 0 34 3
A initializeSearchAction() 0 19 3
C searchAction() 0 34 7
A isOverwriteDemand() 0 4 2

How to fix   Complexity   

Complex Class

Complex classes like EventController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use EventController, and based on these observations, apply Extract Interface, too.

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 10
    public function saveRegistrationAction(Registration $registration, Event $event)
300
    {
301 10
        $autoConfirmation = (bool)$this->settings['registration']['autoConfirmation'];
302 10
        $result = RegistrationResult::REGISTRATION_SUCCESSFUL;
303 10
        $success = $this->registrationService->checkRegistrationSuccess($event, $registration, $result);
304
305
        // Save registration if no errors
306 10
        if ($success) {
307 3
            $linkValidity = (int)$this->settings['confirmation']['linkValidity'];
308 3
            if ($linkValidity === 0) {
309
                // Use 3600 seconds as default value if not set
310 3
                $linkValidity = 3600;
311 3
            }
312 3
            $confirmationUntil = new \DateTime();
313 3
            $confirmationUntil->add(new \DateInterval('PT' . $linkValidity . 'S'));
314
315 3
            $registration->setEvent($event);
316 3
            $registration->setPid($event->getPid());
317 3
            $registration->setConfirmationUntil($confirmationUntil);
318 3
            $registration->setLanguage($GLOBALS['TSFE']->config['config']['language']);
319 3
            $registration->setFeUser($this->registrationService->getCurrentFeUserObject());
320 3
            $registration->_setProperty('_languageUid', $GLOBALS['TSFE']->sys_language_uid);
321 3
            $this->registrationRepository->add($registration);
322
323
            // Persist registration, so we have an UID
324 3
            $this->objectManager->get('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager')->persistAll();
325
326
            // Add new registration to event
327 3
            $event->addRegistration($registration);
328 3
            $this->eventRepository->update($event);
329
330
            // Send notifications to user and admin if confirmation link should be sent
331 3
            if (!$autoConfirmation) {
332 2
                $this->notificationService->sendUserMessage(
333 2
                    $event,
334 2
                    $registration,
335 2
                    $this->settings,
336
                    MessageType::REGISTRATION_NEW
337 2
                );
338 2
                $this->notificationService->sendAdminMessage(
339 2
                    $event,
340 2
                    $registration,
341 2
                    $this->settings,
342
                    MessageType::REGISTRATION_NEW
343 2
                );
344 2
            }
345
346
            // Create given amount of registrations if necessary
347 3
            if ($registration->getAmountOfRegistrations() > 1) {
348 1
                $this->registrationService->createDependingRegistrations($registration);
349 1
            }
350
351
            // Clear cache for configured pages
352 3
            $this->utilityService->clearCacheForConfiguredUids($this->settings);
353 3
        }
354
355 10
        if ($autoConfirmation && $success) {
356 1
            $this->redirect(
357 1
                'confirmRegistration',
358 1
                null,
359 1
                null,
360
                [
361 1
                    'reguid' => $registration->getUid(),
362 1
                    'hmac' => $this->hashService->generateHmac('reg-' . $registration->getUid())
363 1
                ]
364 1
            );
365 1
        } else {
366 9
            $this->redirect(
367 9
                'saveRegistrationResult',
368 9
                null,
369 9
                null,
370 9
                ['result' => $result]
371 9
            );
372
        }
373 10
    }
374
375
    /**
376
     * Shows the result of the saveRegistrationAction
377
     *
378
     * @param int $result Result
379
     *
380
     * @return void
381
     */
382 9
    public function saveRegistrationResultAction($result)
383
    {
384
        switch ($result) {
385 9
            case RegistrationResult::REGISTRATION_SUCCESSFUL:
386 1
                $messageKey = 'event.message.registrationsuccessful';
387 1
                $titleKey = 'registrationResult.title.successful';
388 1
                break;
389 8
            case RegistrationResult::REGISTRATION_FAILED_EVENT_EXPIRED:
390 1
                $messageKey = 'event.message.registrationfailedeventexpired';
391 1
                $titleKey = 'registrationResult.title.failed';
392 1
                break;
393 7
            case RegistrationResult::REGISTRATION_FAILED_MAX_PARTICIPANTS:
394 1
                $messageKey = 'event.message.registrationfailedmaxparticipants';
395 1
                $titleKey = 'registrationResult.title.failed';
396 1
                break;
397 6
            case RegistrationResult::REGISTRATION_NOT_ENABLED:
398 1
                $messageKey = 'event.message.registrationfailednotenabled';
399 1
                $titleKey = 'registrationResult.title.failed';
400 1
                break;
401 5
            case RegistrationResult::REGISTRATION_FAILED_DEADLINE_EXPIRED:
402 1
                $messageKey = 'event.message.registrationfaileddeadlineexpired';
403 1
                $titleKey = 'registrationResult.title.failed';
404 1
                break;
405 4
            case RegistrationResult::REGISTRATION_FAILED_NOT_ENOUGH_FREE_PLACES:
406 1
                $messageKey = 'event.message.registrationfailednotenoughfreeplaces';
407 1
                $titleKey = 'registrationResult.title.failed';
408 1
                break;
409 3
            case RegistrationResult::REGISTRATION_FAILED_MAX_AMOUNT_REGISTRATIONS_EXCEEDED:
410 1
                $messageKey = 'event.message.registrationfailedmaxamountregistrationsexceeded';
411 1
                $titleKey = 'registrationResult.title.failed';
412 1
                break;
413 2
            case RegistrationResult::REGISTRATION_FAILED_EMAIL_NOT_UNIQUE:
414 1
                $messageKey = 'event.message.registrationfailedemailnotunique';
415 1
                $titleKey = 'registrationResult.title.failed';
416 1
                break;
417 1
            default:
418 1
                $messageKey = '';
419 1
                $titleKey = '';
420 1
        }
421
422 9
        $this->view->assign('messageKey', $messageKey);
423 9
        $this->view->assign('titleKey', $titleKey);
424 9
    }
425
426
    /**
427
     * Confirms the registration if possible and sends e-mails to admin and user
428
     *
429
     * @param int $reguid UID of registration
430
     * @param string $hmac HMAC for parameters
431
     *
432
     * @return void
433
     */
434 2
    public function confirmRegistrationAction($reguid, $hmac)
435
    {
436
        /* @var $registration Registration */
437 2
        list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkConfirmRegistration($reguid, $hmac);
438
439 2
        if ($failed === false) {
440 1
            $registration->setConfirmed(true);
441 1
            $this->registrationRepository->update($registration);
442
443
            // Send notifications to user and admin
444 1
            $this->notificationService->sendUserMessage(
445 1
                $registration->getEvent(),
446 1
                $registration,
447 1
                $this->settings,
448
                MessageType::REGISTRATION_CONFIRMED
449 1
            );
450 1
            $this->notificationService->sendAdminMessage(
451 1
                $registration->getEvent(),
452 1
                $registration,
453 1
                $this->settings,
454
                MessageType::REGISTRATION_CONFIRMED
455 1
            );
456
457
            // Confirm registrations depending on main registration if necessary
458 1
            if ($registration->getAmountOfRegistrations() > 1) {
459 1
                $this->registrationService->confirmDependingRegistrations($registration);
460 1
            }
461 1
        }
462
463
        // Redirect to payment provider if payment/redirect is enabled
464 2
        $paymentPid = (int)$this->settings['paymentPid'];
465 2
        if (!$failed && $paymentPid > 0 && $this->registrationService->redirectPaymentEnabled($registration)) {
466
            $this->uriBuilder->reset()
467
                ->setTargetPageUid($paymentPid)
468
                ->setUseCacheHash(false);
469
            $uri =  $this->uriBuilder->uriFor(
470
                'redirect',
471
                [
472
                    'registration' => $registration,
473
                    'hmac' => $this->hashService->generateHmac('redirectAction-' . $registration->getUid())
474
                ],
475
                'Payment',
476
                'sfeventmgt',
477
                'Pipayment'
478
            );
479
            $this->redirectToUri($uri);
480
        }
481
482 2
        $this->view->assign('messageKey', $messageKey);
483 2
        $this->view->assign('titleKey', $titleKey);
484 2
    }
485
486
    /**
487
     * Cancels the registration if possible and sends e-mails to admin and user
488
     *
489
     * @param int $reguid UID of registration
490
     * @param string $hmac HMAC for parameters
491
     *
492
     * @return void
493
     */
494 2
    public function cancelRegistrationAction($reguid, $hmac)
495
    {
496
        /* @var $registration Registration */
497 2
        list($failed, $registration, $messageKey, $titleKey) = $this->registrationService->checkCancelRegistration($reguid, $hmac);
498
499 2
        if ($failed === false) {
500
            // Send notifications (must run before cancelling the registration)
501 1
            $this->notificationService->sendUserMessage(
502 1
                $registration->getEvent(),
503 1
                $registration,
504 1
                $this->settings,
505
                MessageType::REGISTRATION_CANCELLED
506 1
            );
507 1
            $this->notificationService->sendAdminMessage(
508 1
                $registration->getEvent(),
509 1
                $registration,
510 1
                $this->settings,
511
                MessageType::REGISTRATION_CANCELLED
512 1
            );
513
514
            // First cancel depending registrations
515 1
            if ($registration->getAmountOfRegistrations() > 1) {
516 1
                $this->registrationService->cancelDependingRegistrations($registration);
517 1
            }
518
519
            // Finally cancel registration
520 1
            $this->registrationRepository->remove($registration);
521
522
            // Clear cache for configured pages
523 1
            $this->utilityService->clearCacheForConfiguredUids($this->settings);
524 1
        }
525 2
        $this->view->assign('messageKey', $messageKey);
526 2
        $this->view->assign('titleKey', $titleKey);
527 2
    }
528
529
    /**
530
     * Set date format for field startDate and endDate
531
     *
532
     * @return void
533
     */
534 1
    public function initializeSearchAction()
535
    {
536 1
        if ($this->settings !== null && $this->settings['search']['dateFormat']) {
537 1
            $this->arguments->getArgument('searchDemand')
538 1
                ->getPropertyMappingConfiguration()->forProperty('startDate')
539 1
                ->setTypeConverterOption(
540 1
                    'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
541 1
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
542 1
                    $this->settings['search']['dateFormat']
543 1
                );
544 1
            $this->arguments->getArgument('searchDemand')
545 1
                ->getPropertyMappingConfiguration()->forProperty('endDate')
546 1
                ->setTypeConverterOption(
547 1
                    'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
548 1
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
549 1
                    $this->settings['search']['dateFormat']
550 1
                );
551 1
        }
552 1
    }
553
554
    /**
555
     * Search view
556
     *
557
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand
558
     * @param array $overwriteDemand OverwriteDemand
559
     *
560
     * @return void
561
     */
562 6
    public function searchAction(SearchDemand $searchDemand = null, array $overwriteDemand = [])
563
    {
564 6
        $eventDemand = $this->createEventDemandObjectFromSettings($this->settings);
565 6
        $eventDemand->setSearchDemand($searchDemand);
566 6
        $foreignRecordDemand = $this->createForeignRecordDemandObjectFromSettings($this->settings);
567 6
        $categoryDemand = $this->createCategoryDemandObjectFromSettings($this->settings);
568
569 6
        if ($searchDemand !== null) {
570 5
            $searchDemand->setFields($this->settings['search']['fields']);
571
572 5
            if ($this->settings['search']['adjustTime'] && $searchDemand->getStartDate() !== null) {
573 1
                $searchDemand->getStartDate()->setTime(0, 0, 0);
574 1
            }
575
576 5
            if ($this->settings['search']['adjustTime'] && $searchDemand->getEndDate() !== null) {
577 1
                $searchDemand->getEndDate()->setTime(23, 59, 59);
578 1
            }
579 5
        }
580
581 6
        if ($this->isOverwriteDemand($overwriteDemand)) {
582 1
            $eventDemand = $this->overwriteEventDemandObject($eventDemand, $overwriteDemand);
583 1
        }
584
585 6
        $categories = $this->categoryRepository->findDemanded($categoryDemand);
586 6
        $locations = $this->locationRepository->findDemanded($foreignRecordDemand);
587
588 6
        $events = $this->eventRepository->findDemanded($eventDemand);
589
590 6
        $this->view->assign('events', $events);
591 6
        $this->view->assign('categories', $categories);
592 6
        $this->view->assign('locations', $locations);
593 6
        $this->view->assign('searchDemand', $searchDemand);
594 6
        $this->view->assign('overwriteDemand', $overwriteDemand);
595 6
    }
596
597
    /**
598
     * Returns if a demand object can be overwritten with the given overwriteDemand array
599
     *
600
     * @param array $overwriteDemand
601
     * @return bool
602
     */
603 9
    protected function isOverwriteDemand($overwriteDemand)
604
    {
605 9
        return $this->settings['disableOverrideDemand'] != 1 && $overwriteDemand !== [];
606
    }
607
608
}
609