|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle; |
|
4
|
|
|
|
|
5
|
|
|
use IrishDan\NotificationBundle\Notification\NotifiableInterface; |
|
6
|
|
|
use IrishDan\NotificationBundle\Notification\NotificationInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class NotificationManager |
|
10
|
|
|
* This the primary public service. |
|
11
|
|
|
* From here all notifications can be dispatched. |
|
12
|
|
|
* Essentially is just a wrapper around the ContainerManager and DatabaseNotificationManager |
|
13
|
|
|
* |
|
14
|
|
|
* @package NotificationBundle |
|
15
|
|
|
*/ |
|
16
|
|
|
class NotificationManager |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var ChannelManager |
|
20
|
|
|
*/ |
|
21
|
|
|
private $channelManager; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var DatabaseNotificationManager |
|
24
|
|
|
*/ |
|
25
|
|
|
private $databaseNotificationManager; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct(ChannelManager $channelManager) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->channelManager = $channelManager; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function broadcast(NotificationInterface $notificatin, array $broadcasters = null) { |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function send(NotificationInterface $notification, $recipients) |
|
37
|
|
|
{ |
|
38
|
|
|
if (!is_array($recipients)) { |
|
39
|
|
|
$recipients = [$recipients]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
$this->channelManager->send($recipients, $notification); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function markAsRead(NotificationInterface $notification) |
|
46
|
|
|
{ |
|
47
|
|
|
$now = new \DateTime(); |
|
48
|
|
|
try { |
|
49
|
|
|
$this->databaseNotificationManager->setReadAtDate($notification, $now); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
return true; |
|
52
|
|
|
} catch (\Exception $exception) { |
|
53
|
|
|
// @TODO: |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function markAllAsRead(NotifiableInterface $user) |
|
58
|
|
|
{ |
|
59
|
|
|
$now = new \DateTime(); |
|
60
|
|
|
try { |
|
61
|
|
|
$this->databaseNotificationManager->setUsersNotificationsAsRead($user, $now); |
|
62
|
|
|
|
|
63
|
|
|
return true; |
|
64
|
|
|
} catch (\Exception $exception) { |
|
65
|
|
|
// @TODO: |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function allNotificationCount(NotifiableInterface $user) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->notificationCount($user); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function unreadNotificationCount(NotifiableInterface $user) |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->notificationCount($user, 'unread'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function readNotificationCount(NotifiableInterface $user) |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->notificationCount($user, 'read'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function notificationCount(NotifiableInterface $user, $status = '') |
|
85
|
|
|
{ |
|
86
|
|
|
// try { |
|
87
|
|
|
|
|
88
|
|
|
return $this->databaseNotificationManager->getUsersNotificationCount($user, $status); |
|
89
|
|
|
// } catch (\Exception $exception) { |
|
|
|
|
|
|
90
|
|
|
// // @TODO: |
|
91
|
|
|
// } |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public function setDatabaseNotificationManager(DatabaseNotificationManager $databaseNotificationManager) |
|
95
|
|
|
{ |
|
96
|
|
|
$this->databaseNotificationManager = $databaseNotificationManager; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.