From 1487cb27634161ef558c367150213bc7077e4198 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Thu, 13 Nov 2014 20:37:37 -0500 Subject: Add graph for user repartition --- app/Model/Acl.php | 2 +- app/Model/ProjectAnalytic.php | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) (limited to 'app/Model') diff --git a/app/Model/Acl.php b/app/Model/Acl.php index 52957130..25e98850 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -41,7 +41,7 @@ class Acl extends Base 'task' => array('show', 'create', 'save', 'edit', 'update', 'close', 'open', 'duplicate', 'remove', 'description', 'move', 'copy', 'time'), 'category' => array('index', 'save', 'edit', 'update', 'confirm', 'remove'), 'action' => array('index', 'event', 'params', 'create', 'confirm', 'remove'), - 'analytic' => array('repartition'), + 'analytic' => array('tasks', 'users'), ); /** diff --git a/app/Model/ProjectAnalytic.php b/app/Model/ProjectAnalytic.php index ccd2c4c9..8ecbf1f0 100644 --- a/app/Model/ProjectAnalytic.php +++ b/app/Model/ProjectAnalytic.php @@ -11,7 +11,7 @@ namespace Model; class ProjectAnalytic extends Base { /** - * Get task repartition + * Get tasks repartition * * @access public * @param integer $project_id Project id @@ -40,4 +40,41 @@ class ProjectAnalytic extends Base return $metrics; } + + /** + * Get users repartition + * + * @access public + * @param integer $project_id Project id + * @return array + */ + public function getUserRepartition($project_id) + { + $metrics = array(); + $total = 0; + $tasks = $this->taskFinder->getAll($project_id); + $users = $this->projectPermission->getMemberList($project_id); + + foreach ($tasks as $task) { + + $user = $users[$task['owner_id']]; + $total++; + + if (! isset($metrics[$user])) { + $metrics[$user] = array( + 'nb_tasks' => 0, + 'percentage' => 0, + 'user' => $user, + ); + } + + $metrics[$user]['nb_tasks']++; + } + + foreach ($metrics as &$metric) { + $metric['percentage'] = round(($metric['nb_tasks'] * 100) / $total, 2); + } + + return array_values($metrics); + } } -- cgit v1.2.3