* Compute begin and end for parent task by his children, finish task #4627.
This commit is contained in:
+52
-4
@@ -259,7 +259,11 @@ class taskModel extends model
|
||||
}
|
||||
|
||||
if(!dao::isError()) $this->loadModel('score')->create('ajax', 'batchCreate');
|
||||
if($parentID && !empty($taskID)) $this->updateParentStatus($taskID);
|
||||
if($parentID && !empty($taskID))
|
||||
{
|
||||
$this->updateParentStatus($taskID);
|
||||
$this->computeBeginAndEnd($parentID);
|
||||
}
|
||||
return $mails;
|
||||
}
|
||||
|
||||
@@ -297,6 +301,37 @@ class taskModel extends model
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute begin and end for parent task.
|
||||
*
|
||||
* @param int $taskID
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function computeBeginAndEnd($taskID)
|
||||
{
|
||||
$tasks = $this->dao->select('estStarted, realStarted, deadline')->from(TABLE_TASK)->where('parent')->eq($taskID)->andWhere('status')->ne('cancel')->andWhere('deleted')->eq(0)->fetchAll();
|
||||
if(empty($tasks)) return true;
|
||||
|
||||
foreach($tasks as $task)
|
||||
{
|
||||
$estStarted = formatTime($task->estStarted);
|
||||
$realStarted = formatTime($task->realStarted);
|
||||
$deadline = formatTime($task->deadline);
|
||||
if(!isset($earliestEstStarted) or (!empty($estStarted) and $earliestEstStarted > $estStarted)) $earliestEstStarted = $estStarted;
|
||||
if(!isset($earliestRealStarted) or (!empty($realStarted) and $earliestRealStarted > $realStarted)) $earliestRealStarted = $realStarted;
|
||||
if(!isset($latestDeadline) or (!empty($deadline) and $latestDeadline < $deadline)) $latestDeadline = $deadline;
|
||||
}
|
||||
|
||||
$newTask = new stdClass();
|
||||
$newTask->estStarted = $earliestEstStarted;
|
||||
$newTask->realStarted = $earliestRealStarted;
|
||||
$newTask->deadline = $latestDeadline;
|
||||
$this->dao->update(TABLE_TASK)->data($newTask)->autoCheck()->where('id')->eq($taskID)->exec();
|
||||
|
||||
return !dao::isError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update parent status by taskID.
|
||||
*
|
||||
@@ -593,7 +628,11 @@ class taskModel extends model
|
||||
->batchCheckIF($task->closedReason == 'cancel', 'finishedBy, finishedDate', 'empty')
|
||||
->where('id')->eq((int)$taskID)->exec();
|
||||
|
||||
if($oldTask->parent) $this->updateParentStatus($taskID);
|
||||
if($oldTask->parent)
|
||||
{
|
||||
$this->updateParentStatus($taskID);
|
||||
$this->computeBeginAndEnd($oldTask->parent);
|
||||
}
|
||||
|
||||
if($this->post->story != false) $this->loadModel('story')->setStage($this->post->story);
|
||||
if(!dao::isError())
|
||||
@@ -760,7 +799,12 @@ class taskModel extends model
|
||||
if($oldTask->story != false) $this->loadModel('story')->setStage($oldTask->story);
|
||||
if(!dao::isError())
|
||||
{
|
||||
if($oldTask->parent) $this->updateParentStatus($oldTask->id);
|
||||
if($oldTask->parent)
|
||||
{
|
||||
$this->updateParentStatus($oldTask->id);
|
||||
$this->computeBeginAndEnd($oldTask->parent);
|
||||
}
|
||||
|
||||
if($task->status == 'done') $this->loadModel('score')->create('task', 'finish', $taskID);
|
||||
if($task->status == 'closed') $this->loadModel('score')->create('task', 'close', $taskID);
|
||||
$allChanges[$taskID] = common::createChanges($oldTask, $task);
|
||||
@@ -924,7 +968,11 @@ class taskModel extends model
|
||||
->check('consumed,left', 'float')
|
||||
->where('id')->eq((int)$taskID)->exec();
|
||||
|
||||
if($oldTask->parent) $this->updateParentStatus($taskID);
|
||||
if($oldTask->parent)
|
||||
{
|
||||
$this->updateParentStatus($taskID);
|
||||
$this->computeBeginAndEnd($oldTask->parent);
|
||||
}
|
||||
if($oldTask->story) $this->loadModel('story')->setStage($oldTask->story);
|
||||
if(!dao::isError()) return common::createChanges($oldTask, $task);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user