* fix bug #27198
This commit is contained in:
+110
-51
@@ -486,17 +486,10 @@ class taskModel extends model
|
||||
|
||||
$clonedTaskID = $this->dao->lastInsertID();
|
||||
|
||||
/* Update the table by judging the beginning of the version number. */
|
||||
if(preg_match('/^\d/', $this->config->version))
|
||||
{
|
||||
/* ZenTao Pms update TABLE_TASKESTIMATE. */
|
||||
$this->dao->update(TABLE_TASKESTIMATE)->set('task')->eq($clonedTaskID)->where('task')->eq($oldParentTask->id)->exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* ZenTao Pro and ZenTao Biz update TABLE_EFFORT. */
|
||||
$this->dao->update(TABLE_EFFORT)->set('objectID')->eq($clonedTaskID)->where('objectID')->eq($oldParentTask->id)->exec();
|
||||
}
|
||||
$this->dao->update(TABLE_EFFORT)->set('objectID')->eq($clonedTaskID)
|
||||
->where('objectID')->eq($oldParentTask->id)
|
||||
->andWhere('objectType')->eq('task')
|
||||
->exec();
|
||||
}
|
||||
|
||||
$this->updateParentStatus($taskID);
|
||||
@@ -981,6 +974,8 @@ class taskModel extends model
|
||||
$taskID = 0;
|
||||
foreach($teams as $team)
|
||||
{
|
||||
if(isset($extra['order']) and $team->order == $extra['order'] and $team->account == $account) return $team;
|
||||
|
||||
if(empty($taskID)) $taskID = $team->task;
|
||||
if(isset($members[$team->account])) $duplicates[$team->account] = $team->account;
|
||||
if(!isset($members[$team->account])) $members[$team->account] = 0;
|
||||
@@ -1247,8 +1242,23 @@ class taskModel extends model
|
||||
unset($oldTask->parent);
|
||||
unset($task->parent);
|
||||
|
||||
|
||||
if(($this->config->edition == 'biz' || $this->config->edition == 'max') && $oldTask->feedback) $this->loadModel('feedback')->updateStatus('task', $oldTask->feedback, $task->status, $oldTask->status);
|
||||
|
||||
if(isset($oldTask->team))
|
||||
{
|
||||
$users = $this->loadModel('user')->getPairs('noletter|noempty');
|
||||
$oldTeams = $oldTask->team;
|
||||
$oldTask->team = '';
|
||||
foreach($oldTeams as $team) $oldTask->team .= "{$this->lang->task->teamMember}: " . zget($users, $team->account) . ", {$this->lang->task->estimateAB}: " . (float)$team->estimate . ", {$this->lang->task->consumedAB}: " . (float)$team->consumed . ", {$this->lang->task->leftAB}: " . (float)$team->left . "\n";
|
||||
$task->team = '';
|
||||
foreach($this->post->team as $i => $account)
|
||||
{
|
||||
if(empty($account)) continue;
|
||||
$task->team .= "{$this->lang->task->teamMember}: " . zget($users, $account) . ", {$this->lang->task->estimateAB}: " . zget($this->post->teamEstimate, $i, 0) . ", {$this->lang->task->consumedAB}: " . zget($this->post->teamConsumed, $i, 0) . ", {$this->lang->task->leftAB}: " . zget($this->post->teamLeft, $i, 0) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return common::createChanges($oldTask, $task);
|
||||
}
|
||||
}
|
||||
@@ -1724,7 +1734,7 @@ class taskModel extends model
|
||||
$estimate->account = $this->app->user->account;
|
||||
$estimate->consumed = (!empty($oldTask->team) and $currentTeam) ? $estimate->consumed - $currentTeam->consumed : $estimate->consumed - $oldTask->consumed;
|
||||
if($this->post->comment) $estimate->work = $this->post->comment;
|
||||
$this->addTaskEstimate($estimate);
|
||||
$estimateID = $this->addTaskEstimate($estimate);
|
||||
|
||||
if(!empty($oldTask->team) and $currentTeam)
|
||||
{
|
||||
@@ -1734,6 +1744,7 @@ class taskModel extends model
|
||||
$data->status = 'doing';
|
||||
|
||||
$this->dao->update(TABLE_TASKTEAM)->data($data)->where('id')->eq($currentTeam->id)->exec();
|
||||
if($oldTask->mode == 'linear') $this->updateEstimateOrder($estimateID, $currentTeam->order);
|
||||
|
||||
$task = $this->computeHours4Multiple($oldTask, $task);
|
||||
|
||||
@@ -1812,6 +1823,7 @@ class taskModel extends model
|
||||
$estimates[$id]->left = $record->left[$id];
|
||||
$estimates[$id]->work = $record->work[$id];
|
||||
$estimates[$id]->account = $this->app->user->account;
|
||||
if(isset($record->order[$id])) $estimates[$id]->order = $record->order[$id];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1823,7 +1835,7 @@ class taskModel extends model
|
||||
$left = $task->left;
|
||||
$now = helper::now();
|
||||
$oldStatus = $task->status;
|
||||
$lastDate = $this->dao->select('*')->from(TABLE_TASKESTIMATE)->where('task')->eq($taskID)->orderBy('date_desc,id_desc')->limit(1)->fetch('date');
|
||||
$lastDate = $this->dao->select('*')->from(TABLE_EFFORT)->where('objectID')->eq($taskID)->andWhere('objectType')->eq('task')->orderBy('date_desc,id_desc')->limit(1)->fetch('date');
|
||||
|
||||
foreach($estimates as $estimate)
|
||||
{
|
||||
@@ -1844,7 +1856,14 @@ class taskModel extends model
|
||||
$lastDate = $estimate->date;
|
||||
}
|
||||
|
||||
if($newTask->left == 0 and strpos('done,cancel,closed', $task->status) === false)
|
||||
if(!empty($task->team))
|
||||
{
|
||||
$extra = array('filter' => 'done');
|
||||
if(isset($estimate->order)) $extra['order'] = $estimate->order;
|
||||
$currentTeam = $this->getTeamByAccount($task->team, $this->app->user->account, $extra);
|
||||
}
|
||||
|
||||
if($newTask->left == 0 and ((empty($currentTeam) and strpos('done,cancel,closed', $task->status) === false) or (!empty($currentTeam) and $currentTeam->status != 'done')))
|
||||
{
|
||||
$newTask->status = 'done';
|
||||
$newTask->assignedTo = $task->openedBy;
|
||||
@@ -1881,11 +1900,11 @@ class taskModel extends model
|
||||
/* Process multi-person task. Update consumed on team table. */
|
||||
if(!empty($task->team))
|
||||
{
|
||||
$currentTeam = $this->getTeamByAccount($task->team, $this->app->user->account);
|
||||
if($currentTeam)
|
||||
if(!empty($currentTeam))
|
||||
{
|
||||
$teamStatus = $estimate->left == 0 ? 'done' : 'doing';
|
||||
$this->dao->update(TABLE_TASKTEAM)->set('left')->eq($estimate->left)->set("consumed = consumed + {$estimate->consumed}")->set('status')->eq($teamStatus)->where('id')->eq($currentTeam->id)->exec();
|
||||
if($task->mode == 'linear' and empty($estimate->order)) $this->updateEstimateOrder($estimateID, $currentTeam->order);
|
||||
$currentTeam->consumed += $estimate->consumed;
|
||||
$currentTeam->left = $estimate->left;
|
||||
$currentTeam->status = $teamStatus;
|
||||
@@ -1923,13 +1942,16 @@ class taskModel extends model
|
||||
*/
|
||||
public function resetEffortLeft($taskID, $members)
|
||||
{
|
||||
$table = $this->config->edition == 'open' ? TABLE_TASKESTIMATE : TABLE_EFFORT;
|
||||
$this->dao->update($table)->set('`left`')->eq(0)->where('account')->in($members)
|
||||
->beginIF($this->config->edition == 'open')->andWhere('task')->eq($taskID)->fi()
|
||||
->beginIF($this->config->edition != 'open')->andWhere('objectID')->eq($taskID)->andWhere('objectType')->eq('task')->fi()
|
||||
->orderBy('date_desc,id_desc')
|
||||
->limit('1')
|
||||
->exec();
|
||||
foreach($members as $account)
|
||||
{
|
||||
$this->dao->update(TABLE_EFFORT)->set('`left`')->eq(0)
|
||||
->where('account')->eq($account)
|
||||
->andWhere('objectID')->eq($taskID)
|
||||
->andWhere('objectType')->eq('task')
|
||||
->orderBy('date_desc,id_desc')
|
||||
->limit('1')
|
||||
->exec();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1998,11 +2020,12 @@ class taskModel extends model
|
||||
$estimate->account = $this->app->user->account;
|
||||
$estimate->consumed = $consumed;
|
||||
if($this->post->comment) $estimate->work = $this->post->comment;
|
||||
if($estimate->consumed) $this->addTaskEstimate($estimate);
|
||||
if($estimate->consumed) $estimateID = $this->addTaskEstimate($estimate);
|
||||
|
||||
if(!empty($oldTask->team) and $currentTeam)
|
||||
{
|
||||
$this->dao->update(TABLE_TASKTEAM)->set('left')->eq(0)->set('consumed')->eq($task->consumed)->set('status')->eq('done')->where('id')->eq($currentTeam->id)->exec();
|
||||
if($oldTask->mode == 'linear' and isset($estimateID)) $this->updateEstimateOrder($estimateID, $currentTeam->order);
|
||||
$task = $this->computeHours4Multiple($oldTask, $task);
|
||||
}
|
||||
|
||||
@@ -2141,10 +2164,11 @@ class taskModel extends model
|
||||
->setDefault('assignedTo', $oldTask->openedBy)
|
||||
->setDefault('assignedDate', $now)
|
||||
->setDefault('finishedBy', '')
|
||||
->setDefault('finishedDate', '0000-00-00')
|
||||
->setDefault('finishedDate', '0000-00-00 00:00:00')
|
||||
->setDefault('canceledBy, lastEditedBy', $this->app->user->account)
|
||||
->setDefault('canceledDate, lastEditedDate', $now)
|
||||
->stripTags($this->config->task->editor->cancel['id'], $this->config->allowedTags)
|
||||
->setIF(empty($oldTask->finishedDate), 'finishedDate', '')
|
||||
->remove('comment')
|
||||
->get();
|
||||
|
||||
@@ -2205,12 +2229,15 @@ class taskModel extends model
|
||||
->setDefault('left', 0)
|
||||
->setDefault('status', 'doing')
|
||||
->setDefault('finishedBy, canceledBy, closedBy, closedReason', '')
|
||||
->setDefault('finishedDate, canceledDate, closedDate', '0000-00-00')
|
||||
->setDefault('finishedDate, canceledDate, closedDate', '0000-00-00 00:00:00')
|
||||
->setDefault('lastEditedBy', $this->app->user->account)
|
||||
->setDefault('lastEditedDate', helper::now())
|
||||
->setDefault('assignedDate', helper::now())
|
||||
->setDefault('activatedDate', helper::now())
|
||||
->stripTags($this->config->task->editor->activate['id'], $this->config->allowedTags)
|
||||
->setIF(empty($oldTask->finishedDate), 'finishedDate', '')
|
||||
->setIF(empty($oldTask->canceledDate), 'canceledDate', '')
|
||||
->setIF(empty($oldTask->closedDate), 'closedDate', '')
|
||||
->remove('comment,uid,multiple,team,teamEstimate,teamConsumed,teamLeft,teamSource')
|
||||
->get();
|
||||
|
||||
@@ -2741,50 +2768,59 @@ class taskModel extends model
|
||||
return $taskCounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update estimate order for linear task team.
|
||||
*
|
||||
* @param int $effortID
|
||||
* @param int $order
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateEstimateOrder($effortID, $order)
|
||||
{
|
||||
$this->dao->update(TABLE_EFFORT)->set('`order`')->eq((int)$order)->where('id')->eq($effortID)->exec();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get task estimate.
|
||||
*
|
||||
* @param int $taskID
|
||||
* @param string $account
|
||||
* @param string $append
|
||||
* @param string $orderBy
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getTaskEstimate($taskID, $account = '', $append = '')
|
||||
public function getTaskEstimate($taskID, $account = '', $append = '', $orderBy = 'date,id')
|
||||
{
|
||||
if($this->config->edition == 'open')
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_TASKESTIMATE)
|
||||
->where('task')->eq($taskID)
|
||||
->beginIF($account)->andWhere('account')->eq($account)->fi()
|
||||
->beginIF($append)->orWhere('id')->eq($append)->fi()
|
||||
->orderBy('date,id')
|
||||
->fetchAll();
|
||||
}
|
||||
return $this->dao->select('*')->from(TABLE_EFFORT)->where('objectID')->eq($taskID)
|
||||
->andWhere('objectType')->eq('task')
|
||||
->andWhere('deleted')->eq('0')
|
||||
->beginIF($account)->andWhere('account')->eq($account)->fi()
|
||||
->beginIF($append)->orWhere('id')->eq($append)->fi()
|
||||
->orderBy('date,id')
|
||||
->orderBy($orderBy)
|
||||
->fetchAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get estimate by id.
|
||||
*
|
||||
* @param int $estimateID
|
||||
* @param int $effortID
|
||||
* @access public
|
||||
* @return object.
|
||||
*/
|
||||
public function getEstimateById($estimateID)
|
||||
public function getEstimateById($effortID)
|
||||
{
|
||||
$estimate = $this->dao->select('*')->from(TABLE_TASKESTIMATE)
|
||||
->where('id')->eq($estimateID)
|
||||
$estimate = $this->dao->select('*')->from(TABLE_EFFORT)
|
||||
->where('id')->eq($effortID)
|
||||
->fetch();
|
||||
|
||||
/* If the estimate is the last of its task, status of task will be checked. */
|
||||
$lastID = $this->dao->select('id')->from(TABLE_TASKESTIMATE)->where('task')->eq($estimate->task)->orderBy('date_desc,id_desc')->limit(1)->fetch('id');
|
||||
$lastID = $this->dao->select('id')->from(TABLE_EFFORT)
|
||||
->where('objectID')->eq($estimate->objectID)
|
||||
->andWhere('objectType')->eq('task')
|
||||
->orderBy('date_desc,id_desc')->limit(1)->fetch('id');
|
||||
|
||||
$estimate->isLast = $lastID == $estimate->id;
|
||||
return $estimate;
|
||||
}
|
||||
@@ -2804,7 +2840,6 @@ class taskModel extends model
|
||||
/* Check for add effort. */
|
||||
if(empty($effort))
|
||||
{
|
||||
if($task->mode == 'linear' and strpos('|done|closed|cancel|pause|', "|{$task->status}|") !== false) return false;
|
||||
$members = array_map(function($member){ return $member->account; }, $task->team);
|
||||
if(!in_array($this->app->user->account, $members)) return false;
|
||||
if($task->mode == 'linear' and $this->app->user->account != $task->assignedTo) return false;
|
||||
@@ -2839,14 +2874,17 @@ class taskModel extends model
|
||||
if($estimate->left < 0) return dao::$errors[] = sprintf($this->lang->error->ge, $this->lang->task->left, '0');
|
||||
|
||||
$task = $this->getById($oldEstimate->task);
|
||||
$this->dao->update(TABLE_TASKESTIMATE)->data($estimate)
|
||||
$this->dao->update(TABLE_EFFORT)->data($estimate)
|
||||
->autoCheck()
|
||||
->where('id')->eq((int)$estimateID)
|
||||
->exec();
|
||||
|
||||
$consumed = $task->consumed + $estimate->consumed - $oldEstimate->consumed;
|
||||
$lastEstimate = $this->dao->select('*')->from(TABLE_TASKESTIMATE)->where('task')->eq($task->id)->orderBy('date_desc,id_desc')->limit(1)->fetch();
|
||||
$left = ($lastEstimate and $estimateID == $lastEstimate->id) ? $estimate->left : $task->left;
|
||||
$lastEstimate = $this->dao->select('*')->from(TABLE_EFFORT)
|
||||
->where('objectID')->eq($task->id)
|
||||
->andWhere('objectType')->eq('task')
|
||||
->orderBy('date_desc,id_desc')->limit(1)->fetch();
|
||||
|
||||
$now = helper::now();
|
||||
$data = new stdClass();
|
||||
@@ -2865,7 +2903,7 @@ class taskModel extends model
|
||||
|
||||
if(!empty($task->team))
|
||||
{
|
||||
$currentTeam = $this->getTeamByAccount($task->team, $oldEstimate->account, array('effortID' => $estimateID));
|
||||
$currentTeam = $this->getTeamByAccount($task->team, $oldEstimate->account, array('order' => $oldEstimate->order));
|
||||
if($currentTeam)
|
||||
{
|
||||
$newTeamInfo = new stdClass();
|
||||
@@ -2915,7 +2953,10 @@ class taskModel extends model
|
||||
$left = $task->left;
|
||||
if($estimate->isLast)
|
||||
{
|
||||
$lastTwoEstimates = $this->dao->select('*')->from(TABLE_TASKESTIMATE)->where('task')->eq($estimate->task)->orderBy('date desc,id desc')->limit(2)->fetchAll();
|
||||
$lastTwoEstimates = $this->dao->select('*')->from(TABLE_EFFORT)
|
||||
->where('objectID')->eq($estimate->task)
|
||||
->andWhere('objectType')->eq('task')
|
||||
->orderBy('date desc,id desc')->limit(2)->fetchAll();
|
||||
$lastTwoEstimate = isset($lastTwoEstimates[1]) ? $lastTwoEstimates[1] : '';
|
||||
if($lastTwoEstimate) $left = $lastTwoEstimate->left;
|
||||
if(empty($lastTwoEstimate) and $left == 0) $left = $task->estimate;
|
||||
@@ -2951,7 +2992,7 @@ class taskModel extends model
|
||||
|
||||
if(!empty($task->team))
|
||||
{
|
||||
$currentTeam = $this->getTeamByAccount($task->team, $estimate->account, array('effortID' => $estimateID));
|
||||
$currentTeam = $this->getTeamByAccount($task->team, $estimate->account, array('effortID' => $estimateID, 'order' => $estimate->order));
|
||||
if($currentTeam)
|
||||
{
|
||||
$left = $currentTeam->left;
|
||||
@@ -2982,7 +3023,7 @@ class taskModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
$this->dao->delete()->from(TABLE_TASKESTIMATE)->where('id')->eq($estimateID)->exec();
|
||||
$this->dao->update(TABLE_EFFORT)->set('deleted')->eq('1')->where('id')->eq($estimateID)->exec();
|
||||
if(!empty($task->team)) $data = $this->computeHours4Multiple($task, $data);
|
||||
|
||||
$this->dao->update(TABLE_TASK)->data($data) ->where('id')->eq($estimate->task)->exec();
|
||||
@@ -3555,11 +3596,29 @@ class taskModel extends model
|
||||
*
|
||||
* @param object $data
|
||||
* @access public
|
||||
* @return void
|
||||
* @return int
|
||||
*/
|
||||
public function addTaskEstimate($data)
|
||||
{
|
||||
$this->dao->insert(TABLE_TASKESTIMATE)->data($data)->autoCheck()->exec();
|
||||
$oldTask = $this->getById($data->task);
|
||||
|
||||
$relation = $this->loadModel('action')->getRelatedFields('task', $data->task);
|
||||
|
||||
$effort = new stdclass();
|
||||
$effort->objectType = 'task';
|
||||
$effort->objectID = $data->task;
|
||||
$effort->execution = $oldTask->execution;
|
||||
$effort->product = $relation['product'];
|
||||
$effort->project = (int)$relation['project'];
|
||||
$effort->account = $data->account;
|
||||
$effort->date = $data->date;
|
||||
$effort->consumed = $data->consumed;
|
||||
$effort->left = $data->left;
|
||||
$effort->work = isset($data->work) ? $data->work : '';
|
||||
$effort->vision = $this->config->vision;
|
||||
$this->dao->insert(TABLE_EFFORT)->data($effort)->autoCheck()->exec();
|
||||
|
||||
return $this->dao->lastInsertID();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user