1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Notimatica\Driver; |
4
|
|
|
|
5
|
|
|
use League\Event\ListenerAcceptorInterface; |
6
|
|
|
use League\Event\ListenerProviderInterface; |
7
|
|
|
use Notimatica\Driver\Contracts\NotificationRepository; |
8
|
|
|
use Notimatica\Driver\Events\NotificationClicked; |
9
|
|
|
use Notimatica\Driver\Events\NotificationDelivered; |
10
|
|
|
use Notimatica\Driver\Events\NotificationFailed; |
11
|
|
|
use Notimatica\Driver\Events\NotificationSent; |
12
|
|
|
|
13
|
|
|
class Statistics implements ListenerProviderInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var NotificationRepository |
17
|
|
|
*/ |
18
|
|
|
protected $notificationRepository; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Create a new StatisticsStorage. |
22
|
|
|
* |
23
|
|
|
* @param NotificationRepository $notificationRepository |
24
|
|
|
*/ |
25
|
14 |
|
public function __construct(NotificationRepository $notificationRepository) |
26
|
|
|
{ |
27
|
14 |
|
$this->notificationRepository = $notificationRepository; |
28
|
14 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Number of sent pushes. |
32
|
|
|
* |
33
|
|
|
* @param NotificationSent $event |
34
|
|
|
*/ |
35
|
1 |
|
public function sent(NotificationSent $event) |
36
|
|
|
{ |
37
|
1 |
|
$this->notificationRepository->increment($event->notification, 'sent', $event->number); |
38
|
1 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Number of delivered pushes. |
42
|
|
|
* |
43
|
|
|
* @param NotificationDelivered $event |
44
|
|
|
*/ |
45
|
1 |
|
public function delivered(NotificationDelivered $event) |
46
|
|
|
{ |
47
|
1 |
|
$this->notificationRepository->increment($event->notification, 'delivered', $event->number); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Number of clicked pushes. |
52
|
|
|
* |
53
|
|
|
* @param NotificationClicked $event |
54
|
|
|
*/ |
55
|
1 |
|
public function clicked(NotificationClicked $event) |
56
|
|
|
{ |
57
|
1 |
|
$this->notificationRepository->increment($event->notification, 'clicked', $event->number); |
58
|
1 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Number of failed pushes. |
62
|
|
|
* |
63
|
|
|
* @param NotificationFailed $event |
64
|
|
|
*/ |
65
|
4 |
|
public function failed(NotificationFailed $event) |
66
|
|
|
{ |
67
|
4 |
|
$this->notificationRepository->increment($event->notification, 'failed', $event->number); |
68
|
4 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Provide event. |
72
|
|
|
* |
73
|
|
|
* @param ListenerAcceptorInterface $listener |
74
|
|
|
* @return $this |
75
|
|
|
*/ |
76
|
9 |
|
public function provideListeners(ListenerAcceptorInterface $listener) |
77
|
|
|
{ |
78
|
|
|
$listener->addListener(NotificationSent::class, function ($e) { |
79
|
|
|
$this->sent($e); |
80
|
9 |
|
}); |
81
|
|
|
$listener->addListener(NotificationDelivered::class, function ($e) { |
82
|
|
|
$this->delivered($e); |
83
|
9 |
|
}); |
84
|
|
|
$listener->addListener(NotificationClicked::class, function ($e) { |
85
|
|
|
$this->clicked($e); |
86
|
9 |
|
}); |
87
|
9 |
|
$listener->addListener(NotificationFailed::class, function ($e) { |
88
|
3 |
|
$this->failed($e); |
89
|
9 |
|
}); |
90
|
|
|
|
91
|
9 |
|
return $this; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|