summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-19 21:39:11 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-19 21:39:11 -0500
commit209dae72faee6042695eb480e2424b311a09bdb0 (patch)
tree61f9e03f616d07a18f07872773d636ac866c1b3f /app
parent885c877f4b58058a0d68eaf31fb9d034753787fe (diff)
Handle notifications for group members attached to a project
Diffstat (limited to 'app')
-rw-r--r--app/Model/ProjectGroupRole.php6
-rw-r--r--app/Model/UserNotification.php29
2 files changed, 29 insertions, 6 deletions
diff --git a/app/Model/ProjectGroupRole.php b/app/Model/ProjectGroupRole.php
index ee6ee7cb..591b28c6 100644
--- a/app/Model/ProjectGroupRole.php
+++ b/app/Model/ProjectGroupRole.php
@@ -101,10 +101,10 @@ class ProjectGroupRole extends Base
*/
public function getAssignableUsers($project_id)
{
- return $this->db->table(self::TABLE)
+ return $this->db->table(User::TABLE)
->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name')
- ->join(GroupMember::TABLE, 'group_id', 'group_id', self::TABLE)
- ->join(User::TABLE, 'id', 'user_id', GroupMember::TABLE)
+ ->join(GroupMember::TABLE, 'user_id', 'id', User::TABLE)
+ ->join(self::TABLE, 'group_id', 'group_id', GroupMember::TABLE)
->eq(self::TABLE.'.project_id', $project_id)
->in(self::TABLE.'.role', array(Role::PROJECT_MANAGER, Role::PROJECT_MEMBER))
->asc(User::TABLE.'.username')
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
*