From f744959a7cf59a4516fb1eebe4d3d713d8e44ddb Mon Sep 17 00:00:00 2001 From: tianshujie Date: Mon, 4 Sep 2023 16:56:26 +0800 Subject: [PATCH] * Refactor grouptask method. --- module/execution/control.php | 172 +++------------------------------ module/execution/zen.php | 181 +++++++++++++++++++++++++++++++++++ 2 files changed, 196 insertions(+), 157 deletions(-) diff --git a/module/execution/control.php b/module/execution/control.php index 5ff5da8708..c94d3473da 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -182,22 +182,23 @@ class execution extends control } /** + * 任务分组视图。 * Browse tasks in group. * * @param int $executionID - * @param string $groupBy the field to group by + * @param string $groupBy story|status|pri|assignedTo|finishedBy|closedBy|type * @param string $filter * @access public * @return void */ - public function grouptask($executionID = 0, $groupBy = 'story', $filter = '') + public function grouptask(int $executionID = 0, string $groupBy = 'story', string $filter = '') { $execution = $this->commonAction($executionID); $executionID = $execution->id; - /* Get tasks and group them. */ + /* Execution of the ops type don't show group by story. */ if(empty($groupBy))$groupBy = 'story'; - if($groupBy == 'story' and $execution->lifetime == 'ops') + if($groupBy == 'story' && $execution->lifetime == 'ops') { $groupBy = 'status'; unset($this->lang->execution->groups['story']); @@ -206,189 +207,46 @@ class execution extends control $sort = common::appendOrder($groupBy); $tasks = $this->loadModel('task')->getExecutionTasks($executionID, 0, 'all', array(), $sort); $groupBy = str_replace('`', '', $groupBy); - $taskLang = $this->lang->task; - $groupByList = array(); $groupTasks = array(); - - $groupTasks = array(); - $allCount = 0; + $groupByList = array(); + $allCount = 0; foreach($tasks as $task) { if($task->mode == 'multi') $task->assignedToRealName = $this->lang->task->team; $groupTasks[] = $task; - $allCount++; + $allCount ++; if(isset($task->children)) { foreach($task->children as $child) { $groupTasks[] = $child; - $allCount++; + $allCount ++; } $task->children = true; unset($task->children); } } - /* Get users. */ - $users = $this->loadModel('user')->getPairs('noletter'); - $tasks = $groupTasks; - $groupTasks = array(); - foreach($tasks as $task) - { - if($groupBy == 'story') - { - $groupTasks[$task->story][] = $task; - $groupByList[$task->story] = $task->storyTitle; - } - elseif($groupBy == 'status') - { - $groupTasks[$taskLang->statusList[$task->status]][] = $task; - } - elseif($groupBy == 'assignedTo') - { - if(isset($task->team)) - { - foreach($task->team as $team) - { - $cloneTask = clone $task; - $cloneTask->assignedTo = $team->account; - $cloneTask->estimate = $team->estimate; - $cloneTask->consumed = $team->consumed; - $cloneTask->left = $team->left; - if($team->left == 0) $cloneTask->status = 'done'; - - $realname = zget($users, $team->account); - $cloneTask->assignedToRealName = $realname; - $groupTasks[$realname][] = $cloneTask; - } - } - else - { - $groupTasks[$task->assignedToRealName][] = $task; - } - } - elseif($groupBy == 'finishedBy') - { - if(isset($task->team)) - { - $task->consumed = $task->estimate = $task->left = 0; - foreach($task->team as $team) - { - if($team->left != 0) - { - $task->estimate += $team->estimate; - $task->consumed += $team->consumed; - $task->left += $team->left; - continue; - } - - $cloneTask = clone $task; - $cloneTask->finishedBy = $team->account; - $cloneTask->estimate = $team->estimate; - $cloneTask->consumed = $team->consumed; - $cloneTask->left = $team->left; - $cloneTask->status = 'done'; - $realname = zget($users, $team->account); - $groupTasks[$realname][] = $cloneTask; - } - if(!empty($task->left)) $groupTasks[$users[$task->finishedBy]][] = $task; - } - else - { - $groupTasks[$users[$task->finishedBy]][] = $task; - } - } - elseif($groupBy == 'closedBy') - { - $groupTasks[$users[$task->closedBy]][] = $task; - } - elseif($groupBy == 'type') - { - $groupTasks[$taskLang->typeList[$task->type]][] = $task; - } - else - { - $groupTasks[$task->$groupBy][] = $task; - } - } - /* Process closed data when group by assignedTo. */ - if($groupBy == 'assignedTo' and isset($groupTasks['Closed'])) - { - $closedTasks = $groupTasks['Closed']; - unset($groupTasks['Closed']); - $groupTasks['closed'] = $closedTasks; - } + /* Get users and build task group data. */ + $users = $this->loadModel('user')->getPairs('noletter'); + $tasks = $groupTasks; + $groupTasks = $this->executionZen->buildGroupTasks($groupBy, $groupTasks, $users); /* Remove task by filter and group. */ - $filter = (empty($filter) and isset($this->lang->execution->groupFilter[$groupBy])) ? key($this->lang->execution->groupFilter[$groupBy]) : $filter; - if($filter != 'all') - { - if($groupBy == 'story' and $filter == 'linked' and isset($groupTasks[0])) - { - $allCount -= count($groupTasks[0]); - unset($groupTasks[0]); - } - elseif($groupBy == 'pri' and $filter == 'noset') - { - foreach($groupTasks as $pri => $tasks) - { - if($pri) - { - $allCount -= count($tasks); - unset($groupTasks[$pri]); - } - } - } - elseif($groupBy == 'assignedTo' and $filter == 'undone') - { - $multiTaskCount = array(); - foreach($groupTasks as $assignedTo => $tasks) - { - foreach($tasks as $i => $task) - { - if($task->status != 'wait' and $task->status != 'doing') - { - if($task->mode == 'multi') - { - if(!isset($multiTaskCount[$task->id])) - { - $multiTaskCount[$task->id] = true; - $allCount -= 1; - } - } - else - { - $allCount -= 1; - } - - unset($groupTasks[$assignedTo][$i]); - } - } - } - } - elseif(($groupBy == 'finishedBy' or $groupBy == 'closedBy') and isset($tasks[''])) - { - $allCount -= count($tasks['']); - unset($tasks['']); - } - } + $filter = (empty($filter) && isset($this->lang->execution->groupFilter[$groupBy])) ? key($this->lang->execution->groupFilter[$groupBy]) : $filter; + list($groupTasks, $allCount) = $this->executionZen->filterGroupTasks($groupTasks, $groupBy, $filter, $allCount, $tasks); /* Assign. */ - $this->app->loadLang('tree'); - $this->view->title = $execution->name . $this->lang->colon . $this->lang->execution->task; $this->view->members = $this->execution->getTeamMembers($executionID); $this->view->tasks = $groupTasks; - $this->view->tabID = 'task'; $this->view->groupByList = $groupByList; $this->view->browseType = 'group'; $this->view->groupBy = $groupBy; $this->view->orderBy = $groupBy; $this->view->executionID = $executionID; $this->view->users = $users; - $this->view->moduleID = 0; - $this->view->moduleName = $this->lang->tree->all; $this->view->features = $this->execution->getExecutionFeatures($execution); $this->view->filter = $filter; $this->view->allCount = $allCount; diff --git a/module/execution/zen.php b/module/execution/zen.php index a2a02b3fe4..bf69bde3d2 100644 --- a/module/execution/zen.php +++ b/module/execution/zen.php @@ -218,6 +218,118 @@ class executionZen extends execution $this->view->statData = $this->execution->statRelatedData($executionID); } + /** + * 构造任务分组视图数据。 + * Build task group data. + * + * @param string $groupBy story|status|pri|assignedTo|finishedBy|closedBy|type + * @param array $tasks + * @param array $users + * @access protected + * @return array + */ + protected function buildGroupTasks(string $groupBy = 'story', array $tasks, array $users): array + { + $groupTasks = array(); + foreach($tasks as $task) + { + if($groupBy == 'story') + { + $groupTasks[$task->story][] = $task; + $groupByList[$task->story] = $task->storyTitle; + } + elseif($groupBy == 'status') + { + $groupTasks[$this->lang->task->statusList[$task->status]][] = $task; + } + elseif($groupBy == 'assignedTo') + { + if(isset($task->team)) + { + $groupTasks = $this->buildGroupMultiTask($groupBy, $task, $users, $groupTasks); + } + else + { + $groupTasks[$task->assignedToRealName][] = $task; + } + } + elseif($groupBy == 'finishedBy') + { + if(isset($task->team)) + { + $task->consumed = $task->estimate = $task->left = 0; + $groupTasks = $this->buildGroupMultiTask($groupBy, $task, $users, $groupTasks); + } + else + { + $groupTasks[$users[$task->finishedBy]][] = $task; + } + } + elseif($groupBy == 'closedBy') + { + $groupTasks[$users[$task->closedBy]][] = $task; + } + elseif($groupBy == 'type') + { + $groupTasks[$this->lang->task->typeList[$task->type]][] = $task; + } + else + { + $groupTasks[$task->$groupBy][] = $task; + } + } + + /* Process closed data when group by assignedTo. */ + if($groupBy == 'assignedTo' && isset($groupTasks['Closed'])) + { + $closedTasks = $groupTasks['Closed']; + unset($groupTasks['Closed']); + $groupTasks['closed'] = $closedTasks; + } + + return $groupTasks; + } + + /** + * 构建多人任务的分组视图数据。 + * Build group data for multiple task. + * + * @param string $groupBy + * @param object $task + * @param array $users + * @param array $groupTasks + * @access protected + * @return array + */ + protected function buildGroupMultiTask(string $groupBy, object $task, array $users, array $groupTasks): array + { + foreach($task->team as $team) + { + if($team->left != 0 && $groupBy == 'finishedBy') + { + $task->estimate += $team->estimate; + $task->consumed += $team->consumed; + $task->left += $team->left; + continue; + } + + $cloneTask = clone $task; + $cloneTask->{$groupBy} = $team->account; + $cloneTask->estimate = $team->estimate; + $cloneTask->consumed = $team->consumed; + $cloneTask->left = $team->left; + if($team->left == 0 || $groupBy == 'finishedBy') $cloneTask->status = 'done'; + + $realname = zget($users, $team->account); + $cloneTask->assignedToRealName = $realname; + $groupTasks[$realname][] = $cloneTask; + } + + if($groupBy == 'finishedBy' && !empty($task->left)) $groupTasks[$users[$task->finishedBy]][] = $task; + + return $groupTasks; + } + /** * 检查累积流图的日期。 * Check Cumulative flow diagram date. @@ -455,6 +567,75 @@ class executionZen extends execution return $members; } + /** + * 根据过滤规则,筛选任务分组数据。 + * Filter task group data based on the filter rules. + * + * @param array $groupTasks + * @param string $groupBy + * @param string $filter + * @param int $allCount + * @param array $tasks + * @access protected + * @return array + */ + protected function filterGroupTasks(array $groupTasks, string $groupBy, string $filter, int $allCount, array $tasks): array + { + if($filter != 'all') + { + if($groupBy == 'story' && $filter == 'linked' && isset($groupTasks[0])) + { + $allCount -= count($groupTasks[0]); + unset($groupTasks[0]); + } + elseif($groupBy == 'pri' && $filter == 'noset') + { + foreach($groupTasks as $pri => $tasks) + { + if($pri) + { + $allCount -= count($tasks); + unset($groupTasks[$pri]); + } + } + } + elseif($groupBy == 'assignedTo' && $filter == 'undone') + { + $multiTaskCount = array(); + foreach($groupTasks as $assignedTo => $tasks) + { + foreach($tasks as $i => $task) + { + if($task->status != 'wait' && $task->status != 'doing') + { + if($task->mode == 'multi') + { + if(!isset($multiTaskCount[$task->id])) + { + $multiTaskCount[$task->id] = true; + $allCount -= 1; + } + } + else + { + $allCount -= 1; + } + + unset($groupTasks[$assignedTo][$i]); + } + } + } + } + elseif(($groupBy == 'finishedBy' || $groupBy == 'closedBy') && isset($tasks[''])) + { + $allCount -= count($tasks['']); + unset($tasks['']); + } + } + + return array($groupTasks, $allCount); + } + /** * 设置最近五次执行。 * Set the recent five executions.