Completed
Push — master ( 617684...c9d31b )
by Torben
161:05 queued 159:19
created

EventController   C

Complexity

Total Complexity 55

Size/Duplication

Total Lines 608
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 15

Test Coverage

Coverage 90.44%

Importance

Changes 0
Metric Value
wmc 55
lcom 3
cbo 15
dl 0
loc 608
ccs 265
cts 293
cp 0.9044
rs 5.904
c 0
b 0
f 0

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