diff --git a/module/testcase/control.php b/module/testcase/control.php index 462ff399c5..49c3459b61 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1289,13 +1289,15 @@ class testcase extends control $this->app->loadClass('pager', $static = true); $pager = pager::init(0, $recPerPage, $pageID); + $cases = $this->testcase->getCanImportCases($productID, $libID, $orderBy, $pager, $browseType, (int)$queryID); + /* 展示变量. */ /* Show the variables. */ - $this->testcaseZen->assignForImportFromLib($productID, $branch, $libID, $orderBy, $queryID, $libraries, $projectID); + $this->testcaseZen->assignForImportFromLib($productID, $branch, $libID, $orderBy, $queryID, $libraries, $projectID, $cases); $this->view->title = $this->lang->testcase->common . $this->lang->hyphen . $this->lang->testcase->importFromLib; $this->view->libraries = $libraries; - $this->view->cases = $this->testcase->getCanImportCases($productID, $libID, $branch, $orderBy, $pager, $browseType, (int)$queryID); + $this->view->cases = $cases; $this->view->libModules = $this->tree->getOptionMenu($libID, 'caselib'); $this->view->pager = $pager; $this->view->browseType = $browseType; @@ -1994,7 +1996,7 @@ class testcase extends control */ public function ajaxGetCanImportModuleItems(int $productID, int $libID, int $branch, int $caseID) { - $moduleItems = $this->testcase->getCanImportedModules($productID, $libID, $branch, 'items'); + $moduleItems = $this->testcase->getCanImportedModules($productID, $libID, $branch, 'items', array($caseID => $caseID)); $caseModuleItmes = isset($moduleItems[$caseID]) ? $moduleItems[$caseID] : array(); return print(json_encode($caseModuleItmes)); } diff --git a/module/testcase/model.php b/module/testcase/model.php index 2b6a8ee3c7..48443a3557 100755 --- a/module/testcase/model.php +++ b/module/testcase/model.php @@ -2705,14 +2705,13 @@ class testcaseModel extends model * * @param int $productID * @param int $libID - * @param int $branch * @param string $orderBy * @param object $pager * @param int $queryID * @access public * @return array */ - public function getCanImportCases(int $productID, int $libID, int|string $branch, string $orderBy = 'id_desc', object $pager = null, string $browseType = '', int $queryID = 0): array + public function getCanImportCases(int $productID, int $libID, string $orderBy = 'id_desc', object $pager = null, string $browseType = '', int $queryID = 0): array { $query = ''; if($browseType == 'bysearch') @@ -2739,16 +2738,32 @@ class testcaseModel extends model } $this->loadModel('branch'); - $product = $this->loadModel('product')->getById($productID); - $branches = $branch === 'all' && $product->type != 'normal' ? array(BRANCH_MAIN => $this->lang->branch->main) + $this->branch->getPairs($productID, 'active') : array($product->type == 'normal' ? 0 : $branch => ''); - $canImport = array(); - foreach($branches as $branchID => $branchName) $canImport += $this->getCanImportedModules($productID, $libID, $branchID); + $this->loadModel('tree'); + $product = $this->loadModel('product')->getById($productID); + $branches = $product->type != 'normal' ? array(BRANCH_MAIN => $this->lang->branch->main) + $this->branch->getPairs($productID, 'active') : array(0); + $branches = array_keys($branches); + $branchModules = array(); + foreach($branches as $branch) $branchModules[$branch] = $this->tree->getOptionMenu($productID, 'case', 0, (string)$branch); + + $caseModuleCount = $this->dao->select('fromCaseID,count(module) AS moduleCount') + ->from(TABLE_CASE)->alias('t1') + ->leftJoin(TABLE_MODULE)->alias('t2')->on('t1.module=t2.id and t1.product = t2.root') + ->where('t1.product')->eq($productID) + ->andWhere('t1.lib')->eq($libID) + ->andWhere('t1.fromCaseID')->ne('') + ->andWhere('t1.deleted')->eq('0') + ->andWhere('((t2.type')->in('story,case')->andWhere('t2.deleted')->eq('0')->markRight(1) + ->orWhere('t1.module')->eq('0')->markRight(1) + ->groupBy('t1.fromCaseID') + ->fetchPairs(); + $canImport = $canNotImport = array(); return $this->dao->select('*')->from(TABLE_CASE) ->where('deleted')->eq('0') ->beginIF($browseType != 'bysearch')->andWhere('lib')->eq($libID)->fi() ->beginIF($browseType == 'bysearch')->andWhere($query)->fi() - ->andWhere('id')->in(array_keys($canImport)) + ->beginIF(count($canImport) <= count($canNotImport))->andWhere('id')->in($canImport)->fi() + ->beginIF(count($canImport) > count($canNotImport))->andWhere('id')->notIn($canNotImport)->fi() ->andWhere('product')->eq(0) ->orderBy($orderBy) ->page($pager) @@ -2766,7 +2781,7 @@ class testcaseModel extends model * @access public * @return array */ - public function getCanImportedModules(int $productID, int $libID, int|string $branch, string $returnType = 'pairs'): array + public function getCanImportedModules(int $productID, int $libID, int|string $branch, string $returnType = 'pairs', array $libCases = array()): array { $importedModules = $this->dao->select('fromCaseID,module')->from(TABLE_CASE) ->where('product')->eq($productID) @@ -2777,8 +2792,8 @@ class testcaseModel extends model ->fetchGroup('fromCaseID', 'module'); foreach($importedModules as $fromCaseID => $modules) $importedModules[$fromCaseID] = array_combine(array_keys($modules), array_keys($modules)); - $libCases = $this->loadModel('caselib')->getLibCases($libID, 'all'); - $modules = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, (string)$branch); + if(empty($libCases)) $libCases = $this->loadModel('caselib')->getLibCases($libID, 'all'); + $modules = $this->loadModel('tree')->getOptionMenu($productID, 'case', 0, (string)$branch); if($returnType == 'items') { $moduleItems = array(); @@ -2786,7 +2801,8 @@ class testcaseModel extends model } $canImportModules = array(); - foreach($libCases as $caseID => $case){ + foreach($libCases as $caseID => $case) + { $caseModules = !empty($importedModules[$caseID]) ? $importedModules[$caseID] : array(); $canImportModules[$caseID] = $returnType == 'pairs' ? array_diff_key($modules, $caseModules) : array_diff_key($moduleItems, $caseModules); if(!empty($canImportModules[$caseID])) diff --git a/module/testcase/zen.php b/module/testcase/zen.php index 8085c60249..2ed090c546 100755 --- a/module/testcase/zen.php +++ b/module/testcase/zen.php @@ -191,10 +191,11 @@ class testcaseZen extends testcase * @param string $orderBy * @param int $queryID * @param array $libraries + * @param array $cases * @access protected * @return void */ - protected function assignForImportFromLib(int $productID, string $branch, int $libID, string $orderBy, int $queryID, array $libraries, int $projectID): void + protected function assignForImportFromLib(int $productID, string $branch, int $libID, string $orderBy, int $queryID, array $libraries, int $projectID, array $cases): void { $product = $this->loadModel('product')->getById($productID); $branches = array(); @@ -204,8 +205,8 @@ class testcaseZen extends testcase $branches = array(BRANCH_MAIN => $this->lang->branch->main) + $this->branch->getPairs($productID, 'active', $projectID); } - foreach($branches as $branchID => $branchName) $canImportModules[$branchID] = $this->testcase->getCanImportedModules($productID, $libID, $branchID, 'items'); - if(empty($branches)) $canImportModules[0] = $this->testcase->getCanImportedModules($productID, $libID, 0, 'items'); + foreach($branches as $branchID => $branchName) $canImportModules[$branchID] = $this->testcase->getCanImportedModules($productID, $libID, $branchID, 'items', $cases); + if(empty($branches)) $canImportModules[0] = $this->testcase->getCanImportedModules($productID, $libID, 0, 'items', $cases); /* Build the search form. */ $actionURL = $this->createLink('testcase', 'importFromLib', "productID={$productID}&branch={$branch}&libID={$libID}&orderBy={$orderBy}&browseType=bySearch&queryID=myQueryID"); @@ -1703,12 +1704,12 @@ class testcaseZen extends testcase { if($branch != 'ditto') $prevBranch = $branch; if($branch == 'ditto') $branches[$caseID] = $prevBranch; - if(!isset($caseModules[$branch]) && in_array($caseID, $caseIdList) !== false) $caseModules[$branch] = $this->testcase->getCanImportedModules($productID, $libID, $branch); + if(!isset($caseModules[$branch]) && in_array($caseID, $caseIdList) !== false) $caseModules[$branch] = $this->testcase->getCanImportedModules($productID, $libID, $branch, 'pairs', $caseIdList); } } else { - $caseModules[$branch] = $this->testcase->getCanImportedModules($productID, $libID, $branch); + $caseModules[$branch] = $this->testcase->getCanImportedModules($productID, $libID, $branch, 'pairs', $caseIdList); } /* 构建用例。 */