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

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