Passed
Push — typo3-v13 ( a3e5b1...74dcf7 )
by Torben
02:43
created

AbstractController::getFrontendPageInformation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\Controller;
13
14
use DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand;
15
use DERHANSEN\SfEventMgt\Domain\Repository\CategoryRepository;
16
use DERHANSEN\SfEventMgt\Domain\Repository\EventRepository;
17
use DERHANSEN\SfEventMgt\Domain\Repository\LocationRepository;
18
use DERHANSEN\SfEventMgt\Domain\Repository\OrganisatorRepository;
19
use DERHANSEN\SfEventMgt\Domain\Repository\Registration\FieldRepository;
20
use DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository;
21
use DERHANSEN\SfEventMgt\Domain\Repository\SpeakerRepository;
22
use DERHANSEN\SfEventMgt\Service\CalendarService;
23
use DERHANSEN\SfEventMgt\Service\ICalendarService;
24
use DERHANSEN\SfEventMgt\Service\NotificationService;
25
use DERHANSEN\SfEventMgt\Service\PaymentService;
26
use DERHANSEN\SfEventMgt\Service\RegistrationService;
27
use TYPO3\CMS\Core\Pagination\SlidingWindowPagination;
28
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Mvc\Controller\ActionController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use TYPO3\CMS\Extbase\Mvc\Controller\Arguments;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Mvc\Controller\Arguments was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Pagination\QueryResultPaginator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Persistence\QueryResultInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Extbase\Reflection\ObjectAccess was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
use TYPO3\CMS\Frontend\Page\PageInformation;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Frontend\Page\PageInformation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
35
abstract class AbstractController extends ActionController
36
{
37
    protected array $ignoredSettingsForOverwriteDemand = ['storagepage', 'orderfieldallowed'];
38
39
    protected EventRepository $eventRepository;
40
    protected RegistrationRepository $registrationRepository;
41
    protected CategoryRepository $categoryRepository;
42
    protected LocationRepository $locationRepository;
43
    protected OrganisatorRepository $organisatorRepository;
44
    protected SpeakerRepository $speakerRepository;
45
    protected NotificationService $notificationService;
46
    protected ICalendarService $icalendarService;
47
    protected RegistrationService $registrationService;
48
    protected CalendarService $calendarService;
49
    protected PaymentService $paymentService;
50
    protected FieldRepository $fieldRepository;
51
52
    public function injectCalendarService(CalendarService $calendarService): void
53
    {
54
        $this->calendarService = $calendarService;
55
    }
56
57
    public function injectCategoryRepository(CategoryRepository $categoryRepository): void
58
    {
59
        $this->categoryRepository = $categoryRepository;
60
    }
61
62
    public function injectEventRepository(EventRepository $eventRepository): void
63
    {
64
        $this->eventRepository = $eventRepository;
65
    }
66
67
    public function injectIcalendarService(ICalendarService $icalendarService): void
68
    {
69
        $this->icalendarService = $icalendarService;
70
    }
71
72
    public function injectLocationRepository(LocationRepository $locationRepository): void
73
    {
74
        $this->locationRepository = $locationRepository;
75
    }
76
77
    public function injectNotificationService(NotificationService $notificationService): void
78
    {
79
        $this->notificationService = $notificationService;
80
    }
81
82
    public function injectOrganisatorRepository(OrganisatorRepository $organisatorRepository): void
83
    {
84
        $this->organisatorRepository = $organisatorRepository;
85
    }
86
87
    public function injectSpeakerRepository(SpeakerRepository $speakerRepository): void
88
    {
89
        $this->speakerRepository = $speakerRepository;
90
    }
91
92
    public function injectPaymentService(PaymentService $paymentService): void
93
    {
94
        $this->paymentService = $paymentService;
95
    }
96
97
    public function injectRegistrationRepository(RegistrationRepository $registrationRepository): void
98
    {
99
        $this->registrationRepository = $registrationRepository;
100
    }
101
102
    public function injectRegistrationService(RegistrationService $registrationService): void
103
    {
104
        $this->registrationService = $registrationService;
105
    }
106
107
    public function injectFieldRepository(FieldRepository $fieldRepository): void
108
    {
109
        $this->fieldRepository = $fieldRepository;
110
    }
111
112
    /**
113
     * Public getter for extbase arguments. Can be used by extending extensions in e.g. event listeners to
114
     * retrieve the current controller arguments.
115
     */
116
    public function getControllerArguments(): Arguments
117
    {
118
        return $this->arguments;
119
    }
120
121
    /**
122
     * Public getter to retrieve extension settings. Can be used by extending extensions in e.g. event listeners to
123
     * retrieve the extension settings.
124
     */
125
    public function getSettings(): array
126
    {
127
        return $this->settings;
128
    }
129
130
    /**
131
     * Returns an array with variables for the pagination. An array with pagination settings should be passed.
132
     * Applies default values if settings are not available:
133
     * - pagination disabled
134
     * - itemsPerPage = 10
135
     * - maxNumPages = 10
136
     */
137
    protected function getPagination(QueryResultInterface $events, array $settings): array
138
    {
139
        $paginationData = [];
140
        $currentPage = $this->request->hasArgument('currentPage') ? (int)$this->request->getArgument('currentPage') : 1;
141
        if (($settings['enablePagination'] ?? false) && (int)$settings['itemsPerPage'] > 0) {
142
            $paginator = new QueryResultPaginator($events, $currentPage, (int)($settings['itemsPerPage'] ?? 10));
143
            $pagination = new SlidingWindowPagination($paginator, (int)($settings['maxNumPages'] ?? 10));
144
            $paginationData = [
145
                'paginator' => $paginator,
146
                'pagination' => $pagination,
147
            ];
148
        }
149
150
        return $paginationData;
151
    }
152
153
    /**
154
     * Overwrites a given demand object by an propertyName =>  $propertyValue array
155
     */
156
    protected function overwriteEventDemandObject(EventDemand $demand, array $overwriteDemand): EventDemand
157
    {
158
        foreach ($this->ignoredSettingsForOverwriteDemand as $property) {
159
            unset($overwriteDemand[$property]);
160
        }
161
162
        foreach ($overwriteDemand as $propertyName => $propertyValue) {
163
            if (in_array(strtolower($propertyName), $this->ignoredSettingsForOverwriteDemand, true)) {
164
                continue;
165
            }
166
            ObjectAccess::setProperty($demand, $propertyName, $propertyValue);
167
        }
168
169
        return $demand;
170
    }
171
172
    protected function getFrontendPageInformation(): PageInformation
173
    {
174
        return $this->request->getAttribute('frontend.page.information');
175
    }
176
}
177