|
1
|
|
|
<?php namespace App\Modules\V1\Notifications\Repositories; |
|
2
|
|
|
|
|
3
|
|
|
use App\Modules\V1\Core\AbstractRepositories\AbstractRepository; |
|
4
|
|
|
|
|
5
|
|
|
class NotificationRepository extends AbstractRepository |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Return the model full namespace. |
|
9
|
|
|
* |
|
10
|
|
|
* @return string |
|
11
|
|
|
*/ |
|
12
|
|
|
protected function getModel() |
|
13
|
|
|
{ |
|
14
|
|
|
return 'App\Modules\V1\Notifications\Notification'; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Retrieve all notifications of the logged in user. |
|
19
|
|
|
* |
|
20
|
|
|
* @param integer $perPage |
|
21
|
|
|
* @return Collection |
|
22
|
|
|
*/ |
|
23
|
|
|
public function list($perPage) |
|
24
|
|
|
{ |
|
25
|
|
|
return \Auth::user()->notifications()->paginate($perPage); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Retrieve unread notifications of the logged in user. |
|
30
|
|
|
* |
|
31
|
|
|
* @param integer $perPage |
|
32
|
|
|
* @return Collection |
|
33
|
|
|
*/ |
|
34
|
|
|
public function unread($perPage) |
|
35
|
|
|
{ |
|
36
|
|
|
return \Auth::user()->unreadNotifications()->paginate($perPage); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Mark the notification as read. |
|
41
|
|
|
* |
|
42
|
|
|
* @param integer $id |
|
43
|
|
|
* @return object |
|
44
|
|
|
*/ |
|
45
|
|
|
public function markAsRead($id) |
|
46
|
|
|
{ |
|
47
|
|
|
if ($notification = \Auth::user()->unreadNotifications()->where('id', $id)) |
|
48
|
|
|
{ |
|
49
|
|
|
$notification->first()->markAsRead(); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Mark all notifications as read. |
|
55
|
|
|
* |
|
56
|
|
|
* @return void |
|
57
|
|
|
*/ |
|
58
|
|
|
public function markAllAsRead() |
|
59
|
|
|
{ |
|
60
|
|
|
\Auth::user()->unreadNotifications()->update(['read_at' => now()]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Notify th given user with the given notification. |
|
65
|
|
|
* |
|
66
|
|
|
* @param collection $users |
|
67
|
|
|
* @param string $notification |
|
68
|
|
|
* @param object $notificationData |
|
69
|
|
|
* @return void |
|
70
|
|
|
*/ |
|
71
|
|
|
public function notify($users, $notification, $notificationData = false) |
|
72
|
|
|
{ |
|
73
|
|
|
$notification = 'App\Modules\V1\Notifications\Notifications\\' . $notification; |
|
74
|
|
|
\Notification::send($users, new $notification($notificationData)); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|