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 send(NotificationInterface $notification, $recipients) |
33
|
|
|
{ |
34
|
|
|
if (!is_array($recipients)) { |
35
|
|
|
$recipients = [$recipients]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$this->channelManager->send($recipients, $notification); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function markAsRead(NotificationInterface $notification) |
42
|
|
|
{ |
43
|
|
|
$now = new \DateTime(); |
44
|
|
|
try { |
45
|
|
|
$this->databaseNotificationManager->setReadAtDate($notification, $now); |
|
|
|
|
46
|
|
|
|
47
|
|
|
return true; |
48
|
|
|
} catch (\Exception $exception) { |
49
|
|
|
// @TODO: |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function markAllAsRead(NotifiableInterface $user) |
54
|
|
|
{ |
55
|
|
|
$now = new \DateTime(); |
56
|
|
|
try { |
57
|
|
|
$this->databaseNotificationManager->setUsersNotificationsAsRead($user, $now); |
58
|
|
|
|
59
|
|
|
return true; |
60
|
|
|
} catch (\Exception $exception) { |
61
|
|
|
// @TODO: |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function allNotificationCount(NotifiableInterface $user) |
66
|
|
|
{ |
67
|
|
|
return $this->notificationCount($user); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function unreadNotificationCount(NotifiableInterface $user) |
71
|
|
|
{ |
72
|
|
|
return $this->notificationCount($user, 'unread'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function readNotificationCount(NotifiableInterface $user) |
76
|
|
|
{ |
77
|
|
|
return $this->notificationCount($user, 'read'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function notificationCount(NotifiableInterface $user, $status = '') |
81
|
|
|
{ |
82
|
|
|
// try { |
83
|
|
|
|
84
|
|
|
return $this->databaseNotificationManager->getUsersNotificationCount($user, $status); |
85
|
|
|
// } catch (\Exception $exception) { |
|
|
|
|
86
|
|
|
// // @TODO: |
87
|
|
|
// } |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function setDatabaseNotificationManager(DatabaseNotificationManager $databaseNotificationManager) |
91
|
|
|
{ |
92
|
|
|
$this->databaseNotificationManager = $databaseNotificationManager; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: