diff --git a/module/execution/model.php b/module/execution/model.php index b25e25cb1c..c6ea7ca8bd 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -3780,18 +3780,20 @@ class executionModel extends model } /** + * 根据传入的条件筛选日期列表。 * Process burndown datas when the sets is smaller than the itemCounts. * - * @param array $sets + * @param array $dateList * @param int $itemCounts * @param string $begin * @param string $end - * @param string $mode + * @param string $mode noempty * @access public * @return array */ - public function processBurnData($sets, $itemCounts, $begin, $end, $mode = 'noempty') + public function processBurnData(array $dateList, int $itemCounts, string $begin, string $end, string $mode = 'noempty'): array { + /* Get the date interval if the $end is not empty, otherwise get the $end. */ if(!helper::isZeroDate($end)) { $period = helper::diffDate($end, $begin) + 1; @@ -3799,8 +3801,7 @@ class executionModel extends model } else { - $counts = $itemCounts; - $period = $itemCounts; + $counts = $period = $itemCounts; $end = date(DT_DATE1, strtotime("+$counts days", strtotime($begin))); } @@ -3810,37 +3811,36 @@ class executionModel extends model $preValue = 0; $todayTag = 0; - foreach($sets as $date => $set) + /* Removes date that are not in the current date range. */ + foreach($dateList as $date => $value) { - if($begin > $date) unset($sets[$date]); + if($begin > $date) unset($dateList[$date]); } + /* Update date that are not in the date list and are in the date range. */ for($i = 0; $i < $period; $i++) { $currentTime = strtotime($current); if($currentTime > $endTime) break; - if($currentTime > time() and !$todayTag) - { - $todayTag = $i + 1; - } + if($currentTime > time() && !$todayTag) $todayTag = $i + 1; - if(isset($sets[$current])) $preValue = $sets[$current]->value; - if(!isset($sets[$current]) and $mode == 'noempty') + if(isset($dateList[$current])) $preValue = $dateList[$current]->value; + if(!isset($dateList[$current]) && $mode == 'noempty') { - $sets[$current] = new stdclass(); - $sets[$current]->name = $current; - $sets[$current]->value = helper::diffDate($current, $today) < 0 ? $preValue : 'null'; + $dateList[$current] = new stdclass(); + $dateList[$current]->name = $current; + $dateList[$current]->value = helper::diffDate($current, $today) < 0 ? $preValue : 'null'; } $nextDay = date(DT_DATE1, $currentTime + 24 * 3600); $current = $nextDay; } - ksort($sets); + ksort($dateList); - if(count($sets) <= $counts) return $sets; - if($endTime <= time()) return array_slice($sets, -$counts, $counts); - if($todayTag <= $counts) return array_slice($sets, 0, $counts); - if($todayTag > $counts) return array_slice($sets, $todayTag - $counts, $counts); + if(count($dateList) <= $counts) return $dateList; + if($endTime <= time()) return array_slice($dateList, -$counts, $counts); + if($todayTag <= $counts) return array_slice($dateList, 0, $counts); + if($todayTag > $counts) return array_slice($dateList, $todayTag - $counts, $counts); } /** diff --git a/module/execution/test/execution.class.php b/module/execution/test/execution.class.php index 0f263a4670..a6c65eaac3 100644 --- a/module/execution/test/execution.class.php +++ b/module/execution/test/execution.class.php @@ -1956,29 +1956,28 @@ class executionTest } /** - * function processBurnData test by execution + * 根据传入的条件筛选日期列表。 + * Process burndown datas when the sets is smaller than the itemCounts. * - * @param string $executionID - * @param array $itemCounts - * @param string $begin - * @param string $end - * @param string $count + * @param int $executionID + * @param int $itemCounts + * @param string $begin + * @param string $end + * @param int $count * @access public - * @return array + * @return array|int */ - public function processBurnDataTest($executionID, $itemCounts, $begin, $end, $count) + public function processBurnDataTest(int $executionID, int $itemCounts, string $begin, string $end, int $count): array|int { - global $tester; - $sets = $tester->dao->select('execution, `date` as name, `left` as value')->from(TABLE_BURN)->where('execution')->eq($executionID)->fetchAll('name'); - - $object = $this->executionModel->processBurnData($sets, $itemCounts, $begin, $end); + $dateList = $this->executionModel->dao->select('execution, `date` as name, `left` as value')->from(TABLE_BURN)->where('execution')->eq($executionID)->fetchAll('name'); + $object = $this->executionModel->processBurnData($dateList, $itemCounts, $begin, $end); if(dao::isError()) { $error = dao::getError(); return $error; } - elseif($count == "1") + elseif($count == 1) { return count($object); } diff --git a/module/execution/test/model/processburndata.php b/module/execution/test/model/processburndata.php index baa79d5486..c9e3520d4f 100755 --- a/module/execution/test/model/processburndata.php +++ b/module/execution/test/model/processburndata.php @@ -3,25 +3,21 @@ include dirname(__FILE__, 5) . '/test/lib/init.php'; include dirname(__FILE__, 2) . '/execution.class.php'; su('admin'); +zdTable('burn')->config('burn')->gen(15); /** title=测试executionModel->processBurnDataTest(); +timeout=0 cid=1 -pid=1 - -敏捷执行查询统计 >> 30 -瀑布执行查询统计 >> 60 -看板执行查询统计 >> 67 -错误时间查询统计 >> 0 */ -$executionIDList = array('101', '131', '161'); -$itemCounts = array('30', '60', '100'); +$executionIDList = array(101, 106, 107); +$itemCounts = array(30, 60, 100); $begin = array('2022-01-15','2022-03-22'); $end = array('2022-03-22','2022-01-15'); -$count = array('0','1'); +$count = array(0, 1); $execution = new executionTest(); r($execution->processBurnDataTest($executionIDList[0], $itemCounts[0], $begin[0], $end[0], $count[1])) && p() && e('30'); // 敏捷执行查询统计