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

149 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 'dashboard_view_notification' => true
117 ];
118
119 $meta = new Meta();
120 $meta->object_id = $userId;
121 $meta->object_type = Constant::OBJECT_TYPE_USER;
122 $meta->key = Constant::USER_DASHBOARD_VIEW;
123 $meta->value = $newSettingsArray;
124 $meta->save();
125
126 return $meta;
127 }
128
129 return $dshboardViewSettings;
130 }
131 public function updateDashboardViewSettings($newSettings)
132 {
133 $userId = get_current_user_id();
134
135 $dshboardViewSettings = Meta::where('object_id', $userId)
136 ->where('object_type', Constant::OBJECT_TYPE_USER)
137 ->where('key', Constant::USER_DASHBOARD_VIEW)
138 ->first();
139
140 foreach ($newSettings as $index => $setting)
141 {
142 $newSettings[$index] = $setting == 'true' ? true : false;
143 }
144
145 $dshboardViewSettings->value = $newSettings;
146 $dshboardViewSettings->save();
147 }
148 }
149