summaryrefslogtreecommitdiff
path: root/app/Analytic/EstimatedTimeComparisonAnalytic.php
diff options
context:
space:
mode:
authorGerardo Zamudio <gerardozamudio@users.noreply.github.com>2016-02-24 23:48:50 -0600
committerGerardo Zamudio <gerardozamudio@users.noreply.github.com>2016-02-24 23:48:50 -0600
commite4de6b3898b64b26d29aff31f21df5fda8055686 (patch)
tree575f8a65440f291d70a070d168eafca8c82a6459 /app/Analytic/EstimatedTimeComparisonAnalytic.php
parentd9ffbea174ea6524d0a22f8375ca8b3aa04a3c96 (diff)
parenta6540bc604c837d92c9368540c145606723e97f7 (diff)
Merge pull request #1 from fguillot/master
Update from upstream
Diffstat (limited to 'app/Analytic/EstimatedTimeComparisonAnalytic.php')
-rw-r--r--app/Analytic/EstimatedTimeComparisonAnalytic.php50
1 files changed, 50 insertions, 0 deletions
diff --git a/app/Analytic/EstimatedTimeComparisonAnalytic.php b/app/Analytic/EstimatedTimeComparisonAnalytic.php
new file mode 100644
index 00000000..490bcd50
--- /dev/null
+++ b/app/Analytic/EstimatedTimeComparisonAnalytic.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace Kanboard\Analytic;
+
+use Kanboard\Core\Base;
+use Kanboard\Model\Task;
+
+/**
+ * Estimated/Spent Time Comparison
+ *
+ * @package analytic
+ * @author Frederic Guillot
+ */
+class EstimatedTimeComparisonAnalytic extends Base
+{
+ /**
+ * Build report
+ *
+ * @access public
+ * @param integer $project_id Project id
+ * @return array
+ */
+ public function build($project_id)
+ {
+ $rows = $this->db->table(Task::TABLE)
+ ->columns('SUM(time_estimated) AS time_estimated', 'SUM(time_spent) AS time_spent', 'is_active')
+ ->eq('project_id', $project_id)
+ ->groupBy('is_active')
+ ->findAll();
+
+ $metrics = array(
+ 'open' => array(
+ 'time_spent' => 0,
+ 'time_estimated' => 0,
+ ),
+ 'closed' => array(
+ 'time_spent' => 0,
+ 'time_estimated' => 0,
+ ),
+ );
+
+ foreach ($rows as $row) {
+ $key = $row['is_active'] == Task::STATUS_OPEN ? 'open' : 'closed';
+ $metrics[$key]['time_spent'] = $row['time_spent'];
+ $metrics[$key]['time_estimated'] = $row['time_estimated'];
+ }
+
+ return $metrics;
+ }
+}