Completed
Push — development ( deb2fc...28a639 )
by Torben
04:28 queued 25s
created

injectCustomNotificationLogRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 0
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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 TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
18
use DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand;
19
use DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand;
20
use DERHANSEN\SfEventMgt\Domain\Model\Event;
21
use DERHANSEN\SfEventMgt\Service;
22
23
/**
24
 * AdministrationController
25
 *
26
 * @author Torben Hansen <[email protected]>
27
 */
28
class AdministrationController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
29
{
30
31
    /**
32
     * EventRepository
33
     *
34
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\EventRepository
35
     * */
36
    protected $eventRepository = null;
37
38
    /**
39
     * CustomNotificationLogRepository
40
     *
41
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository
42
     */
43
    protected $customNotificationLogRepository = null;
44
45
    /**
46
     * ExportService
47
     *
48
     * @var \DERHANSEN\SfEventMgt\Service\ExportService
49
     */
50
    protected $exportService = null;
51
52
    /**
53
     * RegistrationService
54
     *
55
     * @var \DERHANSEN\SfEventMgt\Service\RegistrationService
56
     */
57
    protected $registrationService = null;
58
59
    /**
60
     * NotificationService
61
     *
62
     * @var \DERHANSEN\SfEventMgt\Service\NotificationService
63
     */
64
    protected $notificationService = null;
65
66
    /**
67
     * SettingsService
68
     *
69
     * @var \DERHANSEN\SfEventMgt\Service\SettingsService
70
     */
71
    protected $settingsService = null;
72
73
    /**
74
     * The current page uid
75
     *
76
     * @var int
77
     */
78
    protected $pid = 0;
79
80
    /**
81
     * DI for $customNotificationLogRepository
82
     *
83
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository
84
     */
85
    public function injectCustomNotificationLogRepository(
86
        \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository
87
    ) {
88
        $this->customNotificationLogRepository = $customNotificationLogRepository;
89
    }
90
91 1
    /**
92
     * DI for $eventRepository
93 1
     *
94 1
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\EventRepository $eventRepository
95
     */
96
    public function injectEventRepository(\DERHANSEN\SfEventMgt\Domain\Repository\EventRepository $eventRepository)
97
    {
98
        $this->eventRepository = $eventRepository;
99
    }
100
101 2
    /**
102
     * DI for $exportService
103 2
     *
104 1
     * @param Service\ExportService $exportService
105 1
     */
106 2
    public function injectExportService(\DERHANSEN\SfEventMgt\Service\ExportService $exportService)
107 2
    {
108 2
        $this->exportService = $exportService;
109 2
    }
110 2
111 2
    /**
112 2
     * DI for $notificationService
113 2
     *
114 2
     * @param Service\NotificationService $notificationService
115 2
     */
116 2
    public function injectNotificationService(\DERHANSEN\SfEventMgt\Service\NotificationService $notificationService)
117 2
    {
118 2
        $this->notificationService = $notificationService;
119 2
    }
120 2
121
    /**
122
     * DI for $registrationService
123
     *
124
     * @param Service\RegistrationService $registrationService
125
     */
126
    public function injectRegistrationService(\DERHANSEN\SfEventMgt\Service\RegistrationService $registrationService)
127
    {
128
        $this->registrationService = $registrationService;
129
    }
130 4
131
    /**
132
     * DI for $settingsService
133 4
     *
134
     * @param Service\SettingsService $settingsService
135 4
     */
136 3
    public function injectSettingsService(\DERHANSEN\SfEventMgt\Service\SettingsService $settingsService)
137 3
    {
138 4
        $this->settingsService = $settingsService;
139
    }
140 4
141 2
    /**
142 2
     * Initialize action
143
     *
144 4
     * @return void
145 1
     */
146 1
    public function initializeAction()
147 1
    {
148 1
        $this->pid = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('id');
149
    }
150 4
151 4
    /**
152 4
     * Set date format for fields startDate and endDate
153 4
     *
154
     * @return void
155
     */
156
    public function initializeListAction()
157
    {
158
        if ($this->settings === null) {
159
            $this->redirect('settingsError');
160
        }
161
        $this->arguments->getArgument('searchDemand')
162 1
            ->getPropertyMappingConfiguration()->forProperty('startDate')
163
            ->setTypeConverterOption(
164 1
                'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
165 1
                DateTimeConverter::CONFIGURATION_DATE_FORMAT,
166
                $this->settings['search']['dateFormat']
167
            );
168
        $this->arguments->getArgument('searchDemand')
169
            ->getPropertyMappingConfiguration()->forProperty('endDate')
170
            ->setTypeConverterOption(
171
                'TYPO3\\CMS\\Extbase\\Property\\TypeConverter\\DateTimeConverter',
172
                DateTimeConverter::CONFIGURATION_DATE_FORMAT,
173 1
                $this->settings['search']['dateFormat']
174
            );
175 1
    }
176 1
177 1
    /**
178
     * List action for backend module
179
     *
180
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand
181
     * @param int $messageId MessageID
182
     *
183
     * @return void
184
     */
185
    public function listAction(SearchDemand $searchDemand = null, $messageId = null)
186 1
    {
187
        /** @var EventDemand $demand */
188 1
        $demand = $this->objectManager->get('DERHANSEN\\SfEventMgt\\Domain\\Model\\Dto\\EventDemand');
189 1
190 1
        if ($searchDemand !== null) {
191 1
            $searchDemand->setFields($this->settings['search']['fields']);
192 1
        }
193 1
        $demand->setSearchDemand($searchDemand);
0 ignored issues
show
Bug introduced by
It seems like $searchDemand defined by parameter $searchDemand on line 185 can be null; however, DERHANSEN\SfEventMgt\Dom...mand::setSearchDemand() does not accept null, maybe add an additional type check?

It seems like you allow that null is being passed for a parameter, however the function which is called does not seem to accept null.

We recommend to add an additional type check (or disallow null for the parameter):

function notNullable(stdClass $x) { }

// Unsafe
function withoutCheck(stdClass $x = null) {
    notNullable($x);
}

// Safe - Alternative 1: Adding Additional Type-Check
function withCheck(stdClass $x = null) {
    if ($x instanceof stdClass) {
        notNullable($x);
    }
}

// Safe - Alternative 2: Changing Parameter
function withNonNullableParam(stdClass $x) {
    notNullable($x);
}
Loading history...
194 1
195 1
        if ($this->pid > 0) {
196
            $demand->setStoragePage($this->pid);
197
        }
198
199
        $variables = [];
200
        if ($messageId !== null && is_numeric($messageId)) {
201
            $variables['showMessage'] = true;
202
            $variables['messageTitleKey'] = 'administration.message-' . $messageId . '.title';
203
            $variables['messageContentKey'] = 'administration.message-' . $messageId . '.content';
204
        }
205 1
206
        $variables['events'] = $this->eventRepository->findDemanded($demand);
207 1
        $variables['searchDemand'] = $searchDemand;
208 1
        $this->view->assignMultiple($variables);
209 1
    }
210 1
211 1
    /**
212
     * Export registrations for a given event
213 1
     *
214 1
     * @param int $eventUid Event UID
215 1
     *
216
     * @return bool Always FALSE, since no view should be rendered
217
     */
218
    public function exportAction($eventUid)
219
    {
220
        $this->exportService->downloadRegistrationsCsv($eventUid, $this->settings['csvExport']);
221
        return false;
222
    }
223
224
    /**
225
     * Calls the handleExpiredRegistrations Service
226
     *
227
     * @return void
228
     */
229
    public function handleExpiredRegistrationsAction()
230
    {
231
        $this->registrationService->handleExpiredRegistrations($this->settings['registration']['deleteExpiredRegistrations']);
232
        $this->redirect('list', 'Administration', 'SfEventMgt', ['demand' => null, 'messageId' => 1]);
233
    }
234
235
    /**
236
     * The index notify action
237
     *
238
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
239
     *
240
     * @return void
241
     */
242
    public function indexNotifyAction(Event $event)
243
    {
244
        $customNotifications = $this->settingsService->getCustomNotifications($this->settings);
245
        $logEntries = $this->customNotificationLogRepository->findByEvent($event);
0 ignored issues
show
Documentation Bug introduced by
The method findByEvent does not exist on object<DERHANSEN\SfEvent...ificationLogRepository>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
246
        $this->view->assignMultiple([
247
            'event' => $event,
248
            'customNotifications' => $customNotifications,
249
            'logEntries' => $logEntries,
250
        ]);
251
    }
252
253
    /**
254
     * Notify action
255
     *
256
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
257
     * @param string $customNotification CustomNotification
258
     *
259
     * @return void
260
     */
261
    public function notifyAction(Event $event, $customNotification)
262
    {
263
        $customNotifications = $this->settingsService->getCustomNotifications($this->settings);
264
        $result = $this->notificationService->sendCustomNotification($event, $customNotification, $this->settings);
265
        $this->notificationService->createCustomNotificationLogentry(
266
            $event,
267
            $customNotifications[$customNotification],
268
            $result
269
        );
270
        $this->redirect('list', 'Administration', 'SfEventMgt', ['demand' => null, 'messageId' => 2]);
271
    }
272
273
    /**
274
     * Shows the settings error view
275
     *
276
     * @return void
277
     */
278
    public function settingsErrorAction()
279
    {
280
    }
281
}
282