Total Complexity | 10 |
Total Lines | 121 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
14 | class NotificationRepository extends Repository implements NotificationRepositoryInterface |
||
15 | { |
||
16 | /** |
||
17 | * @return string |
||
18 | */ |
||
19 | public function model() |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * @param int $userId |
||
26 | * @param int $perPage |
||
27 | * @return mixed |
||
28 | */ |
||
29 | public function lengthAwarePaginate($userId, $perPage = 20) |
||
30 | { |
||
31 | return $this->prepare($userId)->paginate($perPage); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param int $userId |
||
36 | * @param int $limit |
||
37 | * @param int $offset |
||
38 | * @return mixed |
||
39 | */ |
||
40 | public function takeForUser($userId, $limit = 10, $offset = 0) |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Mark notifications as read |
||
47 | * |
||
48 | * @use Coyote\Http\Controllers\User\NotificationsController |
||
49 | * @param array $id |
||
50 | */ |
||
51 | public function markAsRead(array $id) |
||
52 | { |
||
53 | $this->model->whereIn('id', $id)->update(['read_at' => Carbon::now()]); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Find notification by url and mark it as read |
||
58 | * |
||
59 | * @param int $userId |
||
60 | * @param mixed $model |
||
61 | */ |
||
62 | public function markAsReadByModel($userId, $model) |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * Build query for repository |
||
75 | * |
||
76 | * @param int $userId |
||
77 | * @return mixed |
||
78 | */ |
||
79 | private function prepare($userId) |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * Gets public notification types |
||
103 | * |
||
104 | * @return mixed |
||
105 | * @throws \Illuminate\Contracts\Container\BindingResolutionException |
||
106 | */ |
||
107 | public function notificationTypes() |
||
108 | { |
||
109 | return $this |
||
110 | ->app |
||
111 | ->make(Notification\Type::class) |
||
112 | ->select() |
||
113 | ->where('is_public', 1) |
||
114 | ->orderBy('notification_types.id') |
||
115 | ->get(); |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * @param int $userId |
||
120 | * @param array $data |
||
121 | * @throws \Illuminate\Contracts\Container\BindingResolutionException |
||
122 | */ |
||
123 | public function updateSettings($userId, array $data) |
||
124 | { |
||
125 | $model = $this->app->make(Setting::class); |
||
126 | |||
127 | foreach ($data as $id => $value) { |
||
128 | $model->where('user_id', $userId)->where('id', $id)->update(['is_enabled' => $value]); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | public function purge(): void |
||
135 | } |
||
136 | } |
||
137 |