* Refactor addProjectMembers method.

This commit is contained in:
tianshujie
2023-09-01 09:16:08 +08:00
parent 19ad64d83e
commit 3d2b686c78
3 changed files with 21 additions and 28 deletions
+11 -10
View File
@@ -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);
}
}
+8 -9
View File
@@ -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);
}
@@ -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,研发'); // 敏捷项目根据执行添加团队信息