Update task time tracking based on subtask time tracking
This commit is contained in:
@@ -10,40 +10,41 @@ use Pimple\Container;
|
||||
* @package model
|
||||
* @author Frederic Guillot
|
||||
*
|
||||
* @property \Core\Session $session
|
||||
* @property \Core\Template $template
|
||||
* @property \Model\Acl $acl
|
||||
* @property \Model\Action $action
|
||||
* @property \Model\Authentication $authentication
|
||||
* @property \Model\Board $board
|
||||
* @property \Model\Category $category
|
||||
* @property \Model\Comment $comment
|
||||
* @property \Model\CommentHistory $commentHistory
|
||||
* @property \Model\Color $color
|
||||
* @property \Model\Config $config
|
||||
* @property \Model\DateParser $dateParser
|
||||
* @property \Model\File $file
|
||||
* @property \Model\Helper $helper
|
||||
* @property \Model\LastLogin $lastLogin
|
||||
* @property \Model\Notification $notification
|
||||
* @property \Model\Project $project
|
||||
* @property \Model\ProjectDuplication $projectDuplication
|
||||
* @property \Model\ProjectPermission $projectPermission
|
||||
* @property \Model\Subtask $subtask
|
||||
* @property \Model\SubtaskHistory $subtaskHistory
|
||||
* @property \Model\Swimlane $swimlane
|
||||
* @property \Model\Task $task
|
||||
* @property \Model\TaskCreation $taskCreation
|
||||
* @property \Model\TaskDuplication $taskDuplication
|
||||
* @property \Model\TaskExport $taskExport
|
||||
* @property \Model\TaskFinder $taskFinder
|
||||
* @property \Model\TaskHistory $taskHistory
|
||||
* @property \Model\TaskPosition $taskPosition
|
||||
* @property \Model\TaskValidator $taskValidator
|
||||
* @property \Model\TimeTracking $timeTracking
|
||||
* @property \Model\User $user
|
||||
* @property \Model\UserSession $userSession
|
||||
* @property \Model\Webhook $webhook
|
||||
* @property \Core\Session $session
|
||||
* @property \Core\Template $template
|
||||
* @property \Model\Acl $acl
|
||||
* @property \Model\Action $action
|
||||
* @property \Model\Authentication $authentication
|
||||
* @property \Model\Board $board
|
||||
* @property \Model\Category $category
|
||||
* @property \Model\Comment $comment
|
||||
* @property \Model\CommentHistory $commentHistory
|
||||
* @property \Model\Color $color
|
||||
* @property \Model\Config $config
|
||||
* @property \Model\DateParser $dateParser
|
||||
* @property \Model\File $file
|
||||
* @property \Model\Helper $helper
|
||||
* @property \Model\LastLogin $lastLogin
|
||||
* @property \Model\Notification $notification
|
||||
* @property \Model\Project $project
|
||||
* @property \Model\ProjectDuplication $projectDuplication
|
||||
* @property \Model\ProjectPermission $projectPermission
|
||||
* @property \Model\Subtask $subtask
|
||||
* @property \Model\SubtaskHistory $subtaskHistory
|
||||
* @property \Model\Swimlane $swimlane
|
||||
* @property \Model\Task $task
|
||||
* @property \Model\TaskCreation $taskCreation
|
||||
* @property \Model\TaskDuplication $taskDuplication
|
||||
* @property \Model\TaskExport $taskExport
|
||||
* @property \Model\TaskFinder $taskFinder
|
||||
* @property \Model\TaskHistory $taskHistory
|
||||
* @property \Model\TaskPosition $taskPosition
|
||||
* @property \Model\TaskValidator $taskValidator
|
||||
* @property \Model\TimeTracking $timeTracking
|
||||
* @property \Model\SubtaskTimeTracking $subtaskTimeTracking
|
||||
* @property \Model\User $user
|
||||
* @property \Model\UserSession $userSession
|
||||
* @property \Model\Webhook $webhook
|
||||
*/
|
||||
abstract class Base
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
@@ -259,6 +267,37 @@ class Subtask extends Base
|
||||
->count() === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user