Completed
Push — master ( 43de24...e5ed3f )
by Tim
02:56
created

CalendarController::determineSearch()   D

Complexity

Conditions 18
Paths 23

Size

Total Lines 82

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 82
rs 4.8666
c 0
b 0
f 0
cc 18
nc 23
nop 7

How to fix   Long Method    Complexity   

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
3
/**
4
 * Calendar.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Controller;
9
10
use HDNET\Calendarize\Domain\Model\Event;
11
use HDNET\Calendarize\Domain\Model\Index;
12
use HDNET\Calendarize\Register;
13
use HDNET\Calendarize\Utility\DateTimeUtility;
14
use HDNET\Calendarize\Utility\EventUtility;
15
use HDNET\Calendarize\Utility\ExtensionConfigurationUtility;
16
use HDNET\Calendarize\Utility\TranslateUtility;
17
use TYPO3\CMS\Backend\Utility\BackendUtility;
18
use TYPO3\CMS\Core\MetaTag\MetaTagManagerRegistry;
19
use TYPO3\CMS\Core\Utility\ClassNamingUtility;
20
use TYPO3\CMS\Core\Utility\GeneralUtility;
21
use TYPO3\CMS\Core\Utility\MathUtility;
22
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
23
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
24
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
25
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
26
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
27
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
28
29
/**
30
 * Calendar.
31
 */
32
class CalendarController extends AbstractController
33
{
34
    /**
35
     * @var ObjectManagerInterface
36
     */
37
    protected $objectManager;
38
39
    public function __construct(ObjectManagerInterface $objectManager)
40
    {
41
        $this->objectManager = $objectManager;
42
    }
43
44
    /**
45
     * Init all actions.
46
     */
47
    public function initializeAction()
48
    {
49
        $this->addCacheTags(['calendarize']);
50
51
        parent::initializeAction();
52
        if (isset($this->settings['format'])) {
53
            $this->request->setFormat($this->settings['format']);
54
        }
55
        $this->indexRepository->setIndexTypes(GeneralUtility::trimExplode(',', $this->settings['configuration'], true));
56
        $additionalSlotArguments = [
57
            'contentRecord' => $this->configurationManager->getContentObject()->data,
58
            'settings' => $this->settings,
59
        ];
60
        $this->indexRepository->setAdditionalSlotArguments($additionalSlotArguments);
61
62
        if (isset($this->settings['sorting'])) {
63
            if (isset($this->settings['sortBy'])) {
64
                $this->indexRepository->setDefaultSortingDirection($this->settings['sorting'], $this->settings['sortBy']);
65
            } else {
66
                $this->indexRepository->setDefaultSortingDirection($this->settings['sorting']);
67
            }
68
        }
69
70
        if (isset($this->arguments['startDate'])) {
71
            $this->arguments['startDate']->getPropertyMappingConfiguration()
72
                ->setTypeConverterOption(
73
                    DateTimeConverter::class,
74
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
75
                    'Y-m-d'
76
                );
77
        }
78
        if (isset($this->arguments['endDate'])) {
79
            $this->arguments['endDate']->getPropertyMappingConfiguration()
80
                ->setTypeConverterOption(
81
                    DateTimeConverter::class,
82
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
83
                    'Y-m-d'
84
                );
85
        }
86
        if ($this->request->hasArgument('event') && 'detailAction' === $this->actionMethodName) {
87
            // default configuration
88
            $configurationName = $this->settings['configuration'];
89
            // configuration overwritten by argument?
90
            if ($this->request->hasArgument('extensionConfiguration')) {
91
                $configurationName = $this->request->getArgument('extensionConfiguration');
92
            }
93
            // get the configuration
94
            $configuration = ExtensionConfigurationUtility::get($configurationName);
95
96
            // get Event by Configuration and Uid
97
            $event = EventUtility::getOriginalRecordByConfiguration($configuration, (int)$this->request->getArgument('event'));
98
            $index = $this->indexRepository->findByEventTraversing($event, true, false, 1)->getFirst();
99
100
            // if there is a valid index in the event
101
            if ($index) {
102
                $this->redirect('detail', null, null, ['index' => $index]);
103
            }
104
        }
105
    }
106
107
    /**
108
     * Latest action.
109
     *
110
     * @param \HDNET\Calendarize\Domain\Model\Index $index
111
     * @param \DateTime                             $startDate
112
     * @param \DateTime                             $endDate
113
     * @param array                                 $customSearch *
114
     * @param int                                   $year
115
     * @param int                                   $month
116
     * @param int                                   $week
117
     *
118
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $startDate
119
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $endDate
120
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $customSearch
121
     *
122
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
123
     */
124
    public function latestAction(
125
        Index $index = null,
126
        \DateTime $startDate = null,
127
        \DateTime $endDate = null,
128
        array $customSearch = [],
129
        $year = null,
130
        $month = null,
131
        $week = null
132
    ) {
133
        $this->checkStaticTemplateIsIncluded();
134
        if (($index instanceof Index) && \in_array('detail', $this->getAllowedActions(), true)) {
135
            $this->forward('detail');
136
        }
137
138
        $this->addCacheTags(['calendarize_latest']);
139
140
        $search = $this->determineSearch($startDate, $endDate, $customSearch, $year, $month, null, $week);
141
142
        $this->slotExtendedAssignMultiple([
143
            'indices' => $search['indices'],
144
            'searchMode' => $search['searchMode'],
145
            'searchParameter' => [
146
                'startDate' => $startDate,
147
                'endDate' => $endDate,
148
                'customSearch' => $customSearch,
149
                'year' => $year,
150
                'month' => $month,
151
                'week' => $week,
152
            ],
153
        ], __CLASS__, __FUNCTION__);
154
    }
155
156
    /**
157
     * Result action.
158
     *
159
     * @param \HDNET\Calendarize\Domain\Model\Index $index
160
     * @param \DateTime                             $startDate
161
     * @param \DateTime                             $endDate
162
     * @param array                                 $customSearch
163
     * @param int                                   $year
164
     * @param int                                   $month
165
     * @param int                                   $week
166
     *
167
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $startDate
168
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $endDate
169
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $customSearch
170
     *
171
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
172
     */
173
    public function resultAction(
174
        Index $index = null,
175
        \DateTime $startDate = null,
176
        \DateTime $endDate = null,
177
        array $customSearch = [],
178
        $year = null,
179
        $month = null,
180
        $week = null
181
    ) {
182
        $this->checkStaticTemplateIsIncluded();
183
        if (($index instanceof Index) && \in_array('detail', $this->getAllowedActions(), true)) {
184
            $this->forward('detail');
185
        }
186
187
        $this->addCacheTags(['calendarize_result']);
188
189
        $search = $this->determineSearch($startDate, $endDate, $customSearch, $year, $month, null, $week);
190
191
        $this->slotExtendedAssignMultiple([
192
            'indices' => $search['indices'],
193
            'searchMode' => $search['searchMode'],
194
            'searchParameter' => [
195
                'startDate' => $startDate,
196
                'endDate' => $endDate,
197
                'customSearch' => $customSearch,
198
                'year' => $year,
199
                'month' => $month,
200
                'week' => $week,
201
            ],
202
        ], __CLASS__, __FUNCTION__);
203
    }
204
205
    /**
206
     * List action.
207
     *
208
     * @param \HDNET\Calendarize\Domain\Model\Index $index
209
     * @param \DateTime                             $startDate
210
     * @param \DateTime                             $endDate
211
     * @param array                                 $customSearch *
212
     * @param int                                   $year
213
     * @param int                                   $month
214
     * @param int                                   $day
215
     * @param int                                   $week
216
     *
217
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $startDate
218
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $endDate
219
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $customSearch
220
     *
221
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
222
     */
223
    public function listAction(
224
        Index $index = null,
225
        \DateTime $startDate = null,
226
        \DateTime $endDate = null,
227
        array $customSearch = [],
228
        $year = null,
229
        $month = null,
230
        $day = null,
231
        $week = null
232
    ) {
233
        $this->checkStaticTemplateIsIncluded();
234
        if (($index instanceof Index) && \in_array('detail', $this->getAllowedActions(), true)) {
235
            $this->forward('detail');
236
        }
237
238
        $this->addCacheTags(['calendarize_list']);
239
240
        $search = $this->determineSearch($startDate, $endDate, $customSearch, $year, $month, $day, $week);
241
242
        $this->slotExtendedAssignMultiple([
243
            'indices' => $search['indices'],
244
            'searchMode' => $search['searchMode'],
245
            'searchParameter' => [
246
                'startDate' => $startDate,
247
                'endDate' => $endDate,
248
                'customSearch' => $customSearch,
249
                'year' => $year,
250
                'month' => $month,
251
                'day' => $day,
252
                'week' => $week,
253
            ],
254
        ], __CLASS__, __FUNCTION__);
255
    }
256
257
    /**
258
     * Shortcut.
259
     */
260
    public function shortcutAction()
261
    {
262
        $this->addCacheTags(['calendarize_shortcut']);
263
        list($table, $uid) = explode(':', $GLOBALS['TSFE']->currentRecord);
264
        $register = Register::getRegister();
265
266
        $event = null;
267
        foreach ($register as $key => $value) {
268
            if ($value['tableName'] === $table) {
269
                $repositoryName = ClassNamingUtility::translateModelNameToRepositoryName($value['modelName']);
270
                if (class_exists($repositoryName)) {
271
                    $repository = $this->objectManager->get($repositoryName);
0 ignored issues
show
Deprecated Code introduced by
The method TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated with message: since TYPO3 10.4, will be removed in version 12.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
272
                    $event = $repository->findByUid($uid);
273
274
                    $this->addCacheTags(['calendarize_' . lcfirst($value['uniqueRegisterKey']) . '_' . $event->getUid()]);
275
                    break;
276
                }
277
            }
278
        }
279
280
        if (!($event instanceof DomainObjectInterface)) {
281
            return 'Invalid object';
282
        }
283
284
        $fetchEvent = $this->indexRepository->findByEventTraversing($event, true, false, 1);
285
        if (\count($fetchEvent) <= 0) {
286
            $fetchEvent = $this->indexRepository->findByEventTraversing($event, false, true, 1, QueryInterface::ORDER_DESCENDING);
287
        }
288
289
        $this->view->assignMultiple([
290
            'indices' => $fetchEvent,
291
        ]);
292
    }
293
294
    /**
295
     * Past action.
296
     *
297
     * @param int    $limit
298
     * @param string $sort
299
     *
300
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
301
     */
302
    public function pastAction(
303
        $limit = 100,
0 ignored issues
show
Unused Code introduced by
The parameter $limit is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
304
        $sort = 'ASC'
0 ignored issues
show
Unused Code introduced by
The parameter $sort is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
305
    ) {
306
        $this->addCacheTags(['calendarize_past']);
307
308
        $limit = (int)($this->settings['limit']);
309
        $sort = $this->settings['sorting'];
310
        $this->checkStaticTemplateIsIncluded();
311
        $this->slotExtendedAssignMultiple([
312
            'indices' => $this->indexRepository->findByPast($limit, $sort),
313
        ], __CLASS__, __FUNCTION__);
314
    }
315
316
    /**
317
     * Year action.
318
     *
319
     * @param int $year
320
     */
321
    public function yearAction($year = null)
322
    {
323
        $this->addCacheTags(['calendarize_year']);
324
325
        // use the thrid day, to avoid time shift problems in the timezone
326
        $date = DateTimeUtility::normalizeDateTime(3, 1, $year);
327
        $now = DateTimeUtility::getNow();
328
        if (null === $year || $now->format('Y') === $date->format('Y')) {
329
            $date = $now;
330
        }
331
332
        if ($this->isDateOutOfTypoScriptConfiguration($date)) {
333
            return $this->return404Page();
334
        }
335
336
        $this->slotExtendedAssignMultiple([
337
            'indices' => $this->indexRepository->findYear((int)$date->format('Y')),
338
            'date' => $date,
339
        ], __CLASS__, __FUNCTION__);
340
    }
341
342
    /**
343
     * Quarter action.
344
     *
345
     * @param int $year
346
     * @param int $quarter 1-4
347
     */
348
    public function quarterAction(int $year = null, int $quarter = null)
349
    {
350
        $this->addCacheTags(['calendarize_quarter']);
351
352
        $quarter = DateTimeUtility::normalizeQuarter($quarter);
353
        $date = DateTimeUtility::normalizeDateTime(1, 1 + (($quarter - 1) * 3), $year);
354
355
        if ($this->isDateOutOfTypoScriptConfiguration($date)) {
356
            return $this->return404Page();
357
        }
358
359
        $this->slotExtendedAssignMultiple([
360
            'indices' => $this->indexRepository->findQuarter((int)$date->format('Y'), $quarter),
361
            'date' => $date,
362
            'quarter' => $quarter,
363
        ], __CLASS__, __FUNCTION__);
364
    }
365
366
    /**
367
     * Month action.
368
     *
369
     * @param int $year
370
     * @param int $month
371
     * @param int $day
372
     */
373
    public function monthAction($year = null, $month = null, $day = null)
374
    {
375
        $this->addCacheTags(['calendarize_month']);
376
377
        $date = DateTimeUtility::normalizeDateTime($day, $month, $year);
378
        $now = DateTimeUtility::getNow();
379
        $useCurrentDate = $now->format('Y-m') === $date->format('Y-m');
380
        if ($useCurrentDate) {
381
            $date = $now;
382
        }
383
384
        if ($this->isDateOutOfTypoScriptConfiguration($date)) {
385
            return $this->return404Page();
386
        }
387
388
        $this->slotExtendedAssignMultiple([
389
            'date' => $date,
390
            'selectDay' => $useCurrentDate,
391
            'ignoreSelectedDay' => !$useCurrentDate,
392
            'indices' => $this->indexRepository->findMonth((int)$date->format('Y'), (int)$date->format('n')),
393
        ], __CLASS__, __FUNCTION__);
394
    }
395
396
    /**
397
     * Week action.
398
     *
399
     * @param int|null $year
400
     * @param int|null $week
401
     */
402
    public function weekAction(?int $year = null, ?int $week = null)
403
    {
404
        $this->addCacheTags(['calendarize_week']);
405
406
        $now = DateTimeUtility::getNow();
407
        if (null === $year) {
408
            $year = (int)$now->format('o'); // 'o' instead of 'Y': http://php.net/manual/en/function.date.php#106974
409
        }
410
        if (null === $week) {
411
            $week = (int)$now->format('W');
412
        }
413
        $weekStart = (int)$this->settings['weekStart'];
414
        $firstDay = DateTimeUtility::convertWeekYear2DayMonthYear($week, $year, $weekStart);
415
416
        if ($this->isDateOutOfTypoScriptConfiguration($firstDay)) {
417
            return $this->return404Page();
418
        }
419
420
        $weekConfiguration = [
421
            '+0 day' => 2,
422
            '+1 days' => 2,
423
            '+2 days' => 2,
424
            '+3 days' => 2,
425
            '+4 days' => 2,
426
            '+5 days' => 1,
427
            '+6 days' => 1,
428
        ];
429
430
        $this->slotExtendedAssignMultiple([
431
            'firstDay' => $firstDay,
432
            'indices' => $this->indexRepository->findWeek($year, $week, $weekStart),
433
            'weekConfiguration' => $weekConfiguration,
434
        ], __CLASS__, __FUNCTION__);
435
    }
436
437
    /**
438
     * Day action.
439
     *
440
     * @param int $year
441
     * @param int $month
442
     * @param int $day
443
     */
444
    public function dayAction($year = null, $month = null, $day = null)
445
    {
446
        $this->addCacheTags(['calendarize_day']);
447
448
        $date = DateTimeUtility::normalizeDateTime($day, $month, $year);
449
        $date->modify('+12 hours');
450
451
        if ($this->isDateOutOfTypoScriptConfiguration($date)) {
452
            return $this->return404Page();
453
        }
454
455
        $previous = clone $date;
456
        $previous->modify('-1 day');
457
458
        $next = clone $date;
459
        $next->modify('+1 day');
460
461
        $this->slotExtendedAssignMultiple([
462
            'indices' => $this->indexRepository->findDay((int)$date->format('Y'), (int)$date->format('n'), (int)$date->format('j')),
463
            'today' => $date,
464
            'previous' => $previous,
465
            'next' => $next,
466
        ], __CLASS__, __FUNCTION__);
467
    }
468
469
    /**
470
     * Detail action.
471
     *
472
     * @param \HDNET\Calendarize\Domain\Model\Index $index
473
     *
474
     * @return string
475
     */
476
    public function detailAction(Index $index = null)
477
    {
478
        if (null === $index) {
479
            // handle fallback for "strange language settings"
480
            if ($this->request->hasArgument('index')) {
481
                $indexId = (int)$this->request->getArgument('index');
482
                if ($indexId > 0) {
483
                    $index = $this->indexRepository->findByUid($indexId);
484
                }
485
            }
486
487
            if (null === $index) {
488
                if (!MathUtility::canBeInterpretedAsInteger($this->settings['listPid'])) {
489
                    return (string)TranslateUtility::get('noEventDetailView');
490
                }
491
                $this->slottedRedirect(__CLASS__, __FUNCTION__ . 'noEvent');
492
            }
493
        }
494
495
        $this->addCacheTags(['calendarize_detail', 'calendarize_index_' . $index->getUid(), 'calendarize_' . lcfirst($index->getConfiguration()['uniqueRegisterKey']) . '_' . $index->getOriginalObject()->getUid()]);
496
497
        // Meta tags
498
        if ($index->getOriginalObject() instanceof Event) {
499
            // @todo move to event
500
            /** @var Event $event */
501
            $event = $index->getOriginalObject();
502
            GeneralUtility::makeInstance(MetaTagManagerRegistry::class)->getManagerForProperty('og:title')->addProperty('og:title', $event->getTitle());
503
        }
504
505
        $this->slotExtendedAssignMultiple([
506
            'index' => $index,
507
            'domain' => GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'),
508
        ], __CLASS__, __FUNCTION__);
509
510
        return $this->view->render();
511
    }
512
513
    /**
514
     * Render the search view.
515
     *
516
     * @param \DateTime $startDate
517
     * @param \DateTime $endDate
518
     * @param array     $customSearch
519
     *
520
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $startDate
521
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $endDate
522
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $customSearch
523
     */
524
    public function searchAction(\DateTime $startDate = null, \DateTime $endDate = null, array $customSearch = [])
525
    {
526
        $this->addCacheTags(['calendarize_search']);
527
528
        $baseDate = DateTimeUtility::getNow();
529
        if (!($startDate instanceof \DateTimeInterface)) {
530
            $startDate = clone $baseDate;
531
        }
532
        if (!($endDate instanceof \DateTimeInterface)) {
533
            $endDate = clone $startDate;
534
            $modify = \is_string($this->settings['searchEndModifier']) ? $this->settings['searchEndModifier'] : '+30 days';
535
            $endDate->modify($modify);
536
        }
537
        $this->checkWrongDateOrder($startDate, $endDate);
538
539
        $this->slotExtendedAssignMultiple([
540
            'startDate' => $startDate,
541
            'endDate' => $endDate,
542
            'customSearch' => $customSearch,
543
            'configurations' => $this->getCurrentConfigurations(),
544
        ], __CLASS__, __FUNCTION__);
545
    }
546
547
    /**
548
     * Render single items.
549
     */
550
    public function singleAction()
551
    {
552
        $this->addCacheTags(['calendarize_single']);
553
554
        $indicies = [];
555
556
        // prepare selection
557
        $selections = [];
558
        $configurations = $this->getCurrentConfigurations();
559
        foreach (GeneralUtility::trimExplode(',', $this->settings['singleItems']) as $item) {
560
            list($table, $uid) = BackendUtility::splitTable_Uid($item);
561
            foreach ($configurations as $configuration) {
562
                if ($configuration['tableName'] === $table) {
563
                    $selections[] = [
564
                        'configuration' => $configuration,
565
                        'uid' => $uid,
566
                    ];
567
                    break;
568
                }
569
            }
570
        }
571
572
        // fetch index
573
        foreach ($selections as $selection) {
574
            $this->indexRepository->setIndexTypes([$selection['configuration']['uniqueRegisterKey']]);
575
            $dummyIndex = new Index();
576
            $dummyIndex->setForeignTable($selection['configuration']['tableName']);
577
            $dummyIndex->setForeignUid($selection['uid']);
578
579
            $result = $this->indexRepository->findByTraversing($dummyIndex);
580
            $index = $result->getQuery()->setLimit(1)->execute()->getFirst();
581
            if (\is_object($index)) {
582
                $indicies[] = $index;
583
            }
584
        }
585
586
        $this->slotExtendedAssignMultiple([
587
            'indicies' => $indicies,
588
            'configurations' => $configurations,
589
        ], __CLASS__, __FUNCTION__);
590
    }
591
592
    /**
593
     * Build the search structure.
594
     *
595
     * @param \DateTime|null $startDate
596
     * @param \DateTime|null $endDate
597
     * @param array          $customSearch
598
     * @param int            $year
599
     * @param int            $month
600
     * @param int            $day
601
     * @param int            $week
602
     *
603
     * @return array
604
     */
605
    protected function determineSearch(
606
        \DateTime $startDate = null,
607
        \DateTime $endDate = null,
608
        array $customSearch = [],
609
        $year = null,
610
        $month = null,
611
        $day = null,
612
        $week = null
613
    ) {
614
        $searchMode = false;
615
        $this->checkWrongDateOrder($startDate, $endDate);
616
        if ($startDate || $endDate || !empty($customSearch)) {
617
            $searchMode = true;
618
            $limit = isset($this->settings['limit']) ? (int)$this->settings['limit'] : 0;
619
            $indices = $this->indexRepository->findBySearch($startDate, $endDate, $customSearch, $limit);
620
        } elseif (MathUtility::canBeInterpretedAsInteger($year) && MathUtility::canBeInterpretedAsInteger($month) && MathUtility::canBeInterpretedAsInteger($day)) {
621
            $indices = $this->indexRepository->findDay((int)$year, (int)$month, (int)$day);
622
        } elseif (MathUtility::canBeInterpretedAsInteger($year) && MathUtility::canBeInterpretedAsInteger($month)) {
623
            $indices = $this->indexRepository->findMonth((int)$year, (int)$month);
624
        } elseif (MathUtility::canBeInterpretedAsInteger($year) && MathUtility::canBeInterpretedAsInteger($week)) {
625
            $indices = $this->indexRepository->findWeek((int)$year, (int)$week, (int)$this->settings['weekStart']);
626
        } elseif (MathUtility::canBeInterpretedAsInteger($year)) {
627
            $indices = $this->indexRepository->findYear((int)$year);
628
        } else {
629
            // check if relative dates are enabled
630
            if ((bool)$this->settings['useRelativeDate']) {
631
                $overrideStartDateRelative = trim($this->settings['overrideStartRelative']);
632
                if ('' === $overrideStartDateRelative) {
633
                    $overrideStartDateRelative = 'now';
634
                }
635
                try {
636
                    $relativeDate = new \DateTime($overrideStartDateRelative);
637
                } catch (\Exception $e) {
638
                    $relativeDate = DateTimeUtility::getNow();
639
                }
640
                $overrideStartDate = $relativeDate->getTimestamp();
641
                $overrideEndDate = 0;
642
                $overrideEndDateRelative = trim($this->settings['overrideEndRelative']);
643
                if ('' !== $overrideStartDateRelative) {
644
                    try {
645
                        $relativeDate->modify($overrideEndDateRelative);
646
                        $overrideEndDate = $relativeDate->getTimestamp();
647
                    } catch (\Exception $e) {
648
                        // do nothing $overrideEndDate is 0
649
                    }
650
                }
651
            } else {
652
                $overrideStartDate = (int)$this->settings['overrideStartdate'];
653
                $overrideEndDate = (int)$this->settings['overrideEnddate'];
654
            }
655
            $indices = $this->indexRepository->findList(
656
                (int)$this->settings['limit'],
657
                $this->settings['listStartTime'],
658
                (int)$this->settings['listStartTimeOffsetHours'],
659
                $overrideStartDate,
660
                $overrideEndDate
661
            );
662
        }
663
664
        // use this variable in your extension to add more custom variables
665
        $variables = [
666
            'extended' => [
667
                'indices' => $indices,
668
                'searchMode' => $searchMode,
669
                'parameters' => [
670
                    'startDate' => $startDate,
671
                    'endDate' => $endDate,
672
                    'customSearch' => $customSearch,
673
                    'year' => $year,
674
                    'month' => $month,
675
                    'day' => $day,
676
                    'week' => $week,
677
                ],
678
            ],
679
        ];
680
        $variables['settings'] = $this->settings;
681
682
        $dispatcher = $this->objectManager->get(Dispatcher::class);
0 ignored issues
show
Deprecated Code introduced by
The method TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated with message: since TYPO3 10.4, will be removed in version 12.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
683
        $variables = $dispatcher->dispatch(__CLASS__, __FUNCTION__, $variables);
684
685
        return $variables['extended'];
686
    }
687
688
    protected function checkWrongDateOrder(\DateTime &$startDate = null, \DateTime &$endDate = null)
689
    {
690
        if ($startDate && $endDate && $endDate < $startDate) {
691
            // End date is before start date. So use start and end equals!
692
            $endDate = clone $startDate;
693
        }
694
    }
695
696
    /**
697
     * Get the allowed actions.
698
     *
699
     * @return array
700
     */
701
    protected function getAllowedActions(): array
702
    {
703
        $configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
704
        $allowedActions = [];
705
        foreach ($configuration['controllerConfiguration'] as $controllerName => $controllerActions) {
706
            $allowedActions[$controllerName] = $controllerActions['actions'];
707
        }
708
709
        return \is_array($allowedActions[__CLASS__]) ? $allowedActions[__CLASS__] : [];
710
    }
711
712
    /**
713
     * Get the current configurations.
714
     *
715
     * @return array
716
     */
717
    protected function getCurrentConfigurations()
718
    {
719
        $configurations = GeneralUtility::trimExplode(',', $this->settings['configuration'], true);
720
        $return = [];
721
        foreach (Register::getRegister() as $key => $configuration) {
722
            if (\in_array($key, $configurations, true)) {
723
                $return[] = $configuration;
724
            }
725
        }
726
727
        return $return;
728
    }
729
730
    /**
731
     * A redirect that have a slot included.
732
     *
733
     * @param string $signalClassName name of the signal class: __CLASS__
734
     * @param string $signalName      name of the signal: __FUNCTION__
735
     * @param array  $variables       optional: if not set use the defaults
736
     */
737
    protected function slottedRedirect($signalClassName, $signalName, $variables = null)
738
    {
739
        // set default variables for the redirect
740
        if (null === $variables) {
741
            $variables['extended'] = [
742
                'actionName' => 'list',
743
                'controllerName' => null,
744
                'extensionName' => null,
745
                'arguments' => [],
746
                'pageUid' => $this->settings['listPid'],
747
                'delay' => 0,
748
                'statusCode' => 301,
749
            ];
750
            $variables['extended']['pluginHmac'] = $this->calculatePluginHmac();
751
            $variables['settings'] = $this->settings;
752
        }
753
754
        $dispatcher = $this->objectManager->get(Dispatcher::class);
0 ignored issues
show
Deprecated Code introduced by
The method TYPO3\CMS\Extbase\Object...ManagerInterface::get() has been deprecated with message: since TYPO3 10.4, will be removed in version 12.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
755
        $variables = $dispatcher->dispatch($signalClassName, $signalName, $variables);
756
757
        $this->redirect(
758
            $variables['extended']['actionName'],
759
            $variables['extended']['controllerName'],
760
            $variables['extended']['extensionName'],
761
            $variables['extended']['arguments'],
762
            $variables['extended']['pageUid'],
763
            $variables['extended']['delay'],
764
            $variables['extended']['statusCode']
765
        );
766
    }
767
}
768