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

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