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 / ActivityHandler.php

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

332 lines 11.5 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 FluentBoards\App\Models\Board;
6 use FluentBoards\App\Models\Stage;
7 use FluentBoards\App\Models\Task;
8 use FluentBoards\App\Models\User;
9 use FluentBoards\App\Services\Constant;
10 use FluentCrm\App\Models\Subscriber;
11 use FluentBoards\App\Models\Comment;
12 use FluentBoards\App\Services\Helper;
13
14 class ActivityHandler
15 {
16 public function createLogActivity($taskId, $action, $column, $oldValue = null, $newValue = null, $description = null, $settings = null )
17 {
18 $data = [
19 'object_type' => Constant::ACTIVITY_TASK,
20 'object_id' => $taskId,
21 'action' => $action, // action type: changed, updated, added, removed
22 'column' => $column,
23 'old_value' => $oldValue,
24 'new_value' => $newValue,
25 'description' => $description,
26 'settings' => $settings
27 ];
28 $userId = get_current_user_id();
29 if($userId == 0){
30 $task = Task::find($taskId);
31 $data['created_by'] = $task->created_by;
32 }
33
34 Helper::createActivity($data);
35 }
36 public function logMoveTaskToAnotherBoardActivity($task, $oldTask)
37 {
38 $old = $this->getBoardTitleById($oldTask->board_id);
39 $new = $this->getBoardTitleById($task->board_id);
40 $this->createLogActivity( $task->id,'changed', 'board', $old, $new);
41 }
42
43 public function logAssigneeAddedActivity($task, $newAssigneeId)
44 {
45 $currentUserId = get_current_user_id();
46 if($newAssigneeId == $currentUserId) {
47 $this->taskAssigneeJoin($task->id);
48 return;
49 }
50 $user = User::findOrFail($newAssigneeId);
51 $currentUserId = get_current_user_id();
52 if($currentUserId === $user->ID){
53 $this->taskAssigneeJoin($task->id);
54 } elseif ($user) {
55 $this->createLogActivity($task->id, 'added', 'assignee', null, $user->display_name);
56 }
57 }
58
59 public function logAssigneeRemovedActivity($task, $newAssigneeId)
60 {
61 $currentUserId = get_current_user_id();
62 if($newAssigneeId == $currentUserId) {
63 $this->taskAssigneeLeave($task->id);
64 return;
65 }
66 $user = User::findOrFail($newAssigneeId);
67 $currentUserId = get_current_user_id();
68 if($currentUserId === $user->ID){
69 $this->taskAssigneeLeave($task->id);
70 } else if($user) {
71 $this->createLogActivity($task->id, 'removed', 'assignee', null, $user->display_name);
72 }
73 }
74
75 public function logTaskCreationActivity($task)
76 {
77 $this->createLogActivity( $task->id,'created', 'task', null, $task->title, null );
78 }
79
80 public function logTaskContentUpdatedActivity($task, $col, $oldTask = null)
81 {
82 $action = 'updated';
83 if($col == 'description'){
84 $this->createLogActivity( $task->id, $action, $col, $oldTask->description, $task->description );
85 }else{
86 if($task->parent_id){
87 $this->createLogActivity( $task->parent_id, $action, 'subtask', $oldTask->title, $task->title );
88 }else{
89 $this->createLogActivity( $task->id, $action, $col, $oldTask->title, $task->title );
90 }
91 }
92 }
93
94 public function taskLabelActivity($task, $label, $action)
95 {
96 $column = 'label';
97 $settings = [
98 'bg_color' => $label->bg_color,
99 'color' => $label->color,
100 'title' => $label->title,
101 ];
102
103 $this->createLogActivity($task->id, $action, $column, null, null, null, $settings);
104 }
105
106 public function logDueDateActivity($task, $oldDate)
107 {
108 $column = 'Due Date';
109 $action = 'changed';
110
111 if($oldDate){
112 $new = gmdate("F j, Y, g:i a", strtotime($task->due_at));
113 $old = gmdate("F j, Y, g:i a", strtotime($oldDate));
114 if($new == $old)
115 return;
116 }
117 $newDueDate = $task->due_at;
118 $new = null;
119 if ($newDueDate) {
120 $new = gmdate("F j, Y, g:i a", strtotime($newDueDate));
121 if(str_contains($new, '12:00 am')){
122 $new = gmdate("F j, Y", strtotime($newDueDate));
123 }
124 }
125 $old = null;
126 if(!$oldDate){
127 $action = 'added';
128 }else{
129 $old = gmdate("F j, Y, g:i a", strtotime($oldDate));
130 if(str_contains($old, '12:00 am')){
131 $old = gmdate("F j, Y", strtotime($oldDate));
132 }
133 }
134
135 $this->createLogActivity($task->id, $action, $column, $old, $new);
136 }
137
138 public function logStartDateActivity($task, $oldDate)
139 {
140 $column = 'Start Date';
141 $action = 'changed';
142
143 if($oldDate){
144 $new = gmdate("F j, Y", strtotime($task->started_at));
145 $old = gmdate("F j, Y", strtotime($oldDate));
146 if($new == $old)
147 return;
148 }
149 $newStartDate = $task->started_at;
150 $new = null;
151 if ($newStartDate) {
152 $new = gmdate("F j, Y", strtotime($newStartDate));
153 }
154 $old = null;
155 if(!$oldDate){
156 $action = 'added';
157 }else{
158 $old = gmdate("F j, Y", strtotime($oldDate));
159 }
160
161 $this->createLogActivity($task->id, $action, $column, $old, $new);
162 }
163
164
165 public function logPriorityChangeActivity($task, $old)
166 {
167 $new = $task->priority;
168 $this->createLogActivity($task->id, 'changed', 'priority', $old, $new);
169 }
170
171 public function logCommentCreateActivity($comment)
172 {
173 if($comment->parent_id) {
174 // dd($comment);
175 $parent = Comment::findOrFail($comment->parent_id);
176 $parentDescription = $parent->description;
177 $this->createLogActivity($comment->task_id, 'added', 'a reply');
178 }else{
179 $commentPlainText = strip_tags($comment->description);
180 $this->createLogActivity($comment->task_id, 'added', 'comment', null, $commentPlainText, null);
181 }
182 }
183 public function logCommentUpdateActivity($comment, $oldComment)
184 {
185 $taskId = $comment->task_id;
186 $newComment = $comment->settings['raw_description'] ?? $comment->description;
187
188 $this->createLogActivity($taskId, 'updated', 'comment', $oldComment, $newComment);
189 }
190 public function logCommentDeleteActivity($comment)
191 {
192 $commentDescription = strip_tags($comment->settings['raw_description'] ?? $comment->description );
193 $taskId = $comment->task_id;
194
195 $this->createLogActivity($taskId, 'removed', 'comment', null, $commentDescription, null);
196 }
197
198 public function logSubtaskAddedActivity($parentTask, $subTask)
199 {
200 $this->createLogActivity($parentTask->id, 'added', 'subtask', null, $subTask->title);
201 }
202
203 public function logSubtaskDeletedActivity($id, $subTaskTitle)
204 {
205 $this->createLogActivity($id, 'removed', 'subtask', null, $subTaskTitle);
206 }
207
208 public function logTaskCompletedOrReopenActivity($task, $status)
209 {
210 if($status == 'completed'){
211 if($task->parent_id){
212 $this->createLogActivity($task->parent_id, 'completed', 'subtask', $task->title);
213 }else{
214 $this->createLogActivity($task->id, 'completed', 'task', $task->title);
215 }
216 }else{
217 if($task->parent_id){
218 $this->createLogActivity($task->parent_id, 'reopened', 'subtask', $task->title);
219 }else{
220 $this->createLogActivity($task->id, 'reopened', 'task', $task->title);
221 }
222 }
223 }
224
225 public function logTaskStageUpdatedActivity($task, $oldStageId)
226 {
227 $oldStage = Stage::findOrFail($oldStageId);
228 $newStage = Stage::findOrFail($task->stage_id);
229 if($oldStage && $newStage){
230 $this->createLogActivity($task->id, 'changed', 'stage', $oldStage->title, $newStage->title);
231 }
232 }
233
234 public function associateUserAddChangeRemoveActivity($oldAssociateId, $newAssociateId, $taskId)
235 {
236 $subsciber = new Subscriber();
237 $oldAssociateUser = $subsciber->find($oldAssociateId);
238 $newAssociateUser = $subsciber->find($newAssociateId);
239 $action = 'added';
240 $column = 'the associate email';
241 $old = null; $new = null;
242
243 if ($oldAssociateUser && $newAssociateUser) {
244 $old = $oldAssociateUser->email;
245 $new = $newAssociateUser->email;
246 $action = 'changed';
247 } elseif ($oldAssociateUser && !$newAssociateUser) {
248 $old = $oldAssociateUser->email;
249 $action = 'removed';
250 } else {
251 $new = $newAssociateUser->email;
252 }
253 $this->createLogActivity($taskId, $action, $column, $old, $new);
254 }
255
256 public function taskAssigneeJoin($id)
257 {
258 $this->createLogActivity($id, 'joined', 'task', null, null);
259 }
260
261 public function taskAssigneeLeave($id)
262 {
263 $this->createLogActivity($id, 'left', 'task', null, null);
264 }
265
266 public function labelManageForTaskActivity($id, $action)
267 {
268 $this->createLogActivity($id, $action, 'label', null, null);
269 }
270
271 private function getBoardTitleById($boardId)
272 {
273 return Board::findOrFail($boardId)->title; // it can be further optimized , we may limit multiple query here.
274 }
275
276 public function taskAddedFromFluentForms($task)
277 {
278 $taskActivity = [
279 'object_type' => Constant::ACTIVITY_TASK,
280 'object_id' => $task->id,
281 'action' => 'created', // action type: changed, updated, added, removed
282 'column' => 'task',
283 'old_value' => $task->title,
284 'new_value' => null,
285 'description' => " from Fluent Forms",
286 ];
287
288 $board = Board::find($task->board_id);
289 $settings = $board->settings ?? [];
290
291 if (isset($settings['tasks_count'])) {
292 if ($settings['tasks_count'] != 0) $settings['tasks_count'] += 1;
293 } else {
294 $settings['tasks_count'] = 1;
295 }
296 $board->settings = $settings;
297 $board->save();
298 $taskStage = $task->stage;
299 $settings = ['task_id' => $task->id];
300
301 $boardActivity = [
302 'object_type' => Constant::ACTIVITY_BOARD,
303 'object_id' => $task->board_id,
304 'action' => 'created', // action type: changed, updated, added, removed, created
305 'column' => 'task',
306 'old_value' => null,
307 'new_value' => $task->title,
308 'description' => 'on stage '. $taskStage->title . ' from Fluent Forms ',
309 'settings' => $settings
310 ];
311 if (intval($task->created_by) > 0) {
312 $taskActivity['created_by'] = intval($task->created_by);
313 $boardActivity['created_by'] = intval($task->created_by);
314
315 } else {
316 $taskActivity['description'] .= ' by '. $task['settings']['author']['name'] . " (" . $task['settings']['author']['email'] . ")";
317 $boardActivity['description'] .= ' by '. $task['settings']['author']['name'] . " (" . $task['settings']['author']['email'] . ")";
318 }
319 Helper::createActivity($taskActivity);
320 Helper::createActivity($boardActivity);
321
322 }
323 public function taskAttachmentAdded($attachment)
324 {
325 $this->createLogActivity($attachment->object_id , 'added', 'attachment', null, strlen($attachment->title) > 0 ? $attachment->title : $attachment->full_url);
326 }
327 public function taskAttachmentDeleted($attachment)
328 {
329 $this->createLogActivity($attachment->object_id , 'deleted', 'attachment', null, strlen($attachment->title) > 0 ? $attachment->title : $attachment->full_url);
330 }
331 }
332