Passed
Push — master ( 801c53...c2c83c )
by Nathan
03:05
created

ListNotificationsController::getNotifications()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Copyright (C) 2018
5
 * Nathan Boiron <[email protected]>
6
 * Romain Canon <[email protected]>
7
 *
8
 * This file is part of the TYPO3 NotiZ project.
9
 * It is free software; you can redistribute it and/or modify it
10
 * under the terms of the GNU General Public License, either
11
 * version 3 of the License, or any later version.
12
 *
13
 * For the full copyright and license information, see:
14
 * http://www.gnu.org/licenses/gpl-3.0.html
15
 */
16
17
namespace CuyZ\Notiz\Controller\Backend\Manager;
18
19
use CuyZ\Notiz\Controller\Backend\Menu;
20
use CuyZ\Notiz\Core\Notification\Notification;
21
22
/**
23
 * Lists all notifications entries belonging to a given type.
24
 */
25
class ListNotificationsController extends ManagerController
26
{
27
    /**
28
     * @param string $notificationIdentifier
29
     * @param string $filterEvent
30
     */
31
    public function processAction($notificationIdentifier, $filterEvent = null)
32
    {
33
        $definition = $this->getDefinition();
34
35
        if (!$definition->hasNotification($notificationIdentifier)) {
36
            $this->addErrorMessage(
37
                'Backend/Module/Manager/ListNotifications:notification_type_not_found',
38
                $notificationIdentifier
39
            );
40
41
            $this->forward('process', 'Backend\\Manager\\ListNotificationTypes');
42
        }
43
44
        $notificationDefinition = $definition->getNotification($notificationIdentifier);
45
        $notifications = $this->getNotifications($notificationIdentifier, $filterEvent);
46
47
        $this->view->assign('notificationDefinition', $notificationDefinition);
48
        $this->view->assign('notifications', $notifications);
49
    }
50
51
    /**
52
     * @return string
53
     */
54
    protected function getMenu()
55
    {
56
        return Menu::MANAGER_NOTIFICATIONS;
57
    }
58
59
    /**
60
     * @param string $notificationIdentifier
61
     * @param string|null $filterEvent
62
     * @return Notification[]
63
     */
64
    private function getNotifications($notificationIdentifier, $filterEvent)
65
    {
66
        $definition = $this->getDefinition();
67
68
        $notificationDefinition = $definition->getNotification($notificationIdentifier);
69
        $processor = $notificationDefinition->getProcessor();
70
71
        if ($filterEvent) {
72
            $eventDefinition = $definition->getEventFromFullIdentifier($filterEvent);
73
74
            $this->view->assign('eventDefinition', $eventDefinition);
75
            $this->view->assign('fullEventIdentifier', $filterEvent);
76
77
            return $processor->getNotificationsFromEventDefinition($eventDefinition);
78
        }
79
80
        return $processor->getAllNotifications();
81
    }
82
}
83