summaryrefslogtreecommitdiff
path: root/app/Model/Subtask.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-02-07 19:39:39 -0500
committerFrederic Guillot <fred@kanboard.net>2015-02-07 19:39:39 -0500
commit2d890cbc712371f17ba4bbceb02af3c5ba04e6da (patch)
treef16630432aa7fa22ebc3784839ed77c55e96e6a8 /app/Model/Subtask.php
parentfa6d19928abcfa03861e264222dbe46ad2fdc15a (diff)
Update task time tracking based on subtask time tracking
Diffstat (limited to 'app/Model/Subtask.php')
-rw-r--r--app/Model/Subtask.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/app/Model/Subtask.php b/app/Model/Subtask.php
index 9ecd2c6a..1d5ed566 100644
--- a/app/Model/Subtask.php
+++ b/app/Model/Subtask.php
@@ -176,6 +176,9 @@ class Subtask extends Base
$subtask_id = $this->persist(self::TABLE, $values);
if ($subtask_id) {
+
+ $this->updateTaskTimeTracking($values['task_id']);
+
$this->container['dispatcher']->dispatch(
self::EVENT_CREATE,
new SubtaskEvent(array('id' => $subtask_id) + $values)
@@ -198,6 +201,11 @@ class Subtask extends Base
$result = $this->db->table(self::TABLE)->eq('id', $values['id'])->save($values);
if ($result) {
+
+ if (isset($values['task_id'])) {
+ $this->updateTaskTimeTracking($values['task_id']);
+ }
+
$this->container['dispatcher']->dispatch(
self::EVENT_UPDATE,
new SubtaskEvent($values)
@@ -260,6 +268,37 @@ class Subtask extends Base
}
/**
+ * Update task time tracking based on subtasks time tracking
+ *
+ * @access public
+ * @param integer $task_id Task id
+ * @return bool
+ */
+ public function updateTaskTimeTracking($task_id)
+ {
+ $result = $this->db
+ ->table(self::TABLE)
+ ->eq('task_id', $task_id)
+ ->columns(
+ 'SUM(time_spent) AS total_spent',
+ 'SUM(time_estimated) AS total_estimated'
+ )
+ ->findOne();
+
+ if (empty($result['total_spent']) && empty($result['total_estimated'])) {
+ return true;
+ }
+
+ return $this->db
+ ->table(Task::TABLE)
+ ->eq('id', $task_id)
+ ->update(array(
+ 'time_spent' => $result['total_spent'],
+ 'time_estimated' => $result['total_estimated'],
+ ));
+ }
+
+ /**
* Remove
*
* @access public