PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 1.21
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v1.21
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.21, at app/Hooks/Handlers/ActivityHandler.php

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