PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 1.0.90
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v1.0.90
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 1.1.0 All 77 releases
fluent-community / app / Http / Controllers / NotificationsController.php

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

105 lines 3.4 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 $notifcations = 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 return [
35 'notifications' => $notifcations
36 ];
37 }
38
39 public function getUnreadNotifications(Request $request)
40 {
41 $user = $this->getUser(true);
42
43 $unreadNotifications = Notification::byStatus('unread', $user->ID)
44 ->with(['xprofile' => function ($q) {
45 return $q->select(ProfileHelper::getXProfilePublicFields());
46 }])
47 ->orderBy('updated_at', 'DESC')
48 ->byType($request->get('notification_type', 'all'))
49 ->limit(50)
50 ->get();
51
52 return [
53 'notifications' => $unreadNotifications,
54 'unread_count' => Notification::byStatus('unread', get_current_user_id())->count()
55 ];
56 }
57
58 public function markAllRead(Request $request)
59 {
60 NotificationSubscriber::where('is_read', 0)
61 ->where('user_id', get_current_user_id())
62 ->update(['is_read' => 1]);
63
64 return [
65 'message' => __('All notifications has been marked as read.', 'fluent-community')
66 ];
67 }
68
69 public function markAsRead(Request $request, $notification_id)
70 {
71 $notification = Notification::find($notification_id);
72
73 NotificationSubscriber::whereHas('notification', function ($query) use ($notification) {
74 return $query->where('id', $notification->id)
75 ->orWhere('feed_id', $notification->feed_id);
76 })
77 ->where('user_id', get_current_user_id())
78 ->update(['is_read' => 1]);
79
80 return [
81 'unread_count' => Notification::byStatus('unread', get_current_user_id())->count()
82 ];
83
84 return $this->getUnreadNotifications($request);
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