/** * Update the time for a given task * * @param Task $task */ private function updateTaskTime(Task $task) { try { $this->dbService->beginTransaction(); // Get the total time for this task. $select = $dbService->select(); $select = $this->dbService->select(); $select->from('timesheetrecord', new Zend_Db_Expr('SUM(endtime - starttime) AS tasktime'))->where('taskid = ?', $task->id); $row = $this->dbService->fetchAll($select); $total = $row[0]['tasktime']; if ($total > 0) { // hours = timespent / 3600 $task->timespent = $total; $task->updated = date('Y-m-d H:i:s'); // make sure that the project the task is attached to is marked as 'started' $project = $this->getProject($task->projectid); if ($project) { // make sure it has a start date if (!mb_strlen($project->actualstart)) { $project->actualstart = date('Y-m-d H:i:s', time()); } // save to force a time update $this->saveProject($project); } $this->saveTask($task); // $this->dbService->updateObject($task); } else { // just save it that there's no time at all $task->timespent = 0; $this->saveTask($task); } $this->dbService->commit(); } catch (Exception $e) { $this->dbService->rollback(); throw $e; } }