summaryrefslogtreecommitdiff
path: root/app/Model
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-11-13 20:37:37 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-11-13 20:37:37 -0500
commit1487cb27634161ef558c367150213bc7077e4198 (patch)
tree5a5684152412abc3bc336cdb63dfe05b7bbb0c4a /app/Model
parente4efc73a90b0ef62b5d828db53a365184be40137 (diff)
Add graph for user repartition
Diffstat (limited to 'app/Model')
-rw-r--r--app/Model/Acl.php2
-rw-r--r--app/Model/ProjectAnalytic.php39
2 files changed, 39 insertions, 2 deletions
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);
+ }
}