* code for task #65274.

This commit is contained in:
wangyidong
2022-08-23 15:19:35 +08:00
parent 19a2ef4ac8
commit 05d5d0054d
2 changed files with 110 additions and 59 deletions
+105 -50
View File
@@ -947,17 +947,63 @@ class taskModel extends model
*
* @param array $teams
* @param string $account
* @param string $filter
* @param array $extra
* @access public
* @return void
* @return object
*/
public function getTeamByAccount($teams, $account = '', $filter = 'done')
public function getTeamByAccount($teams, $account = '', $extra = array('filter' => 'done'))
{
if(empty($account)) $account = $this->app->user->account;
$filter = zget($extra, 'filter', '');
$effortID = zget($extra, 'effortID', '');
$duplicates = array();
$members = array();
$taskID = 0;
foreach($teams as $team)
{
if($filter and $team->status == $filter) continue;
if($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;
$members[$team->account] += 1;
}
/*
* 1. No duplicate account;
* 2. Account is not duplicate account;
* 3. Not by effort;
* Then direct get team by account.
*/
if(empty($duplicates) or (!isset($duplicates[$account])) or empty($effortID))
{
foreach($teams as $team)
{
if($filter and $team->status == $filter) continue;
if($team->account == $account) return $team;
}
}
elseif($effortID)
{
$efforts = $this->getTaskEstimate($taskID);
$prevTeam = null;
$thisTeam = null;
foreach($efforts as $effort)
{
$thisTeam = reset($teams);
if($effort->id == $effortID)
{
if($effort->account == $thisTeam->account) return $thisTeam;
if($effort->account == $prevTeam->account) return $prevTeam;
return false;
}
if(empty($currentEffort) and $effort->left == 0)
{
if($thisTeam->account == $effort->account) $prevTeam = array_shift($teams);
}
}
}
}
@@ -1660,12 +1706,7 @@ class taskModel extends model
$data->left = $this->post->left;
$data->status = 'doing';
$this->dao->update(TABLE_TASKTEAM)->data($data)->where('task')->eq($taskID)
->andWhere('account')->eq($currentTeam->account)
->andWhere('status')->ne('done')
->orderBy('`order`')
->limit(1)
->exec();
$this->dao->update(TABLE_TASKTEAM)->data($data)->where('id')->eq($currentTeam->id)->exec();
$task = $this->computeHours4Multiple($oldTask, $task);
@@ -1805,17 +1846,17 @@ class taskModel extends model
if(!empty($task->team))
{
$myConsumed = $task->team[$this->app->user->account]->consumed;
$currentTeam = $this->getTeamByAccount($task->team, $this->app->user->account);
if($currentTeam)
{
$newTeamInfo = new stdClass();
$newTeamInfo->consumed = $currentTeam->consumed + $consumed;
$newTeamInfo->left = $left;
$newTeamInfo->status = ($newTeamInfo->consumed > 0 and $left == 0) ? 'done' : 'doing';
$this->dao->update(TABLE_TASKTEAM)->data($newTeamInfo)->where('id')->eq($currentTeam->id)->exec();
$newTeamInfo = new stdClass();
$newTeamInfo->consumed = $myConsumed + $consumed;
$newTeamInfo->left = $left;
$this->dao->update(TABLE_TASKTEAM)->data($newTeamInfo)
->where('task')->eq($taskID)
->andWhere('account')->eq($this->app->user->account)
->exec();
$data = $this->computeHours4Multiple($task, $data);
$data = $this->computeHours4Multiple($task, $data);
}
}
$this->dao->update(TABLE_TASK)->data($data)->where('id')->eq($taskID)->exec();
@@ -1918,16 +1959,9 @@ class taskModel extends model
if($this->post->comment) $estimate->work = $this->post->comment;
if($estimate->consumed) $this->addTaskEstimate($estimate);
if(!empty($oldTask->team))
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('task')->eq((int)$taskID)
->andWhere('account')->eq($this->app->user->account)
->andWhere('status')->ne('done')
->orderBy('`order`')
->limit(1)
->exec();
$this->dao->update(TABLE_TASKTEAM)->set('left')->eq(0)->set('consumed')->eq($task->consumed)->set('status')->eq('done')->where('id')->eq($currentTeam->id)->exec();
$task = $this->computeHours4Multiple($oldTask, $task);
@@ -2714,6 +2748,27 @@ class taskModel extends model
return $estimate;
}
/**
* Check operate effort.
*
* @param object $task
* @param object $effort
* @access public
* @return bool
*/
public function canOperateEffort($task, $effort)
{
if(empty($task->team)) return true;
if($task->mode == 'linear')
{
if(strpos('|closed|cancel|pause|', "|{$task->status}|") !== false) return false;
if($task->status == 'doing') return $task->assignedTo == $effort->account;
}
if($this->app->user->account == $effort->account) return true;
return false;
}
/**
* Update estimate.
*
@@ -2756,17 +2811,17 @@ class taskModel extends model
if(!empty($task->team))
{
$oldConsumed = $task->team[$oldEstimate->account]->consumed;
$currentTeam = $this->getTeamByAccount($task->team, $oldEstimate->account, array('filter' => '', 'effortID' => $estimateID));
if($currentTeam)
{
$newTeamInfo = new stdClass();
$newTeamInfo->consumed = $currentTeam->consumed + $estimate->consumed - $oldEstimate->consumed;
if($currentTeam->status != 'done') $newTeamInfo->left = $left;
if($currentTeam->status != 'done' and $newTeamInfo->consumed > 0 and $left == 0) $newTeamInfo->status = 'done';
$this->dao->update(TABLE_TASKTEAM)->data($newTeamInfo)->where('id')->eq($currentTeam->id)->exec();
$newTeamInfo = new stdClass();
$newTeamInfo->consumed = $oldConsumed + $estimate->consumed - $oldEstimate->consumed;
$newTeamInfo->left = $left;
$this->dao->update(TABLE_TASKTEAM)->data($newTeamInfo)
->where('task')->eq($oldEstimate->task)
->andWhere('account')->eq($oldEstimate->account)
->exec();
$data = $this->computeHours4Multiple($task, $data);
$data = $this->computeHours4Multiple($task, $data);
}
}
$this->dao->update(TABLE_TASK)->data($data)->where('id')->eq($task->id)->exec();
@@ -2825,17 +2880,17 @@ class taskModel extends model
}
if(!empty($task->team))
{
$oldConsumed = $task->team[$estimate->account]->consumed;
$currentTeam = $this->getTeamByAccount($task->team, $oldEstimate->account, array('filter' => '', 'effortID' => $estimateID));
if($currentTeam)
{
$newTeamInfo = new stdClass();
$newTeamInfo->consumed = $currentTeam->consumed - $estimate->consumed;
if($currentTeam->status != 'done') $newTeamInfo->left = $left;
if($currentTeam->status != 'done' and $newTeamInfo->consumed > 0 and $left == 0) $newTeamInfo->status = 'done';
$this->dao->update(TABLE_TASKTEAM)->data($newTeamInfo)->where('id')->eq($currentTeam->id)->exec();
$newTeamInfo = new stdClass();
$newTeamInfo->consumed = $oldConsumed - $estimate->consumed;
$newTeamInfo->left = $left;
$this->dao->update(TABLE_TASKTEAM)->data($newTeamInfo)
->where('task')->eq($estimate->task)
->andWhere('account')->eq($estimate->account)
->exec();
$data = $this->computeHours4Multiple($task, $data);
$data = $this->computeHours4Multiple($task, $data);
}
}
$this->dao->update(TABLE_TASK)->data($data) ->where('id')->eq($estimate->task)->exec();
+5 -9
View File
@@ -45,7 +45,7 @@
<th class="thWidth"><?php echo $lang->task->consumed;?></th>
<th class="thWidth"><?php echo $lang->task->left;?></th>
<th><?php echo $lang->comment;?></th>
<th class='c-actions-2'><?php if(empty($members) or $task->assignedTo == $this->app->user->account or ($task->mode == 'multi' and isset($members[$app->user->account]))) echo $lang->actions;?></th>
<th class='c-actions-2'><?php echo $lang->actions;?></th>
</tr>
</thead>
<tbody>
@@ -57,21 +57,17 @@
<td title="<?php echo $estimate->consumed . ' ' . $lang->execution->workHour;?>"><?php echo $estimate->consumed . ' ' . $lang->execution->workHourUnit;?></td>
<td title="<?php echo $estimate->left . ' ' . $lang->execution->workHour;?>"><?php echo $estimate->left . ' ' . $lang->execution->workHourUnit;?></td>
<td class="text-left" title="<?php echo $estimate->work;?>"><?php echo $estimate->work;?></td>
<?php if(empty($members) or $task->assignedTo == $this->app->user->account or ($task->mode == 'multi' and isset($members[$app->user->account]))):?>
<td align='center' class='c-actions'>
<?php
if($this->app->user->account == $estimate->account)
{
common::printIcon('task', 'editEstimate', "estimateID=$estimate->id", '', 'list', 'pencil', '', 'showinonlybody', true);
common::printIcon('task', 'deleteEstimate', "estimateID=$estimate->id", '', 'list', 'close', 'hiddenwin', 'showinonlybody');
}
$canOperateEffort = $this->task->canOperateEffort($task, $estimate);
common::printIcon('task', 'editEstimate', "estimateID=$estimate->id", '', 'list', 'pencil', '', 'showinonlybody', true, $canOperateEffort ? '' : 'disabled');
common::printIcon('task', 'deleteEstimate', "estimateID=$estimate->id", '', 'list', 'close', 'hiddenwin', 'showinonlybody', false, ($canOperateEffort and $estimate->left > 0) ? '' : 'disabled');
?>
</td>
</tr>
<?php endif;?>
<?php endforeach;?>
<?php endif;?>
<?php if(!empty($members) and (!isset($members[$app->user->account]) or ($task->assignedTo != $app->user->account and $task->mode == 'linear'))):?>
<?php if(!empty($members) and (!isset($members[$app->user->account]) or ($task->assignedTo != $app->user->account and $task->mode == 'linear'))):?>
</tbody>
</table>
</form>