diff options
| author | Frederic Guillot <fred@kanboard.net> | 2015-10-03 12:09:27 -0400 |
|---|---|---|
| committer | Frederic Guillot <fred@kanboard.net> | 2015-10-03 12:09:27 -0400 |
| commit | d67d7c54e65e80d1b484490e42dbecb969aa7686 (patch) | |
| tree | e62446885fac0d3af5b29d409d8e9a4f6c50940e /app/Model/OverdueNotification.php | |
| parent | b5a2b8f9f7ac9ef947357acd3981993159d64b52 (diff) | |
Add web notifications
Diffstat (limited to 'app/Model/OverdueNotification.php')
| -rw-r--r-- | app/Model/OverdueNotification.php | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/app/Model/OverdueNotification.php b/app/Model/OverdueNotification.php new file mode 100644 index 00000000..19bd0987 --- /dev/null +++ b/app/Model/OverdueNotification.php @@ -0,0 +1,60 @@ +<?php + +namespace Model; + +/** + * Task Overdue Notification model + * + * @package model + * @author Frederic Guillot + */ +class OverdueNotification extends Base +{ + /** + * Send overdue tasks + * + * @access public + */ + public function sendOverdueTaskNotifications() + { + $tasks = $this->taskFinder->getOverdueTasks(); + + foreach ($this->groupByColumn($tasks, 'project_id') as $project_id => $project_tasks) { + + // Get the list of users that should receive notifications for each projects + $users = $this->notification->getUsersWithNotificationEnabled($project_id); + + foreach ($users as $user) { + $this->sendUserOverdueTaskNotifications($user, $project_tasks); + } + } + + return $tasks; + } + + /** + * Send overdue tasks for a given user + * + * @access public + * @param array $user + * @param array $tasks + */ + public function sendUserOverdueTaskNotifications(array $user, array $tasks) + { + $user_tasks = array(); + + foreach ($tasks as $task) { + if ($this->notificationFilter->shouldReceiveNotification($user, array('task' => $task))) { + $user_tasks[] = $task; + } + } + + if (! empty($user_tasks)) { + $this->notification->sendUserNotification( + $user, + Task::EVENT_OVERDUE, + array('tasks' => $user_tasks, 'project_name' => $tasks[0]['project_name']) + ); + } + } +} |
