Completed
Push — development ( 9bc761...3c5a2a )
by Torben
02:36
created

AdministrationController::getErrorFlashMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
namespace DERHANSEN\SfEventMgt\Controller;
3
4
/*
5
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.txt file that was distributed with this source code.
9
 */
10
11
use TYPO3\CMS\Extbase\Property\TypeConverter\DateTimeConverter;
12
use DERHANSEN\SfEventMgt\Domain\Model\Dto\EventDemand;
13
use DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand;
14
use DERHANSEN\SfEventMgt\Domain\Model\Event;
15
use DERHANSEN\SfEventMgt\Service;
16
17
/**
18
 * AdministrationController
19
 *
20
 * @author Torben Hansen <[email protected]>
21
 */
22
class AdministrationController extends AbstractController
23
{
24
    /**
25
     * CustomNotificationLogRepository
26
     *
27
     * @var \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository
28
     */
29
    protected $customNotificationLogRepository = null;
30
31
    /**
32
     * ExportService
33
     *
34
     * @var \DERHANSEN\SfEventMgt\Service\ExportService
35
     */
36
    protected $exportService = null;
37
38
    /**
39
     * SettingsService
40
     *
41
     * @var \DERHANSEN\SfEventMgt\Service\SettingsService
42
     */
43
    protected $settingsService = null;
44
45
    /**
46
     * Backend User Session Service
47
     *
48
     * @var \DERHANSEN\SfEventMgt\Service\BeUserSessionService
49
     */
50
    protected $beUserSessionService = null;
51
52
    /**
53
     * The current page uid
54
     *
55
     * @var int
56
     */
57
    protected $pid = 0;
58
59
    /**
60
     * DI for $customNotificationLogRepository
61
     *
62
     * @param \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository
63
     */
64
    public function injectCustomNotificationLogRepository(
65
        \DERHANSEN\SfEventMgt\Domain\Repository\CustomNotificationLogRepository $customNotificationLogRepository
66
    ) {
67
        $this->customNotificationLogRepository = $customNotificationLogRepository;
68
    }
69
70
    /**
71
     * DI for $exportService
72
     *
73
     * @param Service\ExportService $exportService
74
     */
75
    public function injectExportService(\DERHANSEN\SfEventMgt\Service\ExportService $exportService)
76
    {
77
        $this->exportService = $exportService;
78
    }
79
80
    /**
81
     * DI for $settingsService
82
     *
83
     * @param Service\SettingsService $settingsService
84
     */
85
    public function injectSettingsService(\DERHANSEN\SfEventMgt\Service\SettingsService $settingsService)
86
    {
87
        $this->settingsService = $settingsService;
88
    }
89
90
    /**
91 1
     * DI for $beUserSessionService
92
     *
93 1
     * @param Service\BeUserSessionService $beUserSessionService
94 1
     */
95
    public function injectBeUserSessionService(\DERHANSEN\SfEventMgt\Service\BeUserSessionService $beUserSessionService)
96
    {
97
        $this->beUserSessionService = $beUserSessionService;
98
    }
99
100
    /**
101 2
     * Initialize action
102
     *
103 2
     * @return void
104 1
     */
105 1
    public function initializeAction()
106 2
    {
107 2
        $this->pid = (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('id');
108 2
    }
109 2
110 2
    /**
111 2
     * Set date format for fields startDate and endDate
112 2
     *
113 2
     * @return void
114 2
     */
115 2
    public function initializeListAction()
116 2
    {
117 2
        if ($this->settings === null) {
118 2
            $this->redirect('settingsError');
119 2
        }
120 2
        $this->arguments->getArgument('searchDemand')
121
            ->getPropertyMappingConfiguration()->forProperty('startDate')
122
            ->setTypeConverterOption(
123
                DateTimeConverter::class,
124
                DateTimeConverter::CONFIGURATION_DATE_FORMAT,
125
                $this->settings['search']['dateFormat']
126
            );
127
        $this->arguments->getArgument('searchDemand')
128
            ->getPropertyMappingConfiguration()->forProperty('endDate')
129
            ->setTypeConverterOption(
130 4
                DateTimeConverter::class,
131
                DateTimeConverter::CONFIGURATION_DATE_FORMAT,
132
                $this->settings['search']['dateFormat']
133 4
            );
134
    }
135 4
136 3
    /**
137 3
     * List action for backend module
138 4
     *
139
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Dto\SearchDemand $searchDemand SearchDemand
140 4
     * @param int $messageId MessageID
141 2
     *
142 2
     * @return void
143
     */
144 4
    public function listAction(SearchDemand $searchDemand = null, $messageId = null)
145 1
    {
146 1
        /** @var EventDemand $demand */
147 1
        $demand = $this->objectManager->get(EventDemand::class);
148 1
149
        if ($searchDemand !== null) {
150 4
            $searchDemand->setFields($this->settings['search']['fields']);
151 4
152 4
            $sessionData = [];
153 4
            $sessionData['searchDemand'] = $searchDemand;
154
            $this->beUserSessionService->saveSessionData($sessionData);
155
        } else {
156
            // Try to restore search demand from Session
157
            $searchDemand = $this->beUserSessionService->getSessionDataByKey('searchDemand');
158
        }
159
160
        $demand->setSearchDemand($searchDemand);
161
162 1
        if ($this->pid > 0) {
163
            $demand->setStoragePage($this->pid);
164 1
        }
165 1
166
        $variables = [];
167
        if ($messageId !== null && is_numeric($messageId)) {
168
            $variables['showMessage'] = true;
169
            $variables['messageTitleKey'] = 'administration.message-' . $messageId . '.title';
170
            $variables['messageContentKey'] = 'administration.message-' . $messageId . '.content';
171
        }
172
173 1
        $variables['events'] = $this->eventRepository->findDemanded($demand);
174
        $variables['searchDemand'] = $searchDemand;
175 1
        $this->view->assignMultiple($variables);
176 1
    }
177 1
178
    /**
179
     * Export registrations for a given event
180
     *
181
     * @param int $eventUid Event UID
182
     *
183
     * @return bool Always FALSE, since no view should be rendered
184
     */
185
    public function exportAction($eventUid)
186 1
    {
187
        $this->exportService->downloadRegistrationsCsv($eventUid, $this->settings['csvExport']);
188 1
        return false;
189 1
    }
190 1
191 1
    /**
192 1
     * Calls the handleExpiredRegistrations Service
193 1
     *
194 1
     * @return void
195 1
     */
196
    public function handleExpiredRegistrationsAction()
197
    {
198
        $this->registrationService->handleExpiredRegistrations($this->settings['registration']['deleteExpiredRegistrations']);
199
        $this->redirect('list', 'Administration', 'SfEventMgt', ['demand' => null, 'messageId' => 1]);
200
    }
201
202
    /**
203
     * The index notify action
204
     *
205 1
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
206
     *
207 1
     * @return void
208 1
     */
209 1
    public function indexNotifyAction(Event $event)
210 1
    {
211 1
        $customNotifications = $this->settingsService->getCustomNotifications($this->settings);
212
        $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...
213 1
        $this->view->assignMultiple([
214 1
            'event' => $event,
215 1
            'customNotifications' => $customNotifications,
216
            'logEntries' => $logEntries,
217
        ]);
218
    }
219
220
    /**
221
     * Notify action
222
     *
223
     * @param \DERHANSEN\SfEventMgt\Domain\Model\Event $event Event
224
     * @param string $customNotification CustomNotification
225
     *
226
     * @return void
227
     */
228
    public function notifyAction(Event $event, $customNotification)
229
    {
230
        $customNotifications = $this->settingsService->getCustomNotifications($this->settings);
231
        $result = $this->notificationService->sendCustomNotification($event, $customNotification, $this->settings);
232
        $this->notificationService->createCustomNotificationLogentry(
233
            $event,
234
            $customNotifications[$customNotification],
235
            $result
236
        );
237
        $this->redirect('list', 'Administration', 'SfEventMgt', ['demand' => null, 'messageId' => 2]);
238
    }
239
240
    /**
241
     * Shows the settings error view
242
     *
243
     * @return void
244
     */
245
    public function settingsErrorAction()
246
    {
247
    }
248
249
    /**
250
     * Suppress default validation messages
251
     *
252
     * @return bool
253
     */
254
    protected function getErrorFlashMessage()
255
    {
256
        return false;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return false; (false) is incompatible with the return type of the parent method TYPO3\CMS\Extbase\Mvc\Co...r::getErrorFlashMessage of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
257
    }
258
}
259