From 3d2b686c78728a8d121dab92a3e2a67d556ad22a Mon Sep 17 00:00:00 2001 From: tianshujie Date: Fri, 1 Sep 2023 09:16:00 +0800 Subject: [PATCH] * Refactor addProjectMembers method. --- module/execution/model.php | 21 ++++++++++--------- module/execution/test/execution.class.php | 17 +++++++-------- .../test/model/addprojectmembers.php | 11 ++-------- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/module/execution/model.php b/module/execution/model.php index b9462453aa..4283b03b21 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -3652,6 +3652,7 @@ class executionModel extends model } /** + * 添加项目团队成员。 * Add the execution team members to the project. * * @param int $projectID @@ -3659,31 +3660,31 @@ class executionModel extends model * @access public * @return void */ - public function addProjectMembers($projectID = 0, $members = array()) + public function addProjectMembers(int $projectID = 0, array $members = array()) { $projectType = 'project'; $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq($projectID)->andWhere('type')->eq($projectType)->fetchPairs(); - $accounts = array(); + $accountList = array(); foreach($members as $member) { if(isset($oldJoin[$member->account])) continue; - $accounts[] = $member->account; + $accountList[] = $member->account; $member->root = $projectID; $member->type = $projectType; $this->dao->insert(TABLE_TEAM)->data($member)->exec(); } /* Only changed account update userview. */ - $oldAccounts = array_keys($oldJoin); - $changedAccounts = array_diff($accounts, $oldAccounts); - $changedAccounts = array_merge($changedAccounts, array_diff($oldAccounts, $accounts)); - $changedAccounts = array_unique($changedAccounts); + $oldAccountList = array_keys($oldJoin); + $changedAccountList = array_diff($accountList, $oldAccountList); + $changedAccountList = array_merge($changedAccountList, array_diff($oldAccountList, $accountList)); + $changedAccountList = array_unique($changedAccountList); - if($changedAccounts) + if($changedAccountList) { - $this->loadModel('user')->updateUserView($projectID, $projectType, $changedAccounts); + $this->loadModel('user')->updateUserView($projectID, $projectType, $changedAccountList); $linkedProducts = $this->dao->select("t2.id")->from(TABLE_PROJECTPRODUCT)->alias('t1') ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id') ->where('t2.deleted')->eq(0) @@ -3691,7 +3692,7 @@ class executionModel extends model ->andWhere('t2.vision')->eq($this->config->vision) ->fetchPairs(); - if(!empty($linkedProducts)) $this->user->updateUserView(array_keys($linkedProducts), 'product', $changedAccounts); + if(!empty($linkedProducts)) $this->user->updateUserView(array_keys($linkedProducts), 'product', $changedAccountList); } } diff --git a/module/execution/test/execution.class.php b/module/execution/test/execution.class.php index 01ce67d33b..e4ee8b75f7 100644 --- a/module/execution/test/execution.class.php +++ b/module/execution/test/execution.class.php @@ -1764,27 +1764,26 @@ class executionTest * function addProjectMembers test by execution * * @param int $projectID - * @param string $executionID - * @param string $count + * @param int $executionID + * @param int $count * @access public - * @return array + * @return array|int */ - public function addProjectMembersTest($projectID = 0, $executionID = 0, $count = 0) + public function addProjectMembersTest(int $projectID = 0, int $executionID = 0, int $count = 0): array|int { - global $tester; - $tester->dbh->query("delete from zt_team where root = $projectID"); - $executionMembers = $tester->dao->select('`root`,`account`,`join`,`role`,`days`,`type`,`hours`')->from(TABLE_TEAM)->where('root')->eq($executionID)->fetchAll('account'); + $this->executionModel->dao->delete()->from(TABLE_TEAM)->where('root')->eq($projectID)->exec(); + $executionMembers = $this->executionModel->dao->select('`root`,`account`,`join`,`role`,`days`,`type`,`hours`')->from(TABLE_TEAM)->where('root')->eq($executionID)->fetchAll('account'); $this->executionModel->addProjectMembers($projectID, $executionMembers); - $object = $tester->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($projectID)->fetchAll(); + $object = $this->executionModel->dao->select('*')->from(TABLE_TEAM)->where('root')->eq($projectID)->fetchAll(); if(dao::isError()) { $error = dao::getError(); return $error; } - elseif($count == "1") + elseif($count == 1) { return count($object); } diff --git a/module/execution/test/model/addprojectmembers.php b/module/execution/test/model/addprojectmembers.php index 06b6841621..daa7a97058 100755 --- a/module/execution/test/model/addprojectmembers.php +++ b/module/execution/test/model/addprojectmembers.php @@ -28,21 +28,14 @@ $team->gen(6); /** title=测试executionModel->addProjectMembersTest(); +timeout=0 cid=1 -pid=1 - -敏捷项目根据执行添加团队信息 >> admin,研发 -瀑布项目根据执行添加团队信息 >> admin,研发 -看板项目根据执行添加团队信息 >> admin,研发 -敏捷项目根据执行添加团队信息统计 >> 2 -瀑布项目根据执行添加团队信息统计 >> 2 -看板项目根据执行添加团队信息统计 >> 2 */ $projectIDList = array(2, 3, 4); $executionIDList = array(5, 6, 7); -$count = array('0','1'); +$count = array(0, 1); $executionTester = new executionTest(); r($executionTester->addProjectMembersTest($projectIDList[0], $executionIDList[0], $count[0])) && p('0:account,role') && e('admin,研发'); // 敏捷项目根据执行添加团队信息