From abdcd8ceaf1244be428245fc538b09fa6aba611b Mon Sep 17 00:00:00 2001 From: xushenjie Date: Wed, 10 May 2023 07:43:00 +0000 Subject: [PATCH] * Adjust the code of programplanModel::checkCodeUnique(). --- module/programplan/model.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/module/programplan/model.php b/module/programplan/model.php index 6313796c3a..e287908756 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -1149,25 +1149,28 @@ class programplanModel extends model } /** - * Check code unique. + * 根据计划ID列表,检查code的唯一性。 + * Check code unique by plan id list. * - * @param array $codes - * @param array $planIDList + * @param array $codes + * @param array $planIDList * @access public - * @return mix + * @return array|bool */ - public function checkCodeUnique($codes, $planIDList) + public function checkCodeUnique(array $codes, array $planIDList): array|bool { $codes = array_filter($codes); $sameCodes = $this->dao->select('code')->from(TABLE_EXECUTION) ->where('type')->in('sprint,stage,kanban') - ->andWhere('deleted')->eq('0') ->andWhere('code')->in($codes) - ->beginIF($planIDList)->andWhere('id')->notin($planIDList)->fi() + ->andWhere('deleted')->eq('0') + ->beginIF(!empty($planIDList))->andWhere('id')->notin($planIDList)->fi() ->fetchPairs('code'); + if(count(array_unique($codes)) != count($codes)) $sameCodes += array_diff_assoc($codes, array_unique($codes)); - return $sameCodes ? $sameCodes : true; + + return $sameCodes ?: true; } /**