From b05cad4addb6e7948ba227fae6d6b56d82cdbe9c Mon Sep 17 00:00:00 2001 From: tianshujie Date: Sat, 18 Feb 2023 20:16:52 +0800 Subject: [PATCH] * Add case of execution method. --- module/execution/model.php | 5 ++- test/class/execution.class.php | 40 +++++++++++++++++++ test/model/execution/resetexecutionsorts.php | 41 ++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 test/model/execution/resetexecutionsorts.php diff --git a/module/execution/model.php b/module/execution/model.php index b3f627198b..55f0734e7f 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -5609,6 +5609,7 @@ class executionModel extends model */ public function resetExecutionSorts($executions, $parentExecutions = array()) { + if(empty($executions)) return array(); if(empty($parentExecutions)) { $execution = current($executions); @@ -5616,6 +5617,7 @@ class executionModel extends model ->where('deleted')->eq(0) ->andWhere('type')->in('kanban,sprint,stage') ->andWhere('grade')->eq(1) + ->andWhere('project')->eq($execution->project) ->orderBy('order_asc') ->fetchAll('id'); } @@ -5623,9 +5625,10 @@ class executionModel extends model $sortedExecutions = array(); foreach($parentExecutions as $executionID => $execution) { + if(!isset($sortedExecutions[$executionID]) and isset($executions[$executionID])) $sortedExecutions[$executionID] = $executions[$executionID]; + $children = $this->getChildExecutions($executionID, 'order_asc'); if(!empty($children)) $sortedExecutions += $this->resetExecutionSorts($executions, $children); - if(!isset($sortedExecutions[$executionID]) and isset($executions[$executionID])) $sortedExecutions[$executionID] = $executions[$executionID]; } return $sortedExecutions; } diff --git a/test/class/execution.class.php b/test/class/execution.class.php index dd2eb1cc8e..2c93e4b48d 100644 --- a/test/class/execution.class.php +++ b/test/class/execution.class.php @@ -2806,4 +2806,44 @@ class executionTest ->andWhere('date')->eq($date) ->orderBy('date DESC, id asc')->fetchGroup('name', 'date'); } + + /** + * Reset execution sorts. + * + * @param int $projectID + * @param string $type noParent + * @access public + * @return string + */ + public function resetExecutionSortsTest($projectID, $type = '') + { + $executions = array(); + $executionIDList = ''; + $firstGradeExecutions = array(); + if($projectID) + { + $executions = $this->executionModel->dao->select('*')->from(TABLE_EXECUTION) + ->where('deleted')->eq(0) + ->andWhere('project')->eq($projectID) + ->andWhere('type')->in('sprint,stage,kanban') + ->orderBy('order_asc') + ->fetchAll('id'); + + if($type == 'hasParent') + { + foreach($executions as $execution) + { + if($execution->grade == 1) $firstGradeExecutions[$execution->id] = $execution->id; + } + } + } + + $executions = $this->executionModel->resetExecutionSorts($executions, $firstGradeExecutions); + if(!empty($executions)) + { + $executionIDList = array_keys($executions); + $executionIDList = implode(',', $executionIDList); + } + return $executionIDList; + } } diff --git a/test/model/execution/resetexecutionsorts.php b/test/model/execution/resetexecutionsorts.php new file mode 100644 index 0000000000..d21a387966 --- /dev/null +++ b/test/model/execution/resetexecutionsorts.php @@ -0,0 +1,41 @@ +#!/usr/bin/env php +gen(5); +su('admin'); + +$execution = zdTable('project'); +$execution->id->range('1-8'); +$execution->name->range('项目集1,项目1,需求阶段1,测试阶段1,需求子阶段1,需求子阶段2,需求子阶段1的迭代1,需求子阶段1的看板1'); +$execution->model->range('[],waterfallplus,[]{6}'); +$execution->type->range('program,project,stage{4},sprint,kanban'); +$execution->project->range('0{2},2{6}'); +$execution->parent->range('0,1,2{2},3{2},5{2}'); +$execution->grade->range('1{4},2{2},3{2}'); +$execution->path->range('`,1,`,`,1,2,`,`,1,2,3`,`,1,2,4,`,`,1,2,3,5,`,`,1,2,3,6,`,`,1,2,3,5,7,`,`1,2,3,5,8,`'); +$execution->order->range('5,10,15,20,25,30,35,40'); +$execution->status->range('doing'); +$execution->openedBy->range('admin'); +$execution->begin->range('20220112 000000:0')->type('timestamp')->format('YY/MM/DD'); +$execution->end->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD'); +$execution->gen(8); + +/** + +title=测试executionModel->resetExecutionSorts(); +cid=1 +pid=1 + +检查没有执行时的排序 >> 0 +检查有执行时的排序 >> 3,5,7,8,6,4 +检查有执行并且传parenExecutions时的排序 >> 3,5,7,8,6,4 + +*/ + +$projectList = array(0, 2); + +$executionTester = new executionTest(); +r($executionTester->resetExecutionSortsTest($projectList[0])) && p() && e('0'); // 检查没有执行时的排序 +r($executionTester->resetExecutionSortsTest($projectList[1])) && p() && e('3,5,7,8,6,4'); // 检查有执行时的排序 +r($executionTester->resetExecutionSortsTest($projectList[1], 'hasParent')) && p() && e('3,5,7,8,6,4'); // 检查有执行并且传parenExecutions时的排序