/** * Test updating hours worked for a task */ public function testUpdateHoursWorked() { CTask::updateHoursWorked(1, 25); $xml_file_dataset = $this->createXMLDataSet($this->getDataSetPath() . 'tasksTestUpdateHoursWorked.xml'); $xml_db_dataset = $this->getConnection()->createDataSet(); $this->assertTablesEqual($xml_file_dataset->getTable('tasks'), $xml_db_dataset->getTable('tasks')); }
/** * Updates the variable information on the task. * * @param int $task_log_task that task id of task this task log is for * * @return void * * @access private */ protected function updateTaskSummary($AppUI = null, $task_id) { $q = $this->_getQuery(); if ($this->_perms->checkModuleItem('tasks', 'edit', $task_id)) { if ($this->task_log_percent_complete < 100) { $q->addQuery('task_log_percent_complete, task_log_date'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_id); $q->addOrder('task_log_date DESC, task_log_id DESC'); $q->setLimit(1); $results = $q->loadHash(); $percentComplete = $results['task_log_percent_complete']; } else { $percentComplete = 100; } $task = new CTask(); $task->overrideDatabase($this->_query); $task->load($task_id); $task->task_percent_complete = $percentComplete; $diff = strtotime($this->task_log_task_end_date) - strtotime($task->task_end_date); $task->task_end_date = 0 == $diff ? $task->task_end_date : $this->task_log_task_end_date; $success = $task->store(); if (!$success) { $this->_AppUI->setMsg($task->getError(), UI_MSG_ERROR, true); } $task->pushDependencies($task_id, $task->task_end_date); } $q->addQuery('SUM(task_log_hours)'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_id); $totalHours = $q->loadResult(); CTask::updateHoursWorked($task_id, $totalHours); }
private function updateHoursWorked($task_log_task) { $q = new DBQuery(); $q->addQuery('SUM(task_log_hours)'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_log_task); $totalHours = $q->loadResult(); CTask::updateHoursWorked($task_log_task, $totalHours); }
/** * Updates the variable information on the task. * * @param int $task_log_task that task id of task this task log is for * * @return void * * @access private */ private function updateTaskSummary(CAppUI $AppUI, $task_id) { $perms = $AppUI->acl(); $q = $this->_query; if ($perms->checkModuleItem('tasks', 'edit', $task_id)) { if ($this->task_log_percent_complete < 100) { $q->addQuery('task_log_percent_complete, task_log_date, task_log_task_end_date'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_id); $q->addOrder('task_log_date DESC, task_log_id DESC'); $q->setLimit(1); $results = $q->loadHash(); $q->clear(); $percentComplete = $results['task_log_percent_complete']; /* * TODO: In theory, we shouldn't just use the task_log_task_end_date, * because if we're after that date and someone is still adding * logs to a task, obviously the task isn't complete. We may want * to check to see if task_log_date > task_log_task_end_date and * use the later one as the end date.. not sure yet. */ $taskEndDate = $results['task_log_task_end_date']; } else { $percentComplete = 100; $taskEndDate = $this->task_log_date; } $task = new CTask(); $task->load($task_id); $task->task_percent_complete = $percentComplete; $task->task_end_date = $taskEndDate; $msg = $task->store($AppUI); if (is_array($msg)) { $AppUI->setMsg($msg, UI_MSG_ERROR, true); } $task->pushDependencies($task_id, $task->task_end_date); } $q->addQuery('SUM(task_log_hours)'); $q->addTable('task_log'); $q->addWhere('task_log_task = ' . (int) $task_log_task); $totalHours = $q->loadResult(); CTask::updateHoursWorked($task_id, $totalHours); }