PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.45
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.45
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 / Hooks / Handlers / TaskHandler.php

TaskHandler.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 1.45, at app/Hooks/Handlers/TaskHandler.php

224 lines 7.2 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\Hooks\Handlers;
4
5 use DateTimeImmutable;
6 use Exception;
7 use FluentBoards\App\Models\Activity;
8 use FluentBoards\App\Models\Meta;
9 use FluentBoards\App\Models\User;
10 use FluentBoards\App\Services\Constant;
11 use FluentBoards\App\Services\OptionService;
12 use FluentCrm\App\Models\Subscriber;
13 use FluentBoards\App\Models\Relation;
14 use FluentCrm\App\Services\ContactsQuery;
15 use FluentCrm\App\Services\PermissionManager as CRMPermissionManager;
16
17 class TaskHandler
18 {
19 private $fileHandler;
20
21 public function __construct(FileHandler $fileHandler)
22 {
23 $this->fileHandler = $fileHandler;
24 }
25 public function taskDeleted($task)
26 {
27 // Delete all activities and comments related to this task
28 Activity::where('object_id', $task->id)->where('object_type', Constant::ACTIVITY_TASK)->delete();
29 Meta::where('object_id', $task->id)->where('object_type', Constant::REPEAT_TASK_META)->delete();
30 }
31
32 public function searchAssignees($options, $search, $includedIds)
33 {
34 $users = get_users([
35 'number' => 20,
36 'search' => $search,
37 ]);
38
39 $formattedUsers = [];
40
41 $pushedIds = [];
42
43 foreach ($users as $user) {
44 $pushedIds[] = $user->ID;
45
46 $formattedUsers[] = [
47 'id' => $user->ID,
48 'title' => $user->display_name . ' (' . $user->user_email . ')',
49 'photo' => get_avatar_url($user->user_email),
50 'left_side_value' => $user->display_name,
51 'right_side_value' => $user->user_email,
52 ];
53 }
54
55 return $formattedUsers;
56
57 if (!$includedIds) {
58 return $formattedUsers;
59 }
60 if (!is_array($includedIds)) {
61 // $includedIds = [$includedIds];
62 $includedIds = [$includedIds];
63 }
64
65 // $includedIds = array_diff($includedIds, $pushedIds);
66 //
67 if ($includedIds) {
68 $users = get_users([
69 'include' => $includedIds,
70 ]);
71
72 foreach ($users as $user) {
73 $formattedUsers[] = [
74 'id3' => $user->ID,
75 'title' => $user->display_name . ' (' . $user->user_email . ')',
76 'photo_' => /* get photo by gravitar or something */ get_avatar_url($user->user_email, ['size' => 50]),
77 'left_side_value' => $user->display_name,
78 'right_side_value' => $user->user_email,
79 'right_side_value1' => $user->user_email,
80 ];
81 }
82 }
83 // dd($formattedUsers);
84
85 return $formattedUsers;
86 }
87
88 public function searchNonBoardWordpressUsers()
89 {
90 $superAdmin = Relation::select('user_id')->distinct()->pluck('user_id');
91 $users = User::whereDoesntHave('boards')->whereNotIn('ID', $superAdmin)->get();
92
93 $formattedUsers = [];
94
95 foreach ($users as $user) {
96 $formattedUsers[] = [
97 'id' => $user->ID,
98 'photo' => $user->photo,
99 'title' => $user->display_name . ' (' . $user->user_email . ')',
100 'left_side_value' => $user->display_name,
101 'right_side_value' => $user->user_email,
102 ];
103 }
104
105 return $formattedUsers;
106 }
107
108 public function searchContact($options, $search, $includedIds)
109 {
110 if (!defined('FLUENTCRM')) {
111 return [];
112 }
113
114 // check if the use has permission to access contacts
115 $contactPermission = CRMPermissionManager::currentUserCan('fcrm_read_contacts');
116 if(!$contactPermission) {
117 return [];
118 }
119
120 $contactsQuery = new ContactsQuery([
121 'search' => $search,
122 'with' => [],
123 'limit' => 20,
124 'offset' => 0,
125 ]);
126 $subscribers = $contactsQuery->get();
127
128 $formattedSubscribers = [];
129
130 $pushedIs = [];
131 foreach ($subscribers as $subscriber) {
132 $pushedIs[] = $subscriber->id;
133 $formattedSubscribers[] = [
134 'id' => $subscriber->id,
135 'title' => $subscriber->full_name . ' (' . $subscriber->email . ')',
136 'photo' => $subscriber->photo,
137 'name' => $subscriber->full_name,
138 'email' => $subscriber->email,
139 ];
140 }
141
142 if (!is_array($includedIds)) {
143 $includedIds = [$includedIds];
144 }
145
146 if (!$includedIds) {
147 return $formattedSubscribers;
148 }
149
150 $remainingIds = array_diff($includedIds, $pushedIs);
151
152 if ($remainingIds) {
153 $remainingContacts = Subscriber::whereIn('id', $remainingIds)->get();
154 foreach ($remainingContacts as $subscriber) {
155 $formattedSubscribers[] = [
156 'id' => $subscriber->id,
157 'title' => $subscriber->full_name . ' (' . $subscriber->email . ')',
158 'photo' => $subscriber->photo,
159 'name' => $subscriber->full_name,
160 'email' => $subscriber->email,
161 ];
162 }
163 }
164
165 return $formattedSubscribers;
166 }
167
168
169
170 /**
171 * Summary of taskAttachmentDeleted
172 * @param mixed $task
173 * @param mixed $deleteUrl
174 * @return void
175 */
176 public function taskAttachmentDeleted($deletedAttachment)
177 {
178 try {
179 $deleteUrl = $deletedAttachment->full_url;
180 $this->fileHandler->deleteFileByUrl($deleteUrl);
181 } catch (Exception $e) {
182 wp_send_json_error($e->getMessage());
183 }
184 }
185
186 public function onTaskCreated($task)
187 {
188 $currentSettings = $this->getGlobalNotificationSettings();
189 $shouldWatch = isset($currentSettings['watch_on_creating_task']) && $currentSettings['watch_on_creating_task'];
190
191 if ($shouldWatch) {
192 $task->watchers()->syncWithoutDetaching([get_current_user_id() => ['object_type' => Constant::OBJECT_TYPE_USER_TASK_WATCH]]);
193 }
194 }
195
196 public function onCommentCreated($comment)
197 {
198 $task = $comment->task;
199 $currentSettings = $this->getGlobalNotificationSettings();
200 $shouldWatch = isset($currentSettings['watch_on_commenting']) && $currentSettings['watch_on_commenting'];
201
202 if ($shouldWatch) {
203 $task->watchers()->syncWithoutDetaching([get_current_user_id() => ['object_type' => Constant::OBJECT_TYPE_USER_TASK_WATCH]]);
204 }
205 }
206
207 public function onAssignAnotherUser($task, $assigneeId)
208 {
209 $currentSettings = $this->getGlobalNotificationSettings();
210 $shouldWatch = isset($currentSettings['watch_on_assigning']) && $currentSettings['watch_on_assigning'];
211
212 if ($shouldWatch) {
213 $task->watchers()->syncWithoutDetaching([$assigneeId => ['object_type' => Constant::OBJECT_TYPE_USER_TASK_WATCH]]);
214 }
215 }
216
217 private function getGlobalNotificationSettings()
218 {
219 $globalSettings = (new OptionService())->getGlobalNotificationSettings();
220
221 return maybe_unserialize($globalSettings->value);
222 }
223 }
224