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

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

192 lines 8.0 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' : 'comment_created';
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($comment, $mentionIds)
30 {
31 if($comment){
32 $task = Task::findOrFail($comment->task_id);
33 $plainDescription = strip_tags($comment->description);
34 $action = 'task_comment_mentioned';
35 $message = $plainDescription;
36 $settings = [ 'comment_id' => $comment->parent_id ?? $comment->id ];
37 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message, $settings);
38 $notification->users()->attach($mentionIds);
39 }
40 }
41
42 public function addSubtaskNotification($parentTask, $subTask)
43 {
44 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($parentTask);
45 if(count($userIdsWhoGetNotification) > 0){
46 $board_id = $subTask->board_id;
47 $action = 'subtask_added';
48 $message = $subTask->title ;
49 $notification = $this->createNotification($parentTask, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
50 $notification->users()->attach($userIdsWhoGetNotification);
51 }
52 }
53
54 public function changeDueDateNotification($task, $oldDate)
55 {
56 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
57 if(count($userIdsWhoGetNotification) > 0){
58 $action = 'task_due_date_changed';
59 $message = date_i18n('F j, Y, g:i a', strtotime($task->due_at));
60 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
61 $notification->users()->attach($userIdsWhoGetNotification);
62 }
63 }
64
65 public function changeStartDateNotification($task, $oldDate)
66 {
67 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
68 if(count($userIdsWhoGetNotification) > 0){
69 $action = 'task_start_date_changed';
70 $message = date_i18n('F j, Y, g:i a', strtotime($task->started_at));
71 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
72 $notification->users()->attach($userIdsWhoGetNotification);
73 }
74 }
75
76 public function changeStageNotification($task, $oldStageId)
77 {
78 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
79 if(count($userIdsWhoGetNotification) > 0){
80 $action = 'task_moved_to_new_stage';
81 $message = $task->stage->title;
82 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
83 $notification->users()->attach($userIdsWhoGetNotification);
84 }
85 }
86
87 public function changePriorityNotification($task, $oldPriority)
88 {
89 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
90 if(count($userIdsWhoGetNotification) > 0){
91 $action = 'task_priority_changed';
92 $message = $task->priority;
93 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
94 $notification->users()->attach($userIdsWhoGetNotification);
95 }
96 }
97
98 public function taskArchiveNotification($task)
99 {
100 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
101 if(count($userIdsWhoGetNotification) > 0){
102 if ($task->archived_at) {
103 $action = 'board_task_archived';
104 $message = $task->title;
105 } else {
106 $action = 'board_task_restored';
107 $message = $task->title;
108 }
109 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
110 $notification->users()->attach($userIdsWhoGetNotification);
111 }
112 }
113
114 public function changeTitleOrDescriptionNotification($task, $col, $oldTask)
115 {
116 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
117 if(count($userIdsWhoGetNotification) > 0){
118 if($col == 'title'){
119 $action = 'task_title_updated';
120 $message = $task->title;
121 }else{
122 $action = 'task_description_updated';
123 $message = $task->description;
124 }
125 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
126 $notification->users()->attach($userIdsWhoGetNotification);
127 }
128 }
129
130 public function changeBoardNotification($task, $oldBoardId)
131 {
132 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
133 if(count($userIdsWhoGetNotification) > 0){
134 $new_board_id = Task::findOrFail($task->board_id)->board_id;
135 $new_board_title = Board::findOrFail($new_board_id)->title;
136 $message = 'moved "' . $task->title . '" task to "' . $new_board_title . '" board.';
137 $notification = $this->createNotification($oldBoardId, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $message);
138 $notification->users()->attach($userIdsWhoGetNotification);
139 }
140 }
141
142 public function assigneeAddedNotification($task, $newAssigneeId)
143 {
144 if($newAssigneeId != get_current_user_id()){
145 $action = 'task_assignee_changed';
146 $message = 'has added you as an assignee.';
147 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
148 $notification->users()->attach($newAssigneeId);
149 }
150 }
151
152 public function assigneeRemovedNotification($task, $newAssigneeId)
153 {
154 if($newAssigneeId != get_current_user_id()){
155 $action = 'task_assignee_changed';
156 $message = 'has removed you as an assignee.';
157 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
158 $notification->users()->attach($newAssigneeId);
159 }
160 }
161
162 public function createNotification($task, $objectType, $action, $description, $settings = null)
163 {
164 $data = [
165 'object_id' => $task->board_id,
166 'object_type' => $objectType,
167 'task_id' => $task->id,
168 'action' => $action,
169 'description' => $description,
170 'settings' => $settings
171 ];
172 $currentUser = get_current_user_id();
173 if($currentUser == 0) {
174 $data['activity_by'] = $task->created_by;
175 }
176 return Notification::create($data);
177 }
178
179 public function findUsersWhoWillGetNotification($task)
180 {
181 $currentUserId = get_current_user_id();
182 $watchersOfTask = $task->watchers;
183 $watchersExceptCurrentUser = [];
184 foreach($watchersOfTask as $watcher){
185 if($watcher->ID != $currentUserId){
186 $watchersExceptCurrentUser[] = $watcher->ID;
187 }
188 }
189 return $watchersExceptCurrentUser;
190 }
191 }
192