diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-01-19 21:39:11 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-01-19 21:39:11 -0500 |
commit | 209dae72faee6042695eb480e2424b311a09bdb0 (patch) | |
tree | 61f9e03f616d07a18f07872773d636ac866c1b3f /app/Model/UserNotification.php | |
parent | 885c877f4b58058a0d68eaf31fb9d034753787fe (diff) |
Handle notifications for group members attached to a project
Diffstat (limited to 'app/Model/UserNotification.php')
-rw-r--r-- | app/Model/UserNotification.php | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/app/Model/UserNotification.php b/app/Model/UserNotification.php index 8161288c..e8a967ac 100644 --- a/app/Model/UserNotification.php +++ b/app/Model/UserNotification.php @@ -71,7 +71,17 @@ class UserNotification extends Base return $this->getEverybodyWithNotificationEnabled($exclude_user_id); } - return $this->getProjectMembersWithNotificationEnabled($project_id, $exclude_user_id); + $users = array(); + $members = $this->getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id); + $groups = $this->getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id); + + foreach (array_merge($members, $groups) as $user) { + if (! isset($users[$user['id']])) { + $users[$user['id']] = $user; + } + } + + return array_values($users); } /** @@ -142,14 +152,14 @@ class UserNotification extends Base } /** - * Get a list of project members with notification enabled + * Get a list of group members with notification enabled * * @access private * @param integer $project_id Project id * @param integer $exclude_user_id User id to exclude * @return array */ - private function getProjectMembersWithNotificationEnabled($project_id, $exclude_user_id) + private function getProjectUserMembersWithNotificationEnabled($project_id, $exclude_user_id) { return $this->db ->table(ProjectUserRole::TABLE) @@ -161,6 +171,19 @@ class UserNotification extends Base ->findAll(); } + private function getProjectGroupMembersWithNotificationEnabled($project_id, $exclude_user_id) + { + return $this->db + ->table(ProjectGroupRole::TABLE) + ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', User::TABLE.'.email', User::TABLE.'.language', User::TABLE.'.notifications_filter') + ->join(GroupMember::TABLE, 'group_id', 'group_id', ProjectGroupRole::TABLE) + ->join(User::TABLE, 'id', 'user_id', GroupMember::TABLE) + ->eq(ProjectGroupRole::TABLE.'.project_id', $project_id) + ->eq(User::TABLE.'.notifications_enabled', '1') + ->neq(User::TABLE.'.id', $exclude_user_id) + ->findAll(); + } + /** * Get a list of project members with notification enabled * |