PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.4.01
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.4.01
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / app / Http / Controllers / NotificationsController.php

NotificationsController.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.4.01, at app/Http/Controllers/NotificationsController.php

105 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Http\Controllers;
4
5 use FluentCommunity\App\Http\Controllers\Controller;
6 use FluentCommunity\App\Models\Feed;
7 use FluentCommunity\App\Models\Notification;
8 use FluentCommunity\App\Models\NotificationSubscriber;
9 use FluentCommunity\App\Services\ProfileHelper;
10 use FluentCommunity\Framework\Http\Request\Request;
11
12 class NotificationsController extends Controller
13 {
14 public function getNotifications(Request $request)
15 {
16 $user = $this->getUser(true);
17
18 $notifications = Notification::whereHas('subscribers', function ($query) use ($user) {
19 return $query->where('user_id', $user->ID);
20 })
21 ->with([
22 'xprofile' => function ($q) {
23 return $q->select(ProfileHelper::getXProfilePublicFields());
24 },
25 'subscriber' => function ($q) {
26 return $q->where('user_id', get_current_user_id());
27 }
28 ])
29 ->byStatus($request->get('status'), $user->ID)
30 ->byType($request->get('notification_type', 'all'))
31 ->orderBy('updated_at', 'DESC')
32 ->paginate();
33
34 $data = [
35 'notifications' => $notifications
36 ];
37 return apply_filters('fluent_community/notifications_api_response', $data, $request->all());
38 }
39
40 public function getUnreadNotifications(Request $request)
41 {
42 $user = $this->getUser(true);
43
44 $unreadNotifications = Notification::byStatus('unread', $user->ID)
45 ->with(['xprofile' => function ($q) {
46 return $q->select(ProfileHelper::getXProfilePublicFields());
47 }])
48 ->orderBy('updated_at', 'DESC')
49 ->byType($request->get('notification_type', 'all'))
50 ->limit(50)
51 ->get();
52
53 $data = [
54 'notifications' => $unreadNotifications,
55 'unread_count' => Notification::byStatus('unread', get_current_user_id())->count()
56 ];
57 return apply_filters('fluent_community/unread_notifications_api_response', $data, $request->all());
58 }
59
60 public function markAllRead(Request $request)
61 {
62 NotificationSubscriber::where('is_read', 0)
63 ->where('user_id', get_current_user_id())
64 ->update(['is_read' => 1]);
65
66 return [
67 'message' => __('All notifications have been marked as read.', 'fluent-community')
68 ];
69 }
70
71 public function markAsRead(Request $request, $notification_id)
72 {
73 $notification = Notification::findOrFail($notification_id);
74
75 NotificationSubscriber::whereHas('notification', function ($query) use ($notification) {
76 return $query->where('id', $notification->id)
77 ->orWhere('feed_id', $notification->feed_id);
78 })
79 ->where('user_id', get_current_user_id())
80 ->update(['is_read' => 1]);
81
82 return [
83 'unread_count' => Notification::byStatus('unread', get_current_user_id())->count()
84 ];
85 }
86
87 public function markAsReadByFeedId(Request $request, $feedId)
88 {
89 $feed = Feed::findOrfail($feedId);
90
91 NotificationSubscriber::whereHas('notification', function ($query) use ($feed) {
92 return $query->where('feed_id', $feed->id);
93 })
94 ->where('user_id', get_current_user_id())
95 ->update(['is_read' => 1]);
96
97 $userModel = $this->getUser();
98
99 return [
100 'unread_notification_count' => $userModel->getUnreadNotificationCount(),
101 'unread_feed_ids' => $userModel->getUnreadNotificationFeedIds(),
102 ];
103 }
104 }
105