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 / Hooks / Handlers / TaskHandler.php

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

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