|
1
|
|
|
<?php namespace App\Modules\Notifications\Services; |
|
2
|
|
|
|
|
3
|
|
|
use App\Modules\Core\BaseClasses\BaseService; |
|
4
|
|
|
use App\Modules\Notifications\Repositories\NotificationRepository; |
|
5
|
|
|
|
|
6
|
|
|
class NotificationService extends BaseService |
|
7
|
|
|
{ |
|
8
|
|
|
/** |
|
9
|
|
|
* Init new object. |
|
10
|
|
|
* |
|
11
|
|
|
* @param NotificationRepository $repo |
|
12
|
|
|
* @return void |
|
|
|
|
|
|
13
|
|
|
*/ |
|
14
|
|
|
public function __construct(NotificationRepository $repo) |
|
15
|
|
|
{ |
|
16
|
|
|
parent::__construct($repo); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Retrieve all notifications of the logged in user. |
|
21
|
|
|
* |
|
22
|
|
|
* @param integer $perPage |
|
23
|
|
|
* @return Collection |
|
24
|
|
|
*/ |
|
25
|
|
|
public function my($perPage) |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->repo->my($perPage); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Retrieve unread notifications of the logged in user. |
|
32
|
|
|
* |
|
33
|
|
|
* @param integer $perPage |
|
34
|
|
|
* @return Collection |
|
35
|
|
|
*/ |
|
36
|
|
|
public function unread($perPage) |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->repo->unread($perPage); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Mark the notification as read. |
|
43
|
|
|
* |
|
44
|
|
|
* @param integer $id |
|
45
|
|
|
* @return object |
|
46
|
|
|
*/ |
|
47
|
|
|
public function markAsRead($id) |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->repo->markAsRead($id); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Mark all notifications as read. |
|
54
|
|
|
* |
|
55
|
|
|
* @return void |
|
56
|
|
|
*/ |
|
57
|
|
|
public function markAllAsRead() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->repo->markAllAsRead(); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Notify th given user with the given notification. |
|
64
|
|
|
* |
|
65
|
|
|
* @param collection $users |
|
66
|
|
|
* @param string $notification |
|
67
|
|
|
* @param object $notificationData |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
public function notify($users, $notification, $notificationData = false) |
|
71
|
|
|
{ |
|
72
|
|
|
$notification = 'App\Modules\Notifications\Notifications\\'.$notification; |
|
73
|
|
|
\Notification::send($users, new $notification($notificationData)); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.