Passed
Pull Request — master (#159)
by Nathan
03:58
created

EntityNotificationProcessor::disable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
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\Core\Notification\Processor;
18
19
use CuyZ\Notiz\Core\Definition\Tree\EventGroup\Event\EventDefinition;
20
use CuyZ\Notiz\Core\Notification\Activable;
21
use CuyZ\Notiz\Core\Notification\Notification;
22
use CuyZ\Notiz\Domain\Repository\EntityNotificationRepository;
23
24
abstract class EntityNotificationProcessor extends NotificationProcessor
25
{
26
    /**
27
     * The repository needs to be injected in the child class.
28
     *
29
     * @var EntityNotificationRepository
30
     */
31
    protected $notificationRepository;
32
33
    /**
34
     * @param EventDefinition $definition
35
     * @return Notification[]
36
     */
37
    public function getNotificationsFromEventDefinition(EventDefinition $definition)
38
    {
39
        return $this->notificationRepository
40
            ->findFromEventDefinition($definition)
41
            ->toArray();
42
    }
43
44
    /**
45
     * @param EventDefinition $definition
46
     * @return Notification[]
47
     */
48
    public function getNotificationsFromEventDefinitionWithDisabled(EventDefinition $definition)
49
    {
50
        return $this->notificationRepository
51
            ->findFromEventDefinitionWithDisabled($definition)
52
            ->toArray();
53
    }
54
55
    /**
56
     * @param EventDefinition $definition
57
     * @return int
58
     */
59
    public function countNotificationsFromEventDefinition(EventDefinition $definition)
60
    {
61
        return $this->notificationRepository->countFromEventDefinition($definition);
62
    }
63
64
    /**
65
     * @param string $identifier
66
     * @return Notification|object
67
     */
68
    public function getNotificationFromIdentifier($identifier)
69
    {
70
        return $this->notificationRepository->findByIdentifierForce($identifier);
71
    }
72
73
    /**
74
     * @return Notification[]
75
     */
76
    public function getAllNotifications()
77
    {
78
        return $this->notificationRepository
79
            ->findAll()
80
            ->toArray();
81
    }
82
83
    /**
84
     * @return Notification[]
85
     */
86
    public function getAllNotificationsWithDisabled()
87
    {
88
        return $this->notificationRepository
89
            ->findAllWithDisabled()
90
            ->toArray();
91
    }
92
93
    /**
94
     * @return int
95
     */
96
    public function getTotalNumber()
97
    {
98
        return $this->notificationRepository
99
            ->findAll()
100
            ->count();
101
    }
102
103
    /**
104
     * @inheritdoc
105
     */
106
    public function enable(Activable $notification)
107
    {
108
        $notification->markAsActive();
109
110
        $this->notificationRepository->update($notification);
111
    }
112
113
    /**
114
     * @inheritdoc
115
     */
116
    public function disable(Activable $notification)
117
    {
118
        $notification->markAsInactive();
119
120
        $this->notificationRepository->update($notification);
121
    }
122
}
123