summaryrefslogtreecommitdiff
path: root/app/Model/ProjectAnalytic.php
diff options
context:
space:
mode:
authorBusfreak <martin@middeke.de>2015-12-15 12:00:47 +0100
committerBusfreak <martin@middeke.de>2015-12-15 12:00:47 +0100
commit16e8241f0f29f0afb9c4ad4c6f68699d62d889ff (patch)
treeaa0f03c5c1d7897246e513e52c6a1f823709dd3d /app/Model/ProjectAnalytic.php
parentb834f5475c8eebb76548046558e7d1464cbd01d4 (diff)
parent9e1f4fa6c7eae1b46cf5431ab085b82e970e2d57 (diff)
Merge remote-tracking branch 'refs/remotes/origin/master'
Diffstat (limited to 'app/Model/ProjectAnalytic.php')
-rw-r--r--app/Model/ProjectAnalytic.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/app/Model/ProjectAnalytic.php b/app/Model/ProjectAnalytic.php
index e77a0368..d23695dc 100644
--- a/app/Model/ProjectAnalytic.php
+++ b/app/Model/ProjectAnalytic.php
@@ -179,4 +179,49 @@ class ProjectAnalytic extends Base
return $stats;
}
+
+ /**
+ * Get the time spent and estimated into each status
+ *
+ * @access public
+ * @param integer $project_id
+ * @return array
+ */
+ public function getHoursByStatus($project_id)
+ {
+ $stats = array();
+
+ // Get the times related to each task
+ $tasks = $this->db
+ ->table(Task::TABLE)
+ ->columns('id', 'time_estimated', 'time_spent', 'is_active')
+ ->eq('project_id', $project_id)
+ ->desc('id')
+ ->limit(1000)
+ ->findAll();
+
+ // Init values
+ $stats['closed'] = array(
+ 'time_spent' => 0,
+ 'time_estimated' => 0,
+ );
+
+ $stats['open'] = array(
+ 'time_spent' => 0,
+ 'time_estimated' => 0,
+ );
+
+ // Add times spent and estimated to each status
+ foreach ($tasks as &$task) {
+ if ($task['is_active']) {
+ $stats['open']['time_estimated'] += $task['time_estimated'];
+ $stats['open']['time_spent'] += $task['time_spent'];
+ } else {
+ $stats['closed']['time_estimated'] += $task['time_estimated'];
+ $stats['closed']['time_spent'] += $task['time_spent'];
+ }
+ }
+
+ return $stats;
+ }
}