summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-08-16 22:17:45 -0400
committerFrederic Guillot <fred@kanboard.net>2015-08-16 22:17:45 -0400
commit2fd177363b1359566ad0078fbb8ec9138eea170c (patch)
treee0f51b1c81d6bc372f5877c598c2f35b1f2670bc /app/Model
parent06638ff5e9eb150e6798b1b79bf77e24f807c7b1 (diff)
Add project users overview
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Acl.php1
-rw-r--r--app/Model/Project.php37
-rw-r--r--app/Model/ProjectPermission.php77
-rw-r--r--app/Model/TaskFinder.php37
-rw-r--r--app/Model/User.php11
5 files changed, 138 insertions, 25 deletions
diff --git a/app/Model/Acl.php b/app/Model/Acl.php
index 312ae7d4..b1e9eb07 100644
--- a/app/Model/Acl.php
+++ b/app/Model/Acl.php
@@ -76,6 +76,7 @@ class Acl extends Base
*/
private $project_admin_acl = array(
'project' => array('remove'),
+ 'projectuser' => '*',
);
/**
diff --git a/app/Model/Project.php b/app/Model/Project.php
index 3c864e5d..fedc41ac 100644
--- a/app/Model/Project.php
+++ b/app/Model/Project.php
@@ -261,6 +261,24 @@ class Project extends Base
}
/**
+ * Fetch more information for each project
+ *
+ * @access public
+ * @param array $projects
+ * @return array
+ */
+ public function applyProjectDetails(array $projects)
+ {
+ foreach ($projects as &$project) {
+ $this->getColumnStats($project);
+ $project['managers'] = $this->projectPermission->getManagers($project['id']);
+ $project['members'] = $this->projectPermission->getOnlyMembers($project['id']);
+ }
+
+ return $projects;
+ }
+
+ /**
* Get project summary for a list of project
*
* @access public
@@ -280,6 +298,25 @@ class Project extends Base
}
/**
+ * Get project details (users + columns) for a list of project
+ *
+ * @access public
+ * @param array $project_ids List of project id
+ * @return \PicoDb\Table
+ */
+ public function getQueryProjectDetails(array $project_ids)
+ {
+ if (empty($project_ids)) {
+ return $this->db->table(Project::TABLE)->limit(0);
+ }
+
+ return $this->db
+ ->table(Project::TABLE)
+ ->in('id', $project_ids)
+ ->callback(array($this, 'applyProjectDetails'));
+ }
+
+ /**
* Create a project
*
* @access public
diff --git a/app/Model/ProjectPermission.php b/app/Model/ProjectPermission.php
index bc752dda..03e9bea6 100644
--- a/app/Model/ProjectPermission.php
+++ b/app/Model/ProjectPermission.php
@@ -66,18 +66,19 @@ class ProjectPermission extends Base
}
/**
- * Get a list of people associated to the project
+ * Get a list of standard user members for a project
*
* @access public
* @param integer $project_id Project id
* @return array
*/
- public function getAssociatedUsers($project_id)
+ public function getOnlyMembers($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();
@@ -107,6 +108,57 @@ class ProjectPermission extends Base
}
/**
+ * Get query for project users overview
+ *
+ * @access public
+ * @param array $project_ids
+ * @param integer $is_owner
+ * @return \PicoDb\Table
+ */
+ public function getQueryByRole(array $project_ids, $is_owner = 0)
+ {
+ if (empty($project_ids)) {
+ $project_ids = array(-1);
+ }
+
+ return $this
+ ->db
+ ->table(self::TABLE)
+ ->join(User::TABLE, 'id', 'user_id')
+ ->join(Project::TABLE, 'id', 'project_id')
+ ->eq(self::TABLE.'.is_owner', $is_owner)
+ ->eq(Project::TABLE.'.is_private', 0)
+ ->in(Project::TABLE.'.id', $project_ids)
+ ->columns(
+ User::TABLE.'.id',
+ User::TABLE.'.username',
+ User::TABLE.'.name',
+ Project::TABLE.'.name AS project_name',
+ Project::TABLE.'.id'
+ );
+ }
+
+ /**
+ * Get a list of people associated to the project
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @return array
+ */
+ public function getAssociatedUsers($project_id)
+ {
+ $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')
+ ->findAll();
+
+ return $this->user->prepareList($users);
+ }
+
+ /**
* Get allowed and not allowed users for a project
*
* @access public
@@ -127,7 +179,6 @@ class ProjectPermission extends Base
$users['managers'] = $this->getManagers($project_id);
foreach ($all_users as $user_id => $username) {
-
if (! isset($users['allowed'][$user_id])) {
$users['not_allowed'][$user_id] = $username;
}
@@ -270,26 +321,6 @@ class ProjectPermission extends Base
}
/**
- * Filter a list of projects for a given user
- *
- * @access public
- * @param array $projects Project list: ['project_id' => 'project_name']
- * @param integer $user_id User id
- * @param string $filter Method name to apply
- * @return array
- */
- public function filterProjects(array $projects, $user_id, $filter = 'isUserAllowed')
- {
- foreach ($projects as $project_id => $project_name) {
- if (! $this->$filter($project_id, $user_id)) {
- unset($projects[$project_id]);
- }
- }
-
- return $projects;
- }
-
- /**
* Return a list of allowed active projects for a given user
*
* @access public
diff --git a/app/Model/TaskFinder.php b/app/Model/TaskFinder.php
index 6cf79d1f..b98e3bd5 100644
--- a/app/Model/TaskFinder.php
+++ b/app/Model/TaskFinder.php
@@ -13,6 +13,43 @@ use PDO;
class TaskFinder extends Base
{
/**
+ * Get query for project user overview
+ *
+ * @access public
+ * @param array $project_ids
+ * @param integer $is_active
+ * @return \PicoDb\Table
+ */
+ public function getProjectUserOverviewQuery(array $project_ids, $is_active)
+ {
+ if (empty($project_ids)) {
+ $project_ids = array(-1);
+ }
+
+ return $this->db
+ ->table(Task::TABLE)
+ ->columns(
+ Task::TABLE.'.id',
+ Task::TABLE.'.title',
+ Task::TABLE.'.date_due',
+ Task::TABLE.'.date_started',
+ Task::TABLE.'.project_id',
+ Task::TABLE.'.color_id',
+ Task::TABLE.'.time_spent',
+ Task::TABLE.'.time_estimated',
+ Project::TABLE.'.name AS project_name',
+ Board::TABLE.'.title AS column_name',
+ User::TABLE.'.username AS assignee_username',
+ User::TABLE.'.name AS assignee_name'
+ )
+ ->eq(Task::TABLE.'.is_active', $is_active)
+ ->in(Project::TABLE.'.id', $project_ids)
+ ->join(Project::TABLE, 'id', 'project_id')
+ ->join(Board::TABLE, 'id', 'column_id', Task::TABLE)
+ ->join(User::TABLE, 'id', 'owner_id', Task::TABLE);
+ }
+
+ /**
* Get query for assigned user tasks
*
* @access public
diff --git a/app/Model/User.php b/app/Model/User.php
index 76af342d..1a7a0666 100644
--- a/app/Model/User.php
+++ b/app/Model/User.php
@@ -208,12 +208,19 @@ class User extends Base
* List all users (key-value pairs with id/username)
*
* @access public
+ * @param boolean $prepend Prepend "All users"
* @return array
*/
- public function getList()
+ public function getList($prepend = false)
{
$users = $this->db->table(self::TABLE)->columns('id', 'username', 'name')->findAll();
- return $this->prepareList($users);
+ $listing = $this->prepareList($users);
+
+ if ($prepend) {
+ return array(User::EVERYBODY_ID => t('Everybody')) + $listing;
+ }
+
+ return $listing;
}
/**