summaryrefslogtreecommitdiff
path: root/app/Model/ProjectAnalytic.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Model/ProjectAnalytic.php')
-rw-r--r--app/Model/ProjectAnalytic.php39
1 files changed, 38 insertions, 1 deletions
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);
+ }
}