PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.95.2
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.95.2
2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 1.45 All 41 releases
fluent-boards / app / Http / Controllers / NotificationController.php

NotificationController.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.95.2, at app/Http/Controllers/NotificationController.php

123 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Http\Controllers;
4
5 use FluentBoards\App\Services\NotificationService;
6 use FluentBoards\Framework\Http\Request\Request;
7
8 class NotificationController extends Controller
9 {
10 private $notificationService;
11
12 public function __construct(NotificationService $notificationService)
13 {
14 parent::__construct();
15 $this->notificationService = $notificationService;
16 }
17 public function getAllNotifications(Request $request)
18 {
19 try {
20 $per_page = $request->getSafe('per_page', 'intval', 20);
21 $page = $request->getSafe('page', 'intval', 1);
22 $action = $request->getSafe('action', 'sanitize_text_field', 'all');
23 $data = $this->notificationService->getAllNotifications($per_page, $page, $action);
24
25 return $this->sendSuccess($data, 200);
26 } catch (\Exception $e) {
27 return $this->sendError($e->getMessage(), 400);
28 }
29 }
30 public function getAllUnreadNotifications(Request $request)
31 {
32 try {
33 $per_page = $request->getSafe('per_page', 'intval', 20);
34 $page = $request->getSafe('page', 'intval', 1);
35 return $this->sendSuccess(
36 $this->notificationService->getAllUnreadNotifications($per_page, $page),
37 200);
38 } catch (\Exception $e) {
39 return $this->sendError($e->getMessage(), 400);
40 }
41 }
42
43 public function newNotificationNumber()
44 {
45 try {
46 $unread_notifications = $this->notificationService->newNotificationNumber();
47
48 return $this->sendSuccess([
49 'total_unread' => $unread_notifications,
50 ], 200);
51 } catch (\Exception $e) {
52 return $this->sendError($e->getMessage(), 400);
53 }
54 }
55
56 public function getBoardNotificationSettings($board_id)
57 {
58 $board_id = absint($board_id);
59 try {
60 $userId = get_current_user_id();
61 $currentSettings = [];
62 $boardSettings = $this->notificationService->getBoardNotificationSettingsOfUser($board_id, $userId);
63 if ($boardSettings && $boardSettings->preferences) {
64 $unserializedData = maybe_unserialize($boardSettings->preferences);
65 // Validate unserialized data is an array
66 if (is_array($unserializedData)) {
67 $currentSettings = $unserializedData;
68 }
69 }
70
71 return $this->sendSuccess([
72 'currentSettings' => $currentSettings,
73 ], 200);
74 } catch (\Exception $e) {
75 return $this->sendError($e->getMessage(), 400);
76 }
77 }
78
79 public function updateBoardNotificationSettings(Request $request, $board_id)
80 {
81 $board_id = absint($board_id);
82 try {
83 // updatedSettings is an array, sanitize each element
84 $rawSettings = $request->getSafe('updatedSettings');
85 $newSettings = [];
86 if (is_array($rawSettings)) {
87 foreach ($rawSettings as $key => $value) {
88 // Sanitize key and value
89 $sanitizedKey = sanitize_text_field($key);
90 $sanitizedValue = sanitize_text_field($value);
91 $newSettings[$sanitizedKey] = $sanitizedValue;
92 }
93 }
94 $this->notificationService->updateBoardNotificationSettings($newSettings, $board_id);
95 return $this->sendSuccess([
96 'message' => __('Board notification settings have been updated', 'fluent-boards'),
97 ], 200);
98 } catch (\Exception $e) {
99 return $this->sendError($e->getMessage(), 400);
100 }
101 }
102
103 public function readNotification(Request $request)
104 {
105 try {
106 $notificationId = $request->getSafe('notification_id', 'intval');
107
108 if ($notificationId) {
109 $notification = $this->notificationService->markNotificationRead($notificationId);
110 } else {
111 $notification = $this->notificationService->markAllRead();
112 }
113
114 return $this->sendSuccess([
115 'message' => __('Notification is updated', 'fluent-boards'),
116 'notification' => $notification
117 ], 200);
118
119 } catch (\Exception $e) {
120 return $this->sendError($e->getMessage(), 400);
121 }
122 }
123 }