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); |
|
|
|
|
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
|
|
|
|