PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.95
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.95
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 / Services / OptionService.php

OptionService.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.95, at app/Services/OptionService.php

193 lines 6.4 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\Services;
4
5 use FluentBoards\App\Models\Board;
6 use FluentBoards\App\Models\Meta;
7 use FluentBoards\App\Models\Relation;
8
9 class OptionService
10 {
11 public function createSuperAdmin($userId)
12 {
13 $existUser = $this->searchUserMeta($userId);
14 if (!$existUser) {
15 $meta = new Meta();
16 $meta->object_id = $userId;
17 $meta->object_type = Constant::OBJECT_TYPE_USER;
18 $meta->key = Constant::FLUENT_BOARD_ADMIN;
19 $meta->save();
20 }
21 }
22
23 public function removeUserSuperAdmin($userId)
24 {
25 $existUser = $this->searchUserMeta($userId);
26 if ($existUser) {
27 $existUser->delete();
28 }
29 }
30
31 private function searchUserMeta($userId)
32 {
33 return Meta::query()->where('object_id', $userId)
34 ->where('object_type', Constant::OBJECT_TYPE_USER)
35 ->where('key', Constant::FLUENT_BOARD_ADMIN)
36 ->first();
37 }
38
39 public function updateGlobalNotificationSettings($newSettings)
40 {
41 $userId = get_current_user_id();
42
43 $globalNotification = Meta::where('object_id', $userId)
44 ->where('object_type', Constant::OBJECT_TYPE_USER)
45 ->where('key', Constant::USER_GLOBAL_NOTIFICATIONS)
46 ->first();
47
48 foreach ($newSettings as $index => $setting)
49 {
50 $newSettings[$index] = $setting == 'true' ? true : false;
51 }
52
53 $globalNotification->value = $newSettings;
54 $globalNotification->save();
55
56 //set this settings to all board
57 $relatedBoardsQuery = Board::where('type', 'to-do')->byAccessUser($userId)->get();
58 $notificationService = new NotificationService();
59 foreach ($relatedBoardsQuery as $board)
60 {
61 $notificationService->updateBoardNotificationSettings($newSettings, $board->id);
62 }
63 }
64
65 public function getGlobalNotificationSettings()
66 {
67 $userId = get_current_user_id();
68 $globalNotification = Meta::where('object_id', $userId)
69 ->where('object_type', Constant::OBJECT_TYPE_USER)
70 ->where('key', Constant::USER_GLOBAL_NOTIFICATIONS)
71 ->first();
72
73 //default notification settings
74 $newSettingsArray = [
75 Constant::GLOBAL_EMAIL_NOTIFICATION_COMMENT => true,
76 Constant::GLOBAL_EMAIL_NOTIFICATION_STAGE_CHANGE => true,
77 Constant::GLOBAL_EMAIL_NOTIFICATION_TASK_ASSIGN => true,
78 Constant::GLOBAL_EMAIL_NOTIFICATION_DUE_DATE => true,
79 Constant::GLOBAL_EMAIL_NOTIFICATION_REMOVE_FROM_TASK => true,
80 Constant::GLOBAL_EMAIL_NOTIFICATION_TASK_ARCHIVE => true,
81 Constant::GLOBAL_EMAIL_NOTIFICATION_CREATING_TASK => true,
82 Constant::GLOBAL_EMAIL_NOTIFICATION_COMMENTING => true,
83 Constant::GLOBAL_EMAIL_NOTIFICATION_ASSIGNING => true
84 ];
85
86 //if no settings found of this user then store default
87 if(!$globalNotification) {
88 $meta = new Meta();
89 $meta->object_id = $userId;
90 $meta->object_type = Constant::OBJECT_TYPE_USER;
91 $meta->key = Constant::USER_GLOBAL_NOTIFICATIONS;
92 $meta->value = $newSettingsArray;
93 $meta->save();
94
95 return $meta;
96 }
97
98 return $globalNotification;
99 }
100
101 public function getDashboardViewSettings()
102 {
103 $userId = get_current_user_id();
104 $dshboardViewSettings = Meta::where('object_id', $userId)
105 ->where('object_type', Constant::OBJECT_TYPE_USER)
106 ->where('key', Constant::USER_DASHBOARD_VIEW)
107 ->first();
108
109 //if no settings found of this user then store default
110 if(!$dshboardViewSettings) {
111 $meta = new Meta();
112 $meta->object_id = $userId;
113 $meta->object_type = Constant::OBJECT_TYPE_USER;
114 $meta->key = Constant::USER_DASHBOARD_VIEW;
115 $meta->value = Constant::DEFAULT_DASHBOARD_VIEW_PREFERENCES;
116 $meta->save();
117
118 return $meta;
119 }
120
121 return $dshboardViewSettings;
122 }
123
124 public function getListViewPreferences()
125 {
126 $userId = get_current_user_id();
127 $dshboardViewSettings = Meta::where('object_id', $userId)
128 ->where('object_type', Constant::OBJECT_TYPE_USER)
129 ->where('key', Constant::USER_LISTVIEW_PREFERENCES)
130 ->first();
131 //if no settings found of this user then store default
132 if(!$dshboardViewSettings) {
133 $meta = new Meta();
134 $meta->object_id = $userId;
135 $meta->object_type = Constant::OBJECT_TYPE_USER;
136 $meta->key = Constant::USER_LISTVIEW_PREFERENCES;
137 $meta->value = Constant::DEFAULT_DASHBOARD_VIEW_PREFERENCES;
138 $meta->save();
139
140 return $meta;
141 }
142
143 return $dshboardViewSettings;
144 }
145 public function updateDashboardViewSettings($newSettings, $view)
146 {
147 $userId = get_current_user_id();
148
149 if ($view == 'listview') {
150 $viewWiseKey = Constant::USER_LISTVIEW_PREFERENCES;
151 } elseif ($view == 'tableview') {
152 $viewWiseKey = Constant::USER_TABLEVIEW_PREFERENCES;
153 } else {
154 $viewWiseKey = Constant::USER_DASHBOARD_VIEW;
155 }
156
157 $dshboardViewSettings = Meta::where('object_id', $userId)
158 ->where('object_type', Constant::OBJECT_TYPE_USER)
159 ->where('key', $viewWiseKey)
160 ->first();
161
162 foreach ($newSettings as $index => $setting)
163 {
164 $newSettings[$index] = $setting == 'true' ? true : false;
165 }
166
167 $dshboardViewSettings->value = $newSettings;
168 $dshboardViewSettings->save();
169 }
170
171 // Add this new method
172 public function getTableViewPreferences()
173 {
174 $userId = get_current_user_id();
175 $tableViewSettings = Meta::where('object_id', $userId)
176 ->where('object_type', Constant::OBJECT_TYPE_USER)
177 ->where('key', Constant::USER_TABLEVIEW_PREFERENCES)
178 ->first();
179 if (!$tableViewSettings) {
180 $meta = new Meta();
181 $meta->object_id = $userId;
182 $meta->object_type = Constant::OBJECT_TYPE_USER;
183 $meta->key = Constant::USER_TABLEVIEW_PREFERENCES;
184 $meta->value = Constant::DEFAULT_TABLEVIEW_VIEW_PREFERENCES;
185 $meta->save();
186
187 return $meta;
188 }
189
190 return $tableViewSettings;
191 }
192 }
193