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

148 lines 4.8 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 ];
82
83 //if no settings found of this user then store default
84 if(!$globalNotification) {
85 $meta = new Meta();
86 $meta->object_id = $userId;
87 $meta->object_type = Constant::OBJECT_TYPE_USER;
88 $meta->key = Constant::USER_GLOBAL_NOTIFICATIONS;
89 $meta->value = $newSettingsArray;
90 $meta->save();
91
92 return $meta;
93 }
94
95 return $globalNotification;
96 }
97
98 public function getDashboardViewSettings()
99 {
100 $userId = get_current_user_id();
101 $dshboardViewSettings = Meta::where('object_id', $userId)
102 ->where('object_type', Constant::OBJECT_TYPE_USER)
103 ->where('key', Constant::USER_DASHBOARD_VIEW)
104 ->first();
105
106 //if no settings found of this user then store default
107 if(!$dshboardViewSettings) {
108 //default notification settings
109 $newSettingsArray = [
110 'dashboard_view_label' => true,
111 'dashboard_view_priority' => true,
112 'dashboard_view_assignee' => true,
113 'dashboard_view_subtask' => true,
114 'dashboard_view_due_date' => true,
115 'dashboard_view_comment' => true
116 ];
117
118 $meta = new Meta();
119 $meta->object_id = $userId;
120 $meta->object_type = Constant::OBJECT_TYPE_USER;
121 $meta->key = Constant::USER_DASHBOARD_VIEW;
122 $meta->value = $newSettingsArray;
123 $meta->save();
124
125 return $meta;
126 }
127
128 return $dshboardViewSettings;
129 }
130 public function updateDashboardViewSettings($newSettings)
131 {
132 $userId = get_current_user_id();
133
134 $dshboardViewSettings = Meta::where('object_id', $userId)
135 ->where('object_type', Constant::OBJECT_TYPE_USER)
136 ->where('key', Constant::USER_DASHBOARD_VIEW)
137 ->first();
138
139 foreach ($newSettings as $index => $setting)
140 {
141 $newSettings[$index] = $setting == 'true' ? true : false;
142 }
143
144 $dshboardViewSettings->value = $newSettings;
145 $dshboardViewSettings->save();
146 }
147 }
148