summaryrefslogtreecommitdiff
path: root/app/Model/ProjectAnalytic.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-11-09 17:59:02 -0500
committerFrédéric Guillot <fred@kanboard.net>2014-11-09 17:59:02 -0500
commite89ba5e9e692f33427fedb05a095255f27480a6b (patch)
tree59cbca6ac75a8eff45be14f6ae4ab487e0a427b1 /app/Model/ProjectAnalytic.php
parent3df63e051fac84cec98c912668722f87d6e8183e (diff)
Analytics: add the first graph (task repartition)
Diffstat (limited to 'app/Model/ProjectAnalytic.php')
-rw-r--r--app/Model/ProjectAnalytic.php43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/Model/ProjectAnalytic.php b/app/Model/ProjectAnalytic.php
new file mode 100644
index 00000000..ccd2c4c9
--- /dev/null
+++ b/app/Model/ProjectAnalytic.php
@@ -0,0 +1,43 @@
+<?php
+
+namespace Model;
+
+/**
+ * Project analytic model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class ProjectAnalytic extends Base
+{
+ /**
+ * Get task repartition
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @return array
+ */
+ public function getTaskRepartition($project_id)
+ {
+ $metrics = array();
+ $total = 0;
+ $columns = $this->board->getColumns($project_id);
+
+ foreach ($columns as $column) {
+
+ $nb_tasks = $this->taskFinder->countByColumnId($project_id, $column['id']);
+ $total += $nb_tasks;
+
+ $metrics[] = array(
+ 'column_title' => $column['title'],
+ 'nb_tasks' => $nb_tasks,
+ );
+ }
+
+ foreach ($metrics as &$metric) {
+ $metric['percentage'] = round(($metric['nb_tasks'] * 100) / $total, 2);
+ }
+
+ return $metrics;
+ }
+}