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.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.35, at app/Hooks/Handlers/ActivityHandler.php

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