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

167 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 = $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 changeDateNotification($task, $oldDate)
55 {
56 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
57 if(count($userIdsWhoGetNotification) > 0){
58 $action = 'task_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 changeStageNotification($task, $oldStageId)
66 {
67 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
68 if(count($userIdsWhoGetNotification) > 0){
69 $action = 'task_moved_to_new_stage';
70 $message = $task->stage->title;
71 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
72 $notification->users()->attach($userIdsWhoGetNotification);
73 }
74 }
75
76 public function changePriorityNotification($task, $oldPriority)
77 {
78 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
79 if(count($userIdsWhoGetNotification) > 0){
80 $action = 'task_priority_changed';
81 $message = $task->priority;
82 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
83 $notification->users()->attach($userIdsWhoGetNotification);
84 }
85 }
86
87 public function taskArchiveNotification($task)
88 {
89 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
90 if(count($userIdsWhoGetNotification) > 0){
91 if ($task->archived_at) {
92 $action = 'board_task_archived';
93 $message = $task->title;
94 } else {
95 $action = 'board_task_restored';
96 $message = $task->title;
97 }
98 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
99 $notification->users()->attach($userIdsWhoGetNotification);
100 }
101 }
102
103 public function changeTitleOrDescriptionNotification($task, $col, $oldTask)
104 {
105 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
106 if(count($userIdsWhoGetNotification) > 0){
107 if($col == 'title'){
108 $action = 'task_title_updated';
109 $message = $task->title;
110 }else{
111 $action = 'task_description_updated';
112 $message = $task->description;
113 }
114 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
115 $notification->users()->attach($userIdsWhoGetNotification);
116 }
117 }
118
119 public function changeBoardNotification($task, $oldBoardId)
120 {
121 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
122 if(count($userIdsWhoGetNotification) > 0){
123 $new_board_id = Task::findOrFail($task->board_id)->board_id;
124 $new_board_title = Board::findOrFail($new_board_id)->title;
125 $message = 'moved "' . $task->title . '" task to "' . $new_board_title . '" board.';
126 $notification = $this->createNotification($oldBoardId, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $message);
127 $notification->users()->attach($userIdsWhoGetNotification);
128 }
129 }
130
131 public function assigneeAddedNotification($task, $newAssigneeId, $operation)
132 {
133 if($newAssigneeId != get_current_user_id()){
134 $action = 'task_assignee_changed';
135 $message = 'has '.$operation.' you as an assignee.';
136 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
137 $notification->users()->attach($newAssigneeId);
138 }
139 }
140
141 public function createNotification($task, $objectType, $action, $description, $settings = null)
142 {
143 $data = [
144 'object_id' => $task->board_id,
145 'object_type' => $objectType,
146 'task_id' => $task->id,
147 'action' => $action,
148 'description' => $description,
149 'settings' => $settings
150 ];
151 return Notification::create($data);
152 }
153
154 public function findUsersWhoWillGetNotification($task)
155 {
156 $currentUserId = get_current_user_id();
157 $watchersOfTask = $task->watchers;
158 $watchersExceptCurrentUser = [];
159 foreach($watchersOfTask as $watcher){
160 if($watcher->ID != $currentUserId){
161 $watchersExceptCurrentUser[] = $watcher->ID;
162 }
163 }
164 return $watchersExceptCurrentUser;
165 }
166 }
167