diff options
| author | Frederic Guillot <fred@kanboard.net> | 2015-08-22 16:20:53 -0400 |
|---|---|---|
| committer | Frederic Guillot <fred@kanboard.net> | 2015-08-22 16:20:53 -0400 |
| commit | fd60964c239627d2d55c6eca0888be84a8f6653f (patch) | |
| tree | 062836c4a49857625a25b2cfdd3bbb93732f915d /app/Model/ProjectPermission.php | |
| parent | 18fd39e6d648a58be0782d514604877504833832 (diff) | |
Add global Gantt chart for all projects
Diffstat (limited to 'app/Model/ProjectPermission.php')
| -rw-r--r-- | app/Model/ProjectPermission.php | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php index 03e9bea6..c412b7a9 100644 --- a/app/Model/ProjectPermission.php +++ b/app/Model/ProjectPermission.php @@ -50,40 +50,49 @@ class ProjectPermission extends Base } /** - * Get a list of allowed people for a project + * Get a list of members and managers with a single SQL query * * @access public * @param integer $project_id Project id * @return array */ - public function getMembers($project_id) + public function getProjectUsers($project_id) { - if ($this->isEverybodyAllowed($project_id)) { - return $this->user->getList(); + $result = array( + 'managers' => array(), + 'members' => array(), + ); + + $users = $this->db + ->table(self::TABLE) + ->join(User::TABLE, 'id', 'user_id') + ->eq('project_id', $project_id) + ->asc('username') + ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name', self::TABLE.'.is_owner') + ->findAll(); + + foreach ($users as $user) { + $key = $user['is_owner'] == 1 ? 'managers' : 'members'; + $result[$key][$user['id']] = $user['name'] ?: $user['username']; } - return $this->getAssociatedUsers($project_id); + return $result; } /** - * Get a list of standard user members for a project + * Get a list of allowed people for a project * * @access public * @param integer $project_id Project id * @return array */ - public function getOnlyMembers($project_id) + public function getMembers($project_id) { - $users = $this->db - ->table(self::TABLE) - ->join(User::TABLE, 'id', 'user_id') - ->eq('project_id', $project_id) - ->eq('is_owner', 0) - ->asc('username') - ->columns(User::TABLE.'.id', User::TABLE.'.username', User::TABLE.'.name') - ->findAll(); + if ($this->isEverybodyAllowed($project_id)) { + return $this->user->getList(); + } - return $this->user->prepareList($users); + return $this->getAssociatedUsers($project_id); } /** |
