Completed
Push — development ( b65fd0...1c81ac )
by Torben
02:57
created

injectBeUserSessionService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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