From 58c5b9f55c9ce49abc0c4fd0bfb9f65b890c862f Mon Sep 17 00:00:00 2001 From: caoyanyi Date: Thu, 21 Sep 2023 09:29:26 +0800 Subject: [PATCH] * Adjust parmas type for branch getList. --- module/branch/model.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/module/branch/model.php b/module/branch/model.php index 47c38ec681..6633195302 100644 --- a/module/branch/model.php +++ b/module/branch/model.php @@ -37,6 +37,7 @@ class branchModel extends model } /** + * 获取分支列表。 * Get branch list. * * @param int $productID @@ -48,8 +49,11 @@ class branchModel extends model * @access public * @return array */ - public function getList($productID, $executionID = 0, $browseType = 'active', $orderBy = 'order', $pager = null, $withMainBranch = true) + public function getList(int $productID, int $executionID = 0, string $browseType = 'active', string $orderBy = 'order', object|null $pager = null, bool $withMainBranch = true): array { + $product = $this->loadModel('product')->getById($productID); + if(!$product) return array(); + $executionBranches = array(); if($executionID) { @@ -57,22 +61,22 @@ class branchModel extends model ->where('project')->eq($executionID) ->andWhere('product')->eq($productID) ->fetchPairs('branch'); - if(in_array(BRANCH_MAIN, $executionBranches)) $withMainBranch = true; if(empty($executionBranches)) return array(); + + if(in_array(BRANCH_MAIN, $executionBranches)) $withMainBranch = true; } + /* Get branch list. */ $branchList = $this->dao->select('*')->from(TABLE_BRANCH) ->where('deleted')->eq(0) ->beginIF($productID)->andWhere('product')->eq($productID)->fi() - ->beginIF($productID and $executionID)->andWhere('id')->in(array_keys($executionBranches))->fi() + ->beginIF($productID && $executionID)->andWhere('id')->in(array_keys($executionBranches))->fi() ->beginIF(!in_array($browseType, array('withClosed', 'all')))->andWhere('status')->eq($browseType)->fi() ->orderBy($orderBy) ->page($pager) ->fetchAll('id'); - if($browseType == 'closed') return $branchList; - $product = $this->loadModel('product')->getById($productID); $defaultBranch = BRANCH_MAIN; foreach($branchList as $branch) $defaultBranch = $branch->default ? $branch->id : $defaultBranch; @@ -90,7 +94,8 @@ class branchModel extends model $mainBranch->desc = sprintf($this->lang->branch->mainBranch, $this->lang->product->branchName[$product->type]); $mainBranch->order = 0; - return array($mainBranch) + $branchList; + array_unshift($branchList, $mainBranch); + return $branchList; } /**