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

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

174 lines 7.1 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\Task;
6 use FluentBoards\App\Models\User;
7 use FluentBoards\App\Models\Board;
8 use FluentBoards\App\Models\Notification;
9 use FluentBoards\App\Services\Constant;
10
11 class NotificationHandler
12 {
13 public function addCommentNotification($comment)
14 {
15 if($comment->task_id){
16 $task = Task::findOrFail($comment->task_id);
17 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
18 if(count($userIdsWhoGetNotification) > 0){
19 $plainDescription = strip_tags($comment->description);
20 $action = $comment->parent_id ? 'task_reply_added' : 'task_comment_added';
21 $message = $plainDescription;
22 $settings = [ 'comment_id' => $comment->parent_id ?? $comment->id ];
23 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message, $settings);
24 $notification->users()->attach($userIdsWhoGetNotification);
25 }
26 }
27 }
28
29 public function mentionInCommentNotification($id, $comment_by, $mentionIds)
30 {
31 $commenter_name = User::where('id', $comment_by)->first()->display_name;
32 $task_title = Task::findOrFail($id)->title;
33 $board_id = Task::findOrFail($id)->board_id;
34 $message = $commenter_name . ' mentioned you in a comment.';
35
36 foreach ($mentionIds as $id) {
37 if ($id != $comment_by) {
38 Notification::create([
39 'user_id' => (int) $id,
40 'board_id' => (int) $board_id,
41 'activity_by' => (int) $comment_by,
42 'activity_type' => 'mention',
43 'description' => $message,
44 ]);
45 }
46 }
47 }
48
49 public function addSubtaskNotification($parentTask, $subTask)
50 {
51 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($parentTask);
52 if(count($userIdsWhoGetNotification) > 0){
53 $board_id = $subTask->board_id;
54 $action = 'subtask_added';
55 $message = $subTask->title ;
56 $notification = $this->createNotification($parentTask, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
57 $notification->users()->attach($userIdsWhoGetNotification);
58 }
59 }
60
61 public function changeDateNotification($task, $oldDate)
62 {
63 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
64 if(count($userIdsWhoGetNotification) > 0){
65 $action = 'task_date_changed';
66 $message = date_i18n('F j, Y, g:i a', strtotime($task->due_at));
67 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
68 $notification->users()->attach($userIdsWhoGetNotification);
69 }
70 }
71
72 public function changeStageNotification($task, $oldStageId)
73 {
74 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
75 if(count($userIdsWhoGetNotification) > 0){
76 $action = 'task_moved_to_new_stage';
77 $message = $task->stage->title;
78 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
79 $notification->users()->attach($userIdsWhoGetNotification);
80 }
81 }
82
83 public function changePriorityNotification($task, $oldPriority)
84 {
85 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
86 if(count($userIdsWhoGetNotification) > 0){
87 $action = 'task_priority_changed';
88 $message = $task->priority;
89 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
90 $notification->users()->attach($userIdsWhoGetNotification);
91 }
92 }
93
94 public function taskArchiveNotification($task)
95 {
96 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
97 if(count($userIdsWhoGetNotification) > 0){
98 if ($task->archived_at) {
99 $action = 'board_task_archived';
100 $message = $task->title;
101 } else {
102 $action = 'board_task_restored';
103 $message = $task->title;
104 }
105 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
106 $notification->users()->attach($userIdsWhoGetNotification);
107 }
108 }
109
110 public function changeTitleOrDescriptionNotification($task, $col, $oldTask)
111 {
112 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
113 if(count($userIdsWhoGetNotification) > 0){
114 if($col == 'title'){
115 $action = 'task_title_updated';
116 $message = $task->title;
117 }else{
118 $action = 'task_description_updated';
119 $message = $task->description;
120 }
121 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
122 $notification->users()->attach($userIdsWhoGetNotification);
123 }
124 }
125
126 public function changeBoardNotification($task, $oldBoardId)
127 {
128 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
129 if(count($userIdsWhoGetNotification) > 0){
130 $new_board_id = Task::findOrFail($task->board_id)->board_id;
131 $new_board_title = Board::findOrFail($new_board_id)->title;
132 $message = 'moved "' . $task->title . '" task to "' . $new_board_title . '" board.';
133 $notification = $this->createNotification($oldBoardId, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $message);
134 $notification->users()->attach($userIdsWhoGetNotification);
135 }
136 }
137
138 public function assigneeAddedNotification($task, $newAssigneeId, $operation)
139 {
140 if($newAssigneeId != get_current_user_id()){
141 $action = 'task_assignee_changed';
142 $message = 'has '.$operation.' you as an assignee.';
143 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
144 $notification->users()->attach($newAssigneeId);
145 }
146 }
147
148 public function createNotification($task, $objectType, $action, $description, $settings = null)
149 {
150 $data = [
151 'object_id' => $task->board_id,
152 'object_type' => $objectType,
153 'task_id' => $task->id,
154 'action' => $action,
155 'description' => $description,
156 'settings' => $settings
157 ];
158 return Notification::create($data);
159 }
160
161 public function findUsersWhoWillGetNotification($task)
162 {
163 $currentUserId = get_current_user_id();
164 $watchersOfTask = $task->watchers;
165 $watchersExceptCurrentUser = [];
166 foreach($watchersOfTask as $watcher){
167 if($watcher->ID != $currentUserId){
168 $watchersExceptCurrentUser[] = $watcher->ID;
169 }
170 }
171 return $watchersExceptCurrentUser;
172 }
173 }
174