Passed
Push — typo3_11 ( 9f005f...de2730 )
by Torben
03:11
created

AbstractController   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 293
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 45
dl 0
loc 293
rs 10
c 1
b 0
f 0
wmc 23

16 Methods

Rating   Name   Duplication   Size   Complexity  
A injectFieldRepository() 0 4 1
A getPagination() 0 14 4
A injectEventRepository() 0 3 1
A injectOrganisatorRepository() 0 4 1
A getTypoScriptFrontendController() 0 3 2
A overwriteEventDemandObject() 0 14 4
A injectSpeakerRepository() 0 4 1
A injectLocationRepository() 0 4 1
A injectCalendarService() 0 3 1
A injectPaymentService() 0 3 1
A injectNotificationService() 0 3 1
A injectHashService() 0 3 1
A injectIcalendarService() 0 3 1
A injectRegistrationService() 0 3 1
A injectRegistrationRepository() 0 4 1
A injectCategoryRepository() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
5
 *
6
 * For the full copyright and license information, please read the
7
 * LICENSE.txt file that was distributed with this source code.
8
 */
9
10
namespace DERHANSEN\SfEventMgt\Controller;
11
12
use DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand;
13
use DERHANSEN\SfEventMgt\Pagination\NumberedPagination;
14
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
15
use TYPO3\CMS\Extbase\Pagination\QueryResultPaginator;
16
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
17
18
/**
19
 * EventController
20
 */
21
abstract class AbstractController extends ActionController
22
{
23
    /**
24
     * Properties in this array will be ignored by overwriteDemandObject()
25
     *
26
     * @var array
27
     */
28
    protected $ignoredSettingsForOverwriteDemand = ['storagepage', 'orderfieldallowed'];
29
30
    /**
31
     * EventRepository
32
     *
33
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\EventRepository
34
     */
35
    protected $eventRepository;
36
37
    /**
38
     * Registration repository
39
     *
40
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository
41
     */
42
    protected $registrationRepository;
43
44
    /**
45
     * Category repository
46
     *
47
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\CategoryRepository
48
     */
49
    protected $categoryRepository;
50
51
    /**
52
     * Location repository
53
     *
54
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\LocationRepository
55
     */
56
    protected $locationRepository;
57
58
    /**
59
     * Organisator repository
60
     *
61
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\OrganisatorRepository
62
     */
63
    protected $organisatorRepository;
64
65
    /**
66
     * Speaker repository
67
     *
68
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\SpeakerRepository
69
     */
70
    protected $speakerRepository;
71
72
    /**
73
     * Notification Service
74
     *
75
     * @var \DERHANSEN\SfEventMgt\Service\NotificationService
76
     */
77
    protected $notificationService;
78
79
    /**
80
     * ICalendar Service
81
     *
82
     * @var \DERHANSEN\SfEventMgt\Service\ICalendarService
83
     */
84
    protected $icalendarService;
85
86
    /**
87
     * Hash Service
88
     *
89
     * @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService
90
     */
91
    protected $hashService;
92
93
    /**
94
     * RegistrationService
95
     *
96
     * @var \DERHANSEN\SfEventMgt\Service\RegistrationService
97
     */
98
    protected $registrationService;
99
100
    /**
101
     * CalendarService
102
     *
103
     * @var \DERHANSEN\SfEventMgt\Service\CalendarService
104
     */
105
    protected $calendarService;
106
107
    /**
108
     * PaymentMethodService
109
     *
110
     * @var \DERHANSEN\SfEventMgt\Service\PaymentService
111
     */
112
    protected $paymentService;
113
114
    /**
115
     * FieldRepository
116
     *
117
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\Registration\FieldRepository
118
     */
119
    protected $fieldRepository;
120
121
    /**
122
     * DI for $calendarService
123
     *
124
     * @param \DERHANSEN\SfEventMgt\Service\CalendarService $calendarService
125
     */
126
    public function injectCalendarService(\DERHANSEN\SfEventMgt\Service\CalendarService $calendarService)
127
    {
128
        $this->calendarService = $calendarService;
129
    }
130
131
    /**
132
     * DI for $categoryRepository
133
     *
134
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\CategoryRepository $categoryRepository
135
     */
136
    public function injectCategoryRepository(
137
        \DERHANSEN\SfEventMgt\Domain\Repository\CategoryRepository $categoryRepository
138
    ) {
139
        $this->categoryRepository = $categoryRepository;
140
    }
141
142
    /**
143
     * DI for $eventRepository
144
     *
145
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\EventRepository $eventRepository
146
     */
147
    public function injectEventRepository(\DERHANSEN\SfEventMgt\Domain\Repository\EventRepository $eventRepository)
148
    {
149
        $this->eventRepository = $eventRepository;
150
    }
151
152
    /**
153
     * DI for $hashService
154
     *
155
     * @param \TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService
156
     */
157
    public function injectHashService(\TYPO3\CMS\Extbase\Security\Cryptography\HashService $hashService)
158
    {
159
        $this->hashService = $hashService;
160
    }
161
162
    /**
163
     * DI for $icalendarService
164
     *
165
     * @param \DERHANSEN\SfEventMgt\Service\ICalendarService $icalendarService
166
     */
167
    public function injectIcalendarService(\DERHANSEN\SfEventMgt\Service\ICalendarService $icalendarService)
168
    {
169
        $this->icalendarService = $icalendarService;
170
    }
171
172
    /**
173
     * DI for $locationRepository
174
     *
175
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\LocationRepository $locationRepository
176
     */
177
    public function injectLocationRepository(
178
        \DERHANSEN\SfEventMgt\Domain\Repository\LocationRepository $locationRepository
179
    ) {
180
        $this->locationRepository = $locationRepository;
181
    }
182
183
    /**
184
     * DI for $notificationService
185
     *
186
     * @param \DERHANSEN\SfEventMgt\Service\NotificationService $notificationService
187
     */
188
    public function injectNotificationService(\DERHANSEN\SfEventMgt\Service\NotificationService $notificationService)
189
    {
190
        $this->notificationService = $notificationService;
191
    }
192
193
    /**
194
     * DI for $organisatorRepository
195
     *
196
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\OrganisatorRepository $organisatorRepository
197
     */
198
    public function injectOrganisatorRepository(
199
        \DERHANSEN\SfEventMgt\Domain\Repository\OrganisatorRepository $organisatorRepository
200
    ) {
201
        $this->organisatorRepository = $organisatorRepository;
202
    }
203
204
    /**
205
     * DI for $speakerRepository
206
     *
207
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\SpeakerRepository $speakerRepository
208
     */
209
    public function injectSpeakerRepository(
210
        \DERHANSEN\SfEventMgt\Domain\Repository\SpeakerRepository $speakerRepository
211
    ) {
212
        $this->speakerRepository = $speakerRepository;
213
    }
214
215
    /**
216
     * DI for $paymentService
217
     *
218
     * @param \DERHANSEN\SfEventMgt\Service\PaymentService $paymentService
219
     */
220
    public function injectPaymentService(\DERHANSEN\SfEventMgt\Service\PaymentService $paymentService)
221
    {
222
        $this->paymentService = $paymentService;
223
    }
224
225
    /**
226
     * DI for $registrationRepository
227
     *
228
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository $registrationRepository
229
     */
230
    public function injectRegistrationRepository(
231
        \DERHANSEN\SfEventMgt\Domain\Repository\RegistrationRepository $registrationRepository
232
    ) {
233
        $this->registrationRepository = $registrationRepository;
234
    }
235
236
    /**
237
     * DI for $registrationService
238
     *
239
     * @param \DERHANSEN\SfEventMgt\Service\RegistrationService $registrationService
240
     */
241
    public function injectRegistrationService(\DERHANSEN\SfEventMgt\Service\RegistrationService $registrationService)
242
    {
243
        $this->registrationService = $registrationService;
244
    }
245
246
    /**
247
     * DI for $fieldRepository
248
     *
249
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\Registration\FieldRepository $fieldRepository
250
     */
251
    public function injectFieldRepository(
252
        \DERHANSEN\SfEventMgt\Domain\Repository\Registration\FieldRepository $fieldRepository
253
    ) {
254
        $this->fieldRepository = $fieldRepository;
255
    }
256
257
    /**
258
     * Returns an array with variables for the pagination. An array with pagination settings should be passed.
259
     * Applies default values if settings are not available:
260
     * - pagination disabled
261
     * - itemsPerPage = 10
262
     * - maxNumPages = 10
263
     *
264
     * @param QueryResultInterface $events
265
     * @param array $settings
266
     * @return array
267
     */
268
    protected function getPagination(QueryResultInterface $events, array $settings): array
269
    {
270
        $pagination = [];
271
        $currentPage = $this->request->hasArgument('currentPage') ? (int)$this->request->getArgument('currentPage') : 1;
272
        if (($settings['enablePagination'] ?? false) && (int)$settings['itemsPerPage'] > 0) {
273
            $paginator = new QueryResultPaginator($events, $currentPage, (int)($settings['itemsPerPage'] ?? 10));
274
            $pagination = new NumberedPagination($paginator, (int)($settings['maxNumPages'] ?? 10));
275
            $pagination = [
276
                'paginator' => $paginator,
277
                'pagination' => $pagination,
278
            ];
279
        }
280
281
        return $pagination;
282
    }
283
284
    /**
285
     * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
286
     */
287
    protected function getTypoScriptFrontendController()
288
    {
289
        return $GLOBALS['TSFE'] ?: null;
290
    }
291
292
    /**
293
     * Overwrites a given demand object by an propertyName =>  $propertyValue array
294
     *
295
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand $demand Demand
296
     * @param array $overwriteDemand OwerwriteDemand
297
     *
298
     * @return \DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand
299
     */
300
    protected function overwriteEventDemandObject(EventDemand $demand, array $overwriteDemand)
301
    {
302
        foreach ($this->ignoredSettingsForOverwriteDemand as $property) {
303
            unset($overwriteDemand[$property]);
304
        }
305
306
        foreach ($overwriteDemand as $propertyName => $propertyValue) {
307
            if (in_array(strtolower($propertyName), $this->ignoredSettingsForOverwriteDemand, true)) {
308
                continue;
309
            }
310
            \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($demand, $propertyName, $propertyValue);
311
        }
312
313
        return $demand;
314
    }
315
}
316