From 36e71b187fd9807cfe6b5522138a549fac451630 Mon Sep 17 00:00:00 2001 From: tianshujie Date: Thu, 17 Aug 2023 15:32:51 +0800 Subject: [PATCH] * Refactor getByID method. --- module/execution/model.php | 11 ++++++++--- module/execution/test/execution.class.php | 4 ++-- module/execution/test/model/getbyid.php | 10 ++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/module/execution/model.php b/module/execution/model.php index 5a1818f3a3..924f5a1dd4 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -2490,14 +2490,15 @@ class executionModel extends model } /** - * Get the execution by ID. + * 获取执行的信息。 + * Get the execution information by ID. * * @param int $executionID * @param bool $setImgSize * @access public - * @return object + * @return object|false */ - public function getByID($executionID, $setImgSize = false) + public function getByID(int $executionID, bool $setImgSize = false): object|false { if(commonModel::isTutorialMode()) return $this->loadModel('tutorial')->getExecution(); @@ -2511,6 +2512,7 @@ class executionModel extends model if($delay > 0) $execution->delay = $delay; } + /* Get hours information. */ $total = $this->dao->select(' ROUND(SUM(estimate), 2) AS totalEstimate, ROUND(SUM(consumed), 2) AS totalConsumed, @@ -2520,6 +2522,8 @@ class executionModel extends model ->andWhere('deleted')->eq(0) ->andWhere('parent')->lt(1) ->fetch(); + + /* Get hours information of the closed and cancel task. */ $closedTotalLeft = $this->dao->select('ROUND(SUM(`left`), 2) AS totalLeft')->from(TABLE_TASK) ->where('execution')->eq((int)$executionID) ->andWhere('deleted')->eq(0) @@ -2527,6 +2531,7 @@ class executionModel extends model ->andWhere('status')->in('closed,cancel') ->fetch('totalLeft'); + /* Set the hours information for the task. */ $execution->days = $execution->days ? $execution->days : ''; $execution->totalHours = $this->dao->select('sum(days * hours) AS totalHours')->from(TABLE_TEAM)->where('root')->eq($execution->id)->andWhere('type')->eq('execution')->fetch('totalHours'); $execution->totalEstimate = round((float)$total->totalEstimate, 1); diff --git a/module/execution/test/execution.class.php b/module/execution/test/execution.class.php index a4d3de416d..9af8150006 100644 --- a/module/execution/test/execution.class.php +++ b/module/execution/test/execution.class.php @@ -664,9 +664,9 @@ class executionTest * * @param string $executionID * @access public - * @return array + * @return string|object|false */ - public function getByIDTest($executionID) + public function getByIDTest(int $executionID): string|object|false { $object = $this->executionModel->getByID($executionID); diff --git a/module/execution/test/model/getbyid.php b/module/execution/test/model/getbyid.php index 48209d5eaa..9df44d3d16 100755 --- a/module/execution/test/model/getbyid.php +++ b/module/execution/test/model/getbyid.php @@ -19,14 +19,12 @@ su('admin'); /** title=executionModel->getByID(); -cid=1 +timeout=0 pid=1 -根据executionID查找任务详情 >> 迭代1 - */ -$executionID = '3'; - $execution = new executionTest(); -r($execution->getByIDTest($executionID)) && p('name') && e('迭代1'); //根据executionID查找任务详情 +r($execution->getByIDTest(3)) && p('name') && e('迭代1'); // 根据executionID查找任务详情 +r($execution->getByIDTest(3, true)) && p('name') && e('迭代1'); // 根据executionID查找任务详情并替换图片链接 +r($execution->getByIDTest(6)) && p() && e('0'); // 查询存在的执行