PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.91.6
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.91.6
2.1.0 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 All 42 releases
fluent-boards / app / Http / Controllers / UserController.php

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

159 lines 5.0 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\Models\Board;
6 use FluentBoards\App\Models\User;
7 use FluentBoards\App\Services\Helper;
8 use FluentBoards\App\Services\PermissionManager;
9 use FluentBoards\App\Services\UserService;
10 use FluentBoards\Framework\Http\Request\Request;
11 use FluentCrm\App\Models\Subscriber;
12
13
14 class UserController extends Controller
15 {
16 private UserService $userService;
17
18 public function __construct(UserService $userService)
19 {
20 parent::__construct();
21 $this->userService = $userService;
22 }
23
24 public function allFluentBoardsUsers()
25 {
26 return [
27 'users' => $this->userService->allFluentBoardsUsers(),
28 'boards' => Board::select('id', 'title')->orderBy('title', 'ASC')->get()
29 ];
30 }
31
32 public function memberAssociatedTaskUsers($user_id)
33 {
34 $user_id = absint($user_id);
35 try {
36 $uniqueUsers = $this->userService->memberAssociatedTaskUsers($user_id);
37
38 return $this->sendSuccess([
39 'users' => $uniqueUsers['uniqueUsers'],
40 'userWiseBoardDesignation' => $uniqueUsers['userWiseBoardDesignation'],
41 ], 200);
42 } catch (\Exception $e) {
43 return $this->sendError($e->getMessage(), 404);
44 }
45 }
46
47 public function searchFluentBoardsUser(Request $request)
48 {
49 try {
50 $search_input = $request->getSafe('searchInput', 'sanitize_text_field', '');
51
52 $boardUsers = $this->userService->searchFluentBoardsUser($search_input);
53
54 return $this->sendSuccess($boardUsers, 200);
55 } catch (\Exception $e) {
56 return $this->sendError($e->getMessage(), 404);
57 }
58 }
59
60 public function searchMemberUser(Request $request, $user_id)
61 {
62 $user_id = absint($user_id);
63 try {
64 $search_input = $request->getSafe('searchInput', 'sanitize_text_field', '');
65 $searchResult = $this->userService->searchMemberUser($search_input, $user_id);
66
67 return $this->sendSuccess([
68 'users' => $searchResult,
69 ], 200);
70 } catch (\Exception $e) {
71 return $this->sendError($e->getMessage(), 404);
72 }
73 }
74
75 public function getMemberAssociatedTasks(Request $request, $user_id)
76 {
77 $user_id = absint($user_id);
78 // Sanitize boardIds array
79 $rawBoardIds = $request->getSafe('boardIds');
80 $boardIds = [];
81 if (is_array($rawBoardIds)) {
82 $boardIds = array_filter(array_map('intval', $rawBoardIds));
83 }
84
85 $requestData = [
86 'page' => $request->getSafe('page', 'intval', 1),
87 'taskType' => $request->getSafe('taskType', 'sanitize_text_field'),
88 'boardIds' => $boardIds,
89 'orderBy' => $request->getSafe('orderBy', 'sanitize_text_field'),
90 'order' => $request->getSafe('order', 'sanitize_text_field'),
91 ];
92 try {
93 return $this->sendSuccess(
94 $this->userService->getMemberAssociatedTasks($user_id, $requestData)
95 , 200);
96 } catch (\Exception $e) {
97 return $this->sendError($e->getMessage(), 404);
98 }
99 }
100
101 public function getMemberRelatedAcitivies(Request $request, $user_id)
102 {
103 $user_id = absint($user_id);
104 $page = $request->getSafe('page', 'intval', 1);
105 try {
106 return $this->sendSuccess(
107 $this->userService->getMemberRelatedAcitivies($user_id, $page)
108 , 200);
109 } catch (\Exception $e) {
110 return $this->sendError($e->getMessage(), 404);
111 }
112 }
113
114 public function getMemberInfo($user_id)
115 {
116 if(!PermissionManager::isFluentBoardsUser($user_id)) {
117 return $this->sendError(
118 [
119 'message' => __('You are not authorized to access this resource', 'fluent-boards'),
120 'code' => 'fluent_boards_unauthorized',
121 'status' => 403
122 ],
123 403
124 );
125 }
126
127 $user_id = absint($user_id);
128 $user = User::findOrFail($user_id);
129
130 $user = Helper::sanitizeUserCollections($user);
131
132 $user->fbs_role = PermissionManager::isFluentBoardsAdmin($user_id) ? 'fbs_admin' : 'member';
133
134 $user->is_wp_admin = user_can($user_id, 'manage_options') ? 'yes' : 'no';
135
136 if (defined('FLUENTCRM')) {
137 $subscriber = Subscriber::where('user_id', $user_id)->first();
138 $user->fluentcrm_subscriber = $subscriber ?? null;
139 }
140
141 return [
142 'user' => $user
143 ];
144 }
145
146 public function getMemberBoards($user_id)
147 {
148 $user_id = absint($user_id);
149 try {
150 return $this->sendSuccess(
151 [
152 'boards' => $this->userService->getMemberBoards($user_id)
153 ], 200);
154 } catch (\Exception $e) {
155 return $this->sendError($e->getMessage(), 404);
156 }
157 }
158 }
159