diff --git a/module/task/model.php b/module/task/model.php index 56496e133d..d9233c34b1 100755 --- a/module/task/model.php +++ b/module/task/model.php @@ -1441,19 +1441,6 @@ class taskModel extends model return $this->processTask($task); } - /** - * 获取执行的项目ID。 - * Get the ID of the project to execution ID. - * - * @param int $executionID - * @access public - * @return int - */ - public function getProjectID(int $executionID = 0): int - { - return $this->dao->select('project')->from(TABLE_EXECUTION)->where('id')->eq($executionID)->fetch('project'); - } - /** * 通过任务ID列表批量获取任务信息。 * Get the task information from the task ID list. @@ -1540,7 +1527,8 @@ class taskModel extends model } /** - * Get execution tasks pairs. + * 获取任务 id:name 的数组。 + * Get an array of task id:name. * * @param int $executionID * @param string $status @@ -1548,19 +1536,24 @@ class taskModel extends model * @access public * @return array */ - public function getExecutionTaskPairs($executionID, $status = 'all', $orderBy = 'finishedBy, id_desc') + public function getExecutionTaskPairs(int $executionID, string $status = 'all', string $orderBy = 'finishedBy, id_desc'): array { - $tasks = array('' => ''); - $stmt = $this->dao->select('t1.id,t1.name,t1.parent,t2.realname AS finishedByRealName') + $tasks = $this->dao->select('t1.id,t1.name,t1.parent,t2.realname AS finishedByRealName') ->from(TABLE_TASK)->alias('t1') ->leftJoin(TABLE_USER)->alias('t2')->on('t1.finishedBy = t2.account') ->where('t1.execution')->eq((int)$executionID) ->andWhere('t1.deleted')->eq(0) ->beginIF($status != 'all')->andWhere('t1.status')->in($status)->fi() ->orderBy($orderBy) - ->query(); - while($task = $stmt->fetch()) $tasks[$task->id] = ($task->parent > 0 ? "[{$this->lang->task->childrenAB}] " : '') . "$task->id:$task->finishedByRealName:$task->name"; - return $tasks; + ->fetchAll('id'); + + $taskPairs = array(); + foreach($tasks as $taskID => $task) + { + $prefix = $task->parent > 0 ? "[{$this->lang->task->childrenAB}] " : ''; + $taskPairs[$taskID] = $prefix . "{$taskID}:{$task->finishedByRealName}:{$task->name}"; + } + return $taskPairs; } /** diff --git a/module/task/test/model/getexecutiontaskpairs.php b/module/task/test/model/getexecutiontaskpairs.php index e85973d03b..ab956ae616 100755 --- a/module/task/test/model/getexecutiontaskpairs.php +++ b/module/task/test/model/getexecutiontaskpairs.php @@ -1,20 +1,40 @@ #!/usr/bin/env php config('project', true)->gen(3); +zdTable('task')->config('task', true)->gen(12); + /** title=taskModel->getExecutionTaskPairs(); +timeout=0 cid=1 -pid=1 - -根据执行id查出任务id与name >> 2::开发任务12 */ -$executionID = '102'; +$taskModel = $tester->loadModel('task'); -$task = new taskTest(); -r($task->getExecutionTaskPairsTest($executionID)) && p('2') && e('2::开发任务12'); //根据执行id查出任务id与name +$emptyExecution = $taskModel->getExecutionTaskPairs(0); +$notExistExecution = $taskModel->getExecutionTaskPairs(4); +$existExecution = $taskModel->getExecutionTaskPairs(3); +$waitTasks = $taskModel->getExecutionTaskPairs(3, 'wait'); +$doingTasks = $taskModel->getExecutionTaskPairs(3, 'doing'); +$doneTasks = $taskModel->getExecutionTaskPairs(3, 'done'); +$cancelTasks = $taskModel->getExecutionTaskPairs(3, 'cancel'); +$closeTasks = $taskModel->getExecutionTaskPairs(3, 'close'); +$tasksByIdASC = $taskModel->getExecutionTaskPairs(3, 'all', 'id_asc'); +$tasksByIdDESC = $taskModel->getExecutionTaskPairs(3, 'all', 'id_desc'); + +r(count($emptyExecution)) && p() && e('0'); // 获取执行ID为0的任务数组数量 +r(count($notExistExecution)) && p() && e('0'); // 获取执行ID不存在的任务数组数量 +r(count($existExecution)) && p() && e('9'); // 获取执行ID为3的任务数组数量 +r(count($waitTasks)) && p() && e('4'); // 获取执行ID为3的未开始任务数组数量 +r(count($doingTasks)) && p() && e('2'); // 获取执行ID为3的进行中任务数组数量 +r(count($doneTasks)) && p() && e('1'); // 获取执行ID为3的已完成任务数组数量 +r(count($cancelTasks)) && p() && e('1'); // 获取执行ID为3的已取消任务数组数量 +r(count($closeTasks)) && p() && e('0'); // 获取执行ID为3的已关闭任务数组数量 +r($existExecution) && p('7') && e('[子] 7::开发任务17'); // 获取执行ID为3的任务数组 +r(implode(',', array_keys($tasksByIdASC))) && p() && e('1,2,3,4,5,6,7,8,9'); // 获取执行ID为3的按照任务Id正序任务数组 +r(implode(',', array_keys($tasksByIdDESC))) && p() && e('9,8,7,6,5,4,3,2,1'); // 获取执行ID为3的按照任务Id倒序任务数组 diff --git a/module/task/zen.php b/module/task/zen.php index 0a00f99da6..f2d4245d55 100644 --- a/module/task/zen.php +++ b/module/task/zen.php @@ -1160,8 +1160,8 @@ class taskZen extends task $response['load'] = $this->createLink('execution', 'story', "executionID={$executionID}"); if($this->config->vision == 'lite') { - $projectID = $this->execution->getProjectID($executionID); - $response['load'] = $this->createLink('projectstory', 'story', "projectID={$projectID}"); + $execution = $this->execution->getByID($executionID); + $response['load'] = $this->createLink('projectstory', 'story', "projectID={$execution->project}"); } return $response; }