summaryrefslogtreecommitdiff
path: root/app/Analytic/TaskDistributionAnalytic.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-15 21:03:19 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-15 21:03:19 -0500
commitc58478c0abfb418048d2ee9c6297a30793f10f80 (patch)
treee4eb461636d87e75c267e3e5f2ff957f3e9e049b /app/Analytic/TaskDistributionAnalytic.php
parent1bbd4faf56969427b550a4d006f2d5018cf97371 (diff)
Move analytic logic to separate classes
Diffstat (limited to 'app/Analytic/TaskDistributionAnalytic.php')
-rw-r--r--app/Analytic/TaskDistributionAnalytic.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/app/Analytic/TaskDistributionAnalytic.php b/app/Analytic/TaskDistributionAnalytic.php
new file mode 100644
index 00000000..614c5f72
--- /dev/null
+++ b/app/Analytic/TaskDistributionAnalytic.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Kanboard\Analytic;
+
+use Kanboard\Core\Base;
+
+/**
+ * Task Distribution
+ *
+ * @package analytic
+ * @author Frederic Guillot
+ */
+class TaskDistributionAnalytic extends Base
+{
+ /**
+ * Build report
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @return array
+ */
+ public function build($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,
+ );
+ }
+
+ if ($total === 0) {
+ return array();
+ }
+
+ foreach ($metrics as &$metric) {
+ $metric['percentage'] = round(($metric['nb_tasks'] * 100) / $total, 2);
+ }
+
+ return $metrics;
+ }
+}