Completed
Push — master ( 7f427d...72c6e0 )
by Tim
02:05
created

CalendarController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Index;
11
use HDNET\Calendarize\Register;
12
use HDNET\Calendarize\Utility\DateTimeUtility;
13
use HDNET\Calendarize\Utility\EventUtility;
14
use HDNET\Calendarize\Utility\ExtensionConfigurationUtility;
15
use HDNET\Calendarize\Utility\TranslateUtility;
16
use TYPO3\CMS\Backend\Utility\BackendUtility;
17
use TYPO3\CMS\Core\Utility\ClassNamingUtility;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
19
use TYPO3\CMS\Core\Utility\MathUtility;
20
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
21
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
22
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
23
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
24
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
25
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
26
27
/**
28
 * Calendar.
29
 */
30
class CalendarController extends AbstractController
31
{
32
33
    /**
34
     * @var ObjectManagerInterface
35
     */
36
    protected $objectManager;
37
38
    public function __construct(ObjectManagerInterface $objectManager)
39
    {
40
        $this->objectManager = $objectManager;
41
    }
42
43
    /**
44
     * Init all actions.
45
     */
46
    public function initializeAction()
47
    {
48
        $this->addCacheTags(['calendarize']);
49
50
        parent::initializeAction();
51
        if (isset($this->settings['format'])) {
52
            $this->request->setFormat($this->settings['format']);
53
        }
54
        $this->indexRepository->setIndexTypes(GeneralUtility::trimExplode(',', $this->settings['configuration'], true));
55
        $additionalSlotArguments = [
56
            'contentRecord' => $this->configurationManager->getContentObject()->data,
57
            'settings' => $this->settings,
58
        ];
59
        $this->indexRepository->setAdditionalSlotArguments($additionalSlotArguments);
60
61
        if (isset($this->settings['sorting'])) {
62
            if (isset($this->settings['sortBy'])) {
63
                $this->indexRepository->setDefaultSortingDirection($this->settings['sorting'], $this->settings['sortBy']);
64
            } else {
65
                $this->indexRepository->setDefaultSortingDirection($this->settings['sorting']);
66
            }
67
        }
68
69
        if (isset($this->arguments['startDate'])) {
70
            $this->arguments['startDate']->getPropertyMappingConfiguration()
71
                ->setTypeConverterOption(
72
                    DateTimeConverter::class,
73
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
74
                    $this->settings['dateFormat']
75
                );
76
        }
77
        if (isset($this->arguments['endDate'])) {
78
            $this->arguments['endDate']->getPropertyMappingConfiguration()
79
                ->setTypeConverterOption(
80
                    DateTimeConverter::class,
81
                    DateTimeConverter::CONFIGURATION_DATE_FORMAT,
82
                    $this->settings['dateFormat']
83
                );
84
        }
85
        if ($this->request->hasArgument('event') && 'detailAction' === $this->actionMethodName) {
86
            // default configuration
87
            $configurationName = $this->settings['configuration'];
88
            // configuration overwritten by argument?
89
            if ($this->request->hasArgument('extensionConfiguration')) {
90
                $configurationName = $this->request->getArgument('extensionConfiguration');
91
            }
92
            // get the configuration
93
            $configuration = ExtensionConfigurationUtility::get($configurationName);
94
95
            // get Event by Configuration and Uid
96
            $event = EventUtility::getOriginalRecordByConfiguration($configuration, (int)$this->request->getArgument('event'));
97
            $index = $this->indexRepository->findByEventTraversing($event, true, false, 1)->getFirst();
98
99
            // if there is a valid index in the event
100
            if ($index) {
101
                $this->redirect('detail', null, null, ['index' => $index]);
102
            }
103
        }
104
    }
105
106
    /**
107
     * Latest action.
108
     *
109
     * @param \HDNET\Calendarize\Domain\Model\Index $index
110
     * @param \DateTime $startDate
111
     * @param \DateTime $endDate
112
     * @param array $customSearch *
113
     * @param int $year
114
     * @param int $month
115
     * @param int $week
116
     *
117
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $startDate
118
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $endDate
119
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $customSearch
120
     *
121
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
122
     */
123
    public function latestAction(
124
        Index $index = null,
125
        \DateTime $startDate = null,
126
        \DateTime $endDate = null,
127
        array $customSearch = [],
128
        $year = null,
129
        $month = null,
130
        $week = null
131
    ) {
132
        $this->checkStaticTemplateIsIncluded();
133
        if (($index instanceof Index) && \in_array('detail', $this->getAllowedActions(), true)) {
134
            $this->forward('detail');
135
        }
136
137
        $this->addCacheTags(['calendarize_latest']);
138
139
        $search = $this->determineSearch($startDate, $endDate, $customSearch, $year, $month, null, $week);
140
141
        $this->slotExtendedAssignMultiple([
142
            'indices' => $search['indices'],
143
            'searchMode' => $search['searchMode'],
144
            'searchParameter' => [
145
                'startDate' => $startDate,
146
                'endDate' => $endDate,
147
                'customSearch' => $customSearch,
148
                'year' => $year,
149
                'month' => $month,
150
                'week' => $week,
151
            ],
152
        ], __CLASS__, __FUNCTION__);
153
    }
154
155
    /**
156
     * Result action.
157
     *
158
     * @param \HDNET\Calendarize\Domain\Model\Index $index
159
     * @param \DateTime $startDate
160
     * @param \DateTime $endDate
161
     * @param array $customSearch
162
     * @param int $year
163
     * @param int $month
164
     * @param int $week
165
     *
166
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $startDate
167
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $endDate
168
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $customSearch
169
     *
170
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
171
     */
172
    public function resultAction(
173
        Index $index = null,
174
        \DateTime $startDate = null,
175
        \DateTime $endDate = null,
176
        array $customSearch = [],
177
        $year = null,
178
        $month = null,
179
        $week = null
180
    ) {
181
        $this->checkStaticTemplateIsIncluded();
182
        if (($index instanceof Index) && \in_array('detail', $this->getAllowedActions(), true)) {
183
            $this->forward('detail');
184
        }
185
186
        $this->addCacheTags(['calendarize_result']);
187
188
        $search = $this->determineSearch($startDate, $endDate, $customSearch, $year, $month, null, $week);
189
190
        $this->slotExtendedAssignMultiple([
191
            'indices' => $search['indices'],
192
            'searchMode' => $search['searchMode'],
193
            'searchParameter' => [
194
                'startDate' => $startDate,
195
                'endDate' => $endDate,
196
                'customSearch' => $customSearch,
197
                'year' => $year,
198
                'month' => $month,
199
                'week' => $week,
200
            ],
201
        ], __CLASS__, __FUNCTION__);
202
    }
203
204
    /**
205
     * List action.
206
     *
207
     * @param \HDNET\Calendarize\Domain\Model\Index $index
208
     * @param \DateTime $startDate
209
     * @param \DateTime $endDate
210
     * @param array $customSearch *
211
     * @param int $year
212
     * @param int $month
213
     * @param int $day
214
     * @param int $week
215
     *
216
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $startDate
217
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $endDate
218
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $customSearch
219
     *
220
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
221
     */
222
    public function listAction(
223
        Index $index = null,
224
        \DateTime $startDate = null,
225
        \DateTime $endDate = null,
226
        array $customSearch = [],
227
        $year = null,
228
        $month = null,
229
        $day = null,
230
        $week = null
231
    ) {
232
        $this->checkStaticTemplateIsIncluded();
233
        if (($index instanceof Index) && \in_array('detail', $this->getAllowedActions(), true)) {
234
            $this->forward('detail');
235
        }
236
237
        $this->addCacheTags(['calendarize_list']);
238
239
        $search = $this->determineSearch($startDate, $endDate, $customSearch, $year, $month, $day, $week);
240
241
        $this->slotExtendedAssignMultiple([
242
            'indices' => $search['indices'],
243
            'searchMode' => $search['searchMode'],
244
            'searchParameter' => [
245
                'startDate' => $startDate,
246
                'endDate' => $endDate,
247
                'customSearch' => $customSearch,
248
                'year' => $year,
249
                'month' => $month,
250
                'day' => $day,
251
                'week' => $week,
252
            ],
253
        ], __CLASS__, __FUNCTION__);
254
    }
255
256
    /**
257
     * Shortcut.
258
     */
259
    public function shortcutAction()
260
    {
261
        $this->addCacheTags(['calendarize_shortcut']);
262
        list($table, $uid) = \explode(':', $GLOBALS['TSFE']->currentRecord);
263
        $register = Register::getRegister();
264
265
        $event = null;
266
        foreach ($register as $key => $value) {
267
            if ($value['tableName'] === $table) {
268
                $repositoryName = ClassNamingUtility::translateModelNameToRepositoryName($value['modelName']);
269
                if (\class_exists($repositoryName)) {
270
                    $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...
271
                    $event = $repository->findByUid($uid);
272
                }
273
            }
274
        }
275
276
        if (!($event instanceof DomainObjectInterface)) {
277
            return 'Invalid object';
278
        }
279
280
        $this->addCacheTags(['calendarize_event_' . $event->getUid()]);
281
282
        $fetchEvent = $this->indexRepository->findByEventTraversing($event, true, false, 1);
283
        if (\count($fetchEvent) <= 0) {
284
            $fetchEvent = $this->indexRepository->findByEventTraversing($event, false, true, 1, QueryInterface::ORDER_DESCENDING);
285
        }
286
287
        $this->view->assignMultiple([
288
            'indices' => $fetchEvent,
289
        ]);
290
    }
291
292
    /**
293
     * Past action.
294
     *
295
     * @param int $limit
296
     * @param string $sort
297
     *
298
     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
299
     */
300
    public function pastAction(
301
        $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...
302
        $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...
303
    ) {
304
        $this->addCacheTags(['calendarize_past']);
305
306
        $limit = (int)($this->settings['limit']);
307
        $sort = $this->settings['sorting'];
308
        $this->checkStaticTemplateIsIncluded();
309
        $this->slotExtendedAssignMultiple([
310
            'indices' => $this->indexRepository->findByPast($limit, $sort),
311
        ], __CLASS__, __FUNCTION__);
312
    }
313
314
    /**
315
     * Year action.
316
     *
317
     * @param int $year
318
     */
319
    public function yearAction($year = null)
320
    {
321
        $this->addCacheTags(['calendarize_year']);
322
323
        $date = DateTimeUtility::normalizeDateTime(1, 1, $year);
324
        $now = DateTimeUtility::getNow();
325
        if ($year === null || $now->format('Y') === $date->format('Y')) {
326
            $date = $now;
327
        }
328
329
        $this->slotExtendedAssignMultiple([
330
            'indices' => $this->indexRepository->findYear((int)$date->format('Y')),
331
            'date' => $date,
332
        ], __CLASS__, __FUNCTION__);
333
    }
334
335
    /**
336
     * Quarter action.
337
     *
338
     * @param int $year
339
     * @param int $quarter 1-4
340
     */
341
    public function quarterAction(int $year = null, int $quarter = null)
342
    {
343
        $this->addCacheTags(['calendarize_quarter']);
344
345
        $quarter = DateTimeUtility::normalizeQuarter($quarter);
346
        $date = DateTimeUtility::normalizeDateTime(1, 1 + (($quarter - 1) * 3), $year);
347
348
        $this->slotExtendedAssignMultiple([
349
            'indices' => $this->indexRepository->findQuarter((int)$date->format('Y'), $quarter),
350
            'date' => $date,
351
            'quarter' => $quarter,
352
        ], __CLASS__, __FUNCTION__);
353
    }
354
355
    /**
356
     * Month action.
357
     *
358
     * @param int $year
359
     * @param int $month
360
     * @param int $day
361
     */
362
    public function monthAction($year = null, $month = null, $day = null)
363
    {
364
        $this->addCacheTags(['calendarize_month']);
365
366
        $date = DateTimeUtility::normalizeDateTime($day, $month, $year);
367
        $now = DateTimeUtility::getNow();
368
        $useCurrentDate = $now->format('Y-m') === $date->format('Y-m');
369
        if ($useCurrentDate) {
370
            $date = $now;
371
        }
372
373
        $this->slotExtendedAssignMultiple([
374
            'date' => $date,
375
            'selectDay' => $useCurrentDate,
376
            'ignoreSelectedDay' => !$useCurrentDate,
377
            'indices' => $this->indexRepository->findMonth((int)$date->format('Y'), (int)$date->format('n')),
378
        ], __CLASS__, __FUNCTION__);
379
    }
380
381
    /**
382
     * Week action.
383
     *
384
     * @param int $year
385
     * @param int $week
386
     */
387
    public function weekAction($year = null, $week = null)
388
    {
389
        $this->addCacheTags(['calendarize_week']);
390
391
        $now = DateTimeUtility::getNow();
392
        if (null === $year) {
393
            $year = $now->format('o'); // 'o' instead of 'Y': http://php.net/manual/en/function.date.php#106974
394
        }
395
        if (null === $week) {
396
            $week = $now->format('W');
397
        }
398
        $weekStart = (int)$this->settings['weekStart'];
399
        $firstDay = DateTimeUtility::convertWeekYear2DayMonthYear((int)$week, $year, $weekStart);
400
        $timezone = DateTimeUtility::getTimeZone();
401
        $firstDay->setTimezone($timezone);
402
        $firstDay->setTime(0, 0, 0);
403
404
        $weekConfiguration = [
405
            '+0 day' => 2,
406
            '+1 days' => 2,
407
            '+2 days' => 2,
408
            '+3 days' => 2,
409
            '+4 days' => 2,
410
            '+5 days' => 1,
411
            '+6 days' => 1,
412
        ];
413
414
        $this->slotExtendedAssignMultiple([
415
            'firstDay' => $firstDay,
416
            'indices' => $this->indexRepository->findWeek($year, $week, $this->settings['weekStart']),
417
            'weekConfiguration' => $weekConfiguration,
418
        ], __CLASS__, __FUNCTION__);
419
    }
420
421
    /**
422
     * Day action.
423
     *
424
     * @param int $year
425
     * @param int $month
426
     * @param int $day
427
     */
428
    public function dayAction($year = null, $month = null, $day = null)
429
    {
430
        $this->addCacheTags(['calendarize_day']);
431
432
        $date = DateTimeUtility::normalizeDateTime($day, $month, $year);
433
        $date->modify('+12 hours');
434
435
        $previous = clone $date;
436
        $previous->modify('-1 day');
437
438
        $next = clone $date;
439
        $next->modify('+1 day');
440
441
        $this->slotExtendedAssignMultiple([
442
            'indices' => $this->indexRepository->findDay((int)$date->format('Y'), (int)$date->format('n'), (int)$date->format('j')),
443
            'today' => $date,
444
            'previous' => $previous,
445
            'next' => $next,
446
        ], __CLASS__, __FUNCTION__);
447
    }
448
449
    /**
450
     * Detail action.
451
     *
452
     * @param \HDNET\Calendarize\Domain\Model\Index $index
453
     *
454
     * @return string
455
     */
456
    public function detailAction(Index $index = null)
457
    {
458
        if (null === $index) {
459
            // handle fallback for "strange language settings"
460
            if ($this->request->hasArgument('index')) {
461
                $indexId = (int)$this->request->getArgument('index');
462
                if ($indexId > 0) {
463
                    $index = $this->indexRepository->findByUid($indexId);
464
                }
465
            }
466
467
            if (null === $index) {
468
                if (!MathUtility::canBeInterpretedAsInteger($this->settings['listPid'])) {
469
                    return (string)TranslateUtility::get('noEventDetailView');
470
                }
471
                $this->slottedRedirect(__CLASS__, __FUNCTION__ . 'noEvent');
472
            }
473
        }
474
475
        $this->addCacheTags(['calendarize_detail', 'calendarize_index_' . $index->getUid(), 'calendarize_event_' . $index->getOriginalObject()->getUid()]);
476
477
        $this->slotExtendedAssignMultiple([
478
            'index' => $index,
479
            'domain' => GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY'),
480
        ], __CLASS__, __FUNCTION__);
481
482
        return $this->view->render();
483
    }
484
485
    /**
486
     * Render the search view.
487
     *
488
     * @param \DateTime $startDate
489
     * @param \DateTime $endDate
490
     * @param array $customSearch
491
     *
492
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $startDate
493
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $endDate
494
     * @TYPO3\CMS\Extbase\Annotation\IgnoreValidation $customSearch
495
     */
496
    public function searchAction(\DateTime $startDate = null, \DateTime $endDate = null, array $customSearch = [])
497
    {
498
        $this->addCacheTags(['calendarize_search']);
499
500
        $baseDate = DateTimeUtility::getNow();
501
        if (!($startDate instanceof \DateTimeInterface)) {
502
            $startDate = clone $baseDate;
503
        }
504
        if (!($endDate instanceof \DateTimeInterface)) {
505
            $endDate = clone $startDate;
506
            $modify = \is_string($this->settings['searchEndModifier']) ? $this->settings['searchEndModifier'] : '+30 days';
507
            $endDate->modify($modify);
508
        }
509
510
        $this->slotExtendedAssignMultiple([
511
            'startDate' => $startDate,
512
            'endDate' => $endDate,
513
            'customSearch' => $customSearch,
514
            'configurations' => $this->getCurrentConfigurations(),
515
        ], __CLASS__, __FUNCTION__);
516
    }
517
518
    /**
519
     * Render single items.
520
     */
521
    public function singleAction()
522
    {
523
        $this->addCacheTags(['calendarize_single']);
524
525
        $indicies = [];
526
527
        // prepare selection
528
        $selections = [];
529
        $configurations = $this->getCurrentConfigurations();
530
        foreach (GeneralUtility::trimExplode(',', $this->settings['singleItems']) as $item) {
531
            list($table, $uid) = BackendUtility::splitTable_Uid($item);
532
            foreach ($configurations as $configuration) {
533
                if ($configuration['tableName'] === $table) {
534
                    $selections[] = [
535
                        'configuration' => $configuration,
536
                        'uid' => $uid,
537
                    ];
538
                    break;
539
                }
540
            }
541
        }
542
543
        // fetch index
544
        foreach ($selections as $selection) {
545
            $this->indexRepository->setIndexTypes([$selection['configuration']['uniqueRegisterKey']]);
546
            $dummyIndex = new Index();
547
            $dummyIndex->setForeignTable($selection['configuration']['tableName']);
548
            $dummyIndex->setForeignUid($selection['uid']);
549
550
            $result = $this->indexRepository->findByTraversing($dummyIndex);
551
            $index = $result->getQuery()->setLimit(1)->execute()->getFirst();
552
            if (\is_object($index)) {
553
                $indicies[] = $index;
554
            }
555
        }
556
557
        $this->slotExtendedAssignMultiple([
558
            'indicies' => $indicies,
559
            'configurations' => $configurations,
560
        ], __CLASS__, __FUNCTION__);
561
    }
562
563
    /**
564
     * Build the search structure.
565
     *
566
     * @param \DateTime|null $startDate
567
     * @param \DateTime|null $endDate
568
     * @param array $customSearch
569
     * @param int $year
570
     * @param int $month
571
     * @param int $day
572
     * @param int $week
573
     *
574
     * @return array
575
     */
576
    protected function determineSearch(
577
        \DateTime $startDate = null,
578
        \DateTime $endDate = null,
579
        array $customSearch = [],
580
        $year = null,
581
        $month = null,
582
        $day = null,
583
        $week = null
584
    ) {
585
        $searchMode = false;
586
        if ($startDate || $endDate || !empty($customSearch)) {
587
            $searchMode = true;
588
            $limit = isset($this->settings['limit']) ? (int)$this->settings['limit'] : 0;
589
            $indices = $this->indexRepository->findBySearch($startDate, $endDate, $customSearch, $limit);
590
        } elseif (MathUtility::canBeInterpretedAsInteger($year) && MathUtility::canBeInterpretedAsInteger($month) && MathUtility::canBeInterpretedAsInteger($day)) {
591
            $indices = $this->indexRepository->findDay((int)$year, (int)$month, (int)$day);
592
        } elseif (MathUtility::canBeInterpretedAsInteger($year) && MathUtility::canBeInterpretedAsInteger($month)) {
593
            $indices = $this->indexRepository->findMonth((int)$year, (int)$month);
594
        } elseif (MathUtility::canBeInterpretedAsInteger($year) && MathUtility::canBeInterpretedAsInteger($week)) {
595
            $indices = $this->indexRepository->findWeek($year, $week, $this->settings['weekStart']);
596
        } elseif (MathUtility::canBeInterpretedAsInteger($year)) {
597
            $indices = $this->indexRepository->findYear((int)$year);
598
        } else {
599
            // check if relative dates are enabled
600
            if ((bool)$this->settings['useRelativeDate']) {
601
                $overrideStartDateRelative = \trim($this->settings['overrideStartRelative']);
602
                if ('' === $overrideStartDateRelative) {
603
                    $overrideStartDateRelative = 'now';
604
                }
605
                try {
606
                    $relativeDate = new \DateTime($overrideStartDateRelative);
607
                } catch (\Exception $e) {
608
                    $relativeDate = new \DateTime();
609
                }
610
                $overrideStartDate = $relativeDate->getTimestamp();
611
                $overrideEndDate = 0;
612
                $overrideEndDateRelative = \trim($this->settings['overrideEndRelative']);
613
                if ('' !== $overrideStartDateRelative) {
614
                    try {
615
                        $relativeDate->modify($overrideEndDateRelative);
616
                        $overrideEndDate = $relativeDate->getTimestamp();
617
                    } catch (\Exception $e) {
618
                        // do nothing $overrideEndDate is 0
619
                    }
620
                }
621
            } else {
622
                $overrideStartDate = (int)$this->settings['overrideStartdate'];
623
                $overrideEndDate = (int)$this->settings['overrideEnddate'];
624
            }
625
            $indices = $this->indexRepository->findList(
626
                (int)$this->settings['limit'],
627
                $this->settings['listStartTime'],
628
                (int)$this->settings['listStartTimeOffsetHours'],
629
                $overrideStartDate,
630
                $overrideEndDate
631
            );
632
        }
633
634
        // use this variable in your extension to add more custom variables
635
        $variables = [
636
            'extended' => [
637
                'indices' => $indices,
638
                'searchMode' => $searchMode,
639
                'parameters' => [
640
                    'startDate' => $startDate,
641
                    'endDate' => $endDate,
642
                    'customSearch' => $customSearch,
643
                    'year' => $year,
644
                    'month' => $month,
645
                    'day' => $day,
646
                    'week' => $week,
647
                ],
648
            ],
649
        ];
650
        $variables['settings'] = $this->settings;
651
652
        $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...
653
        $variables = $dispatcher->dispatch(__CLASS__, __FUNCTION__, $variables);
654
655
        return $variables['extended'];
656
    }
657
658
    /**
659
     * Get the allowed actions.
660
     *
661
     * @return array
662
     */
663
    protected function getAllowedActions(): array
664
    {
665
        $configuration = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
666
        $allowedActions = [];
667
        foreach ($configuration['controllerConfiguration'] as $controllerName => $controllerActions) {
668
            $allowedActions[$controllerName] = $controllerActions['actions'];
669
        }
670
671
        return \is_array($allowedActions['Calendar']) ? $allowedActions['Calendar'] : [];
672
    }
673
674
    /**
675
     * Get the current configurations.
676
     *
677
     * @return array
678
     */
679
    protected function getCurrentConfigurations()
680
    {
681
        $configurations = GeneralUtility::trimExplode(',', $this->settings['configuration'], true);
682
        $return = [];
683
        foreach (Register::getRegister() as $key => $configuration) {
684
            if (\in_array($key, $configurations, true)) {
685
                $return[] = $configuration;
686
            }
687
        }
688
689
        return $return;
690
    }
691
692
    /**
693
     * A redirect that have a slot included.
694
     *
695
     * @param string $signalClassName name of the signal class: __CLASS__
696
     * @param string $signalName name of the signal: __FUNCTION__
697
     * @param array $variables optional: if not set use the defaults
698
     */
699
    protected function slottedRedirect($signalClassName, $signalName, $variables = null)
700
    {
701
        // set default variables for the redirect
702
        if (null === $variables) {
703
            $variables['extended'] = [
704
                'actionName' => 'list',
705
                'controllerName' => null,
706
                'extensionName' => null,
707
                'arguments' => [],
708
                'pageUid' => $this->settings['listPid'],
709
                'delay' => 0,
710
                'statusCode' => 301,
711
            ];
712
            $variables['extended']['pluginHmac'] = $this->calculatePluginHmac();
713
            $variables['settings'] = $this->settings;
714
        }
715
716
        $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...
717
        $variables = $dispatcher->dispatch($signalClassName, $signalName, $variables);
718
719
        $this->redirect(
720
            $variables['extended']['actionName'],
721
            $variables['extended']['controllerName'],
722
            $variables['extended']['extensionName'],
723
            $variables['extended']['arguments'],
724
            $variables['extended']['pageUid'],
725
            $variables['extended']['delay'],
726
            $variables['extended']['statusCode']
727
        );
728
    }
729
}
730