Completed
Push — development ( 640c04...189908 )
by Torben
09:05 queued 03:50
created

AdministrationController   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 202
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 97.01%

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 10
dl 0
loc 202
rs 10
c 0
b 0
f 0
ccs 65
cts 67
cp 0.9701

11 Methods

Rating   Name   Duplication   Size   Complexity  
A injectCustomNotificationLogRepository() 0 5 1
A injectExportService() 0 4 1
A injectSettingsService() 0 4 1
A initializeAction() 0 4 1
A initializeListAction() 0 20 2
B listAction() 0 25 5
A exportAction() 0 5 1
A handleExpiredRegistrationsAction() 0 5 1
A indexNotifyAction() 0 10 1
A notifyAction() 0 11 1
A settingsErrorAction() 0 3 1
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 AbstractController
29
{
30
    /**
31
     * CustomNotificationLogRepository
32
     *
33
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository
34
     */
35
    protected $customNotificationLogRepository = null;
36
37
    /**
38
     * ExportService
39
     *
40
     * @var \DERHANSEN\SfEventMgt\Service\ExportService
41
     */
42
    protected $exportService = null;
43
44
    /**
45
     * SettingsService
46
     *
47
     * @var \DERHANSEN\SfEventMgt\Service\SettingsService
48
     */
49
    protected $settingsService = null;
50
51
    /**
52
     * The current page uid
53
     *
54
     * @var int
55
     */
56
    protected $pid = 0;
57
58
    /**
59
     * DI for $customNotificationLogRepository
60
     *
61
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository
62
     */
63
    public function injectCustomNotificationLogRepository(
64
        \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository
65
    ) {
66
        $this->customNotificationLogRepository = $customNotificationLogRepository;
67
    }
68
69
    /**
70
     * DI for $exportService
71
     *
72
     * @param Service\ExportService $exportService
73
     */
74
    public function injectExportService(\DERHANSEN\SfEventMgt\Service\ExportService $exportService)
75
    {
76
        $this->exportService = $exportService;
77
    }
78
79
    /**
80
     * DI for $settingsService
81
     *
82
     * @param Service\SettingsService $settingsService
83
     */
84
    public function injectSettingsService(\DERHANSEN\SfEventMgt\Service\SettingsService $settingsService)
85
    {
86
        $this->settingsService = $settingsService;
87
    }
88
89
    /**
90
     * Initialize action
91 1
     *
92
     * @return void
93 1
     */
94 1
    public function initializeAction()
95
    {
96
        $this->pid = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('id');
97
    }
98
99
    /**
100
     * Set date format for fields startDate and endDate
101 2
     *
102
     * @return void
103 2
     */
104 1
    public function initializeListAction()
105 1
    {
106 2
        if ($this->settings === null) {
107 2
            $this->redirect('settingsError');
108 2
        }
109 2
        $this->arguments->getArgument('searchDemand')
110 2
            ->getPropertyMappingConfiguration()->forProperty('startDate')
111 2
            ->setTypeConverterOption(
112 2
                DateTimeConverter::class,
113 2
                DateTimeConverter::CONFIGURATION_DATE_FORMAT,
114 2
                $this->settings['search']['dateFormat']
115 2
            );
116 2
        $this->arguments->getArgument('searchDemand')
117 2
            ->getPropertyMappingConfiguration()->forProperty('endDate')
118 2
            ->setTypeConverterOption(
119 2
                DateTimeConverter::class,
120 2
                DateTimeConverter::CONFIGURATION_DATE_FORMAT,
121
                $this->settings['search']['dateFormat']
122
            );
123
    }
124
125
    /**
126
     * List action for backend module
127
     *
128
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand
129
     * @param int $messageId MessageID
130 4
     *
131
     * @return void
132
     */
133 4
    public function listAction(SearchDemand $searchDemand = null, $messageId = null)
134
    {
135 4
        /** @var EventDemand $demand */
136 3
        $demand = $this->objectManager->get(EventDemand::class);
137 3
138 4
        if ($searchDemand !== null) {
139
            $searchDemand->setFields($this->settings['search']['fields']);
140 4
        }
141 2
        $demand->setSearchDemand($searchDemand);
0 ignored issues
show
Bug introduced by
It seems like $searchDemand defined by parameter $searchDemand on line 133 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...
142 2
143
        if ($this->pid > 0) {
144 4
            $demand->setStoragePage($this->pid);
145 1
        }
146 1
147 1
        $variables = [];
148 1
        if ($messageId !== null && is_numeric($messageId)) {
149
            $variables['showMessage'] = true;
150 4
            $variables['messageTitleKey'] = 'administration.message-' . $messageId . '.title';
151 4
            $variables['messageContentKey'] = 'administration.message-' . $messageId . '.content';
152 4
        }
153 4
154
        $variables['events'] = $this->eventRepository->findDemanded($demand);
155
        $variables['searchDemand'] = $searchDemand;
156
        $this->view->assignMultiple($variables);
157
    }
158
159
    /**
160
     * Export registrations for a given event
161
     *
162 1
     * @param int $eventUid Event UID
163
     *
164 1
     * @return bool Always FALSE, since no view should be rendered
165 1
     */
166
    public function exportAction($eventUid)
167
    {
168
        $this->exportService->downloadRegistrationsCsv($eventUid, $this->settings['csvExport']);
169
        return false;
170
    }
171
172
    /**
173 1
     * Calls the handleExpiredRegistrations Service
174
     *
175 1
     * @return void
176 1
     */
177 1
    public function handleExpiredRegistrationsAction()
178
    {
179
        $this->registrationService->handleExpiredRegistrations($this->settings['registration']['deleteExpiredRegistrations']);
180
        $this->redirect('list', 'Administration', 'SfEventMgt', ['demand' => null, 'messageId' => 1]);
181
    }
182
183
    /**
184
     * The index notify action
185
     *
186 1
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
187
     *
188 1
     * @return void
189 1
     */
190 1
    public function indexNotifyAction(Event $event)
191 1
    {
192 1
        $customNotifications = $this->settingsService->getCustomNotifications($this->settings);
193 1
        $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...
194 1
        $this->view->assignMultiple([
195 1
            'event' => $event,
196
            'customNotifications' => $customNotifications,
197
            'logEntries' => $logEntries,
198
        ]);
199
    }
200
201
    /**
202
     * Notify action
203
     *
204
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
205 1
     * @param string $customNotification CustomNotification
206
     *
207 1
     * @return void
208 1
     */
209 1
    public function notifyAction(Event $event, $customNotification)
210 1
    {
211 1
        $customNotifications = $this->settingsService->getCustomNotifications($this->settings);
212
        $result = $this->notificationService->sendCustomNotification($event, $customNotification, $this->settings);
213 1
        $this->notificationService->createCustomNotificationLogentry(
214 1
            $event,
215 1
            $customNotifications[$customNotification],
216
            $result
217
        );
218
        $this->redirect('list', 'Administration', 'SfEventMgt', ['demand' => null, 'messageId' => 2]);
219
    }
220
221
    /**
222
     * Shows the settings error view
223
     *
224
     * @return void
225
     */
226
    public function settingsErrorAction()
227
    {
228
    }
229
}
230