summaryrefslogtreecommitdiff
path: root/app/Model/TimeTracking.php
diff options
context:
space:
mode:
authorFrédéric Guillot <fred@kanboard.net>2014-10-11 21:11:10 -0400
committerFrédéric Guillot <fred@kanboard.net>2014-10-11 21:11:10 -0400
commitacba6839a6082e3e3800a733f8baea7c843fc02e (patch)
treee2847dcd13d9ccc3d8f0f6f936a5776df852e11b /app/Model/TimeTracking.php
parenta8418afdebe92dde495bc5010645779c73939b7b (diff)
Add 3 new fields for tasks: start date, time estimated and time spent
Diffstat (limited to 'app/Model/TimeTracking.php')
-rw-r--r--app/Model/TimeTracking.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/app/Model/TimeTracking.php b/app/Model/TimeTracking.php
new file mode 100644
index 00000000..4ddddf12
--- /dev/null
+++ b/app/Model/TimeTracking.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Model;
+
+/**
+ * Time tracking model
+ *
+ * @package model
+ * @author Frederic Guillot
+ */
+class TimeTracking extends Base
+{
+ /**
+ * Calculate time metrics for a task
+ *
+ * Use subtasks time metrics if not empty otherwise return task time metrics
+ *
+ * @access public
+ * @param array $task Task properties
+ * @param array $subtasks Subtasks list
+ * @return array
+ */
+ public function getTaskTimesheet(array $task, array $subtasks)
+ {
+ $timesheet = array(
+ 'time_spent' => 0,
+ 'time_estimated' => 0,
+ 'time_remaining' => 0,
+ );
+
+ foreach ($subtasks as &$subtask) {
+ $timesheet['time_estimated'] += $subtask['time_estimated'];
+ $timesheet['time_spent'] += $subtask['time_spent'];
+ }
+
+ if ($timesheet['time_estimated'] == 0 && $timesheet['time_spent'] == 0) {
+ $timesheet['time_estimated'] = $task['time_estimated'];
+ $timesheet['time_spent'] = $task['time_spent'];
+ }
+
+ $timesheet['time_remaining'] = $timesheet['time_estimated'] - $timesheet['time_spent'];
+
+ return $timesheet;
+ }
+}