summaryrefslogtreecommitdiff
path: root/app/Model/ProjectPermission.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model/ProjectPermission.php')
-rw-r--r--app/Model/ProjectPermission.php41
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);
}
/**