Passed
Push — master ( c2c83c...eb4088 )
by Nathan
03:39
created

getAllNotificationsWithDisabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
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\Notification\EntityNotification;
23
use CuyZ\Notiz\Domain\Repository\EntityNotificationRepository;
24
25
abstract class EntityNotificationProcessor extends NotificationProcessor
26
{
27
    /**
28
     * The repository needs to be injected in the child class.
29
     *
30
     * @var EntityNotificationRepository
31
     */
32
    protected $notificationRepository;
33
34
    /**
35
     * @param EventDefinition $definition
36
     * @return Notification[]
37
     */
38
    public function getNotificationsFromEventDefinition(EventDefinition $definition)
39
    {
40
        return $this->notificationRepository
41
            ->findFromEventDefinition($definition)
42
            ->toArray();
43
    }
44
45
    /**
46
     * @param EventDefinition $definition
47
     * @return Notification[]
48
     */
49
    public function getNotificationsFromEventDefinitionWithDisabled(EventDefinition $definition)
50
    {
51
        return $this->notificationRepository
52
            ->findFromEventDefinitionWithDisabled($definition)
53
            ->toArray();
54
    }
55
56
    /**
57
     * @param EventDefinition $definition
58
     * @return int
59
     */
60
    public function countNotificationsFromEventDefinition(EventDefinition $definition)
61
    {
62
        return $this->notificationRepository->countFromEventDefinition($definition);
63
    }
64
65
    /**
66
     * @param string $identifier
67
     * @return Notification|object
68
     */
69
    public function getNotificationFromIdentifier($identifier)
70
    {
71
        return $this->notificationRepository->findByIdentifierForce($identifier);
72
    }
73
74
    /**
75
     * @return Notification[]
76
     */
77
    public function getAllNotifications()
78
    {
79
        return $this->notificationRepository
80
            ->findAll()
81
            ->toArray();
82
    }
83
84
    /**
85
     * @return Notification[]
86
     */
87
    public function getAllNotificationsWithDisabled()
88
    {
89
        return $this->notificationRepository
90
            ->findAllWithDisabled()
91
            ->toArray();
92
    }
93
94
    /**
95
     * @return int
96
     */
97
    public function getTotalNumber()
98
    {
99
        return $this->notificationRepository
100
            ->findAll()
101
            ->count();
102
    }
103
104
    /**
105
     * @param Activable|EntityNotification $notification
106
     */
107
    public function enable(Activable $notification)
108
    {
109
        $notification->setActive(true);
0 ignored issues
show
Bug introduced by
The method setActive() does not exist on CuyZ\Notiz\Core\Notification\Activable. Since it exists in all sub-types, consider adding an abstract or default implementation to CuyZ\Notiz\Core\Notification\Activable. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
        $notification->/** @scrutinizer ignore-call */ 
110
                       setActive(true);
Loading history...
110
111
        $this->notificationRepository->update($notification);
112
    }
113
114
    /**
115
     * @param Activable|EntityNotification $notification
116
     */
117
    public function disable(Activable $notification)
118
    {
119
        $notification->setActive(false);
120
121
        $this->notificationRepository->update($notification);
122
    }
123
}
124