* [task#133112,doing,2h] sync added members from execution.

This commit is contained in:
liumengyi
2024-12-03 13:25:42 +08:00
committed by 田淑杰
parent 445392668b
commit c19cdf5ca4
4 changed files with 41 additions and 27 deletions
+2 -3
View File
@@ -1167,7 +1167,6 @@ class project extends control
$account = $user->account;
$this->project->unlinkMember($projectID, $account, $removeExecution == 'yes');
if(!dao::isError()) $this->loadModel('action')->create('team', $projectID, 'managedTeam');
/* if ajax request, send result. */
if(dao::isError()) return $this->sendError(dao::getError());
@@ -1219,7 +1218,7 @@ class project extends control
$executionMembers = array();
foreach($executionTeams as $executionID => $executionTeam)
{
$executionMembers += array_keys($executionTeam);
$executionMembers = array_merge($executionMembers, array_keys($executionTeam));
}
$currentMembers = $this->project->getTeamMembers($projectID);
@@ -1235,7 +1234,7 @@ class project extends control
$this->view->currentMembers = $currentMembers;
$this->view->copyProjectID = $copyProjectID;
$this->view->teamMembers = $this->projectZen->buildMembers($currentMembers, $members2Import, $deptUsers, $project->days);
$this->view->executionMembers = $executionMembers;
$this->view->executionMembers = array_unique($executionMembers);
$this->display();
}
+6 -20
View File
@@ -1762,14 +1762,17 @@ class projectModel extends model
*/
public function unlinkMember(int $projectID, string $account, bool $removeExecution = false): bool
{
$this->projectTao->unlinkTeamMember($projectID, 'project', $account);
$user = $this->loadModel('user')->getById($account);
$changes = array(array('field' => 'removeDiff', 'old' => '', 'new' => '', 'diff' => $user->realname));
$this->loadModel('user')->updateUserView(array($projectID), 'project', array($account));
$this->projectTao->unlinkTeamMember($projectID, 'project', $account, $user->realname, $changes);
$this->user->updateUserView(array($projectID), 'project', array($account));
if($removeExecution)
{
$executions = $this->loadModel('execution')->getByProject($projectID, 'undone', 0, true);
$this->projectTao->unlinkTeamMember(array_keys($executions), 'execution', $account);
$this->projectTao->unlinkTeamMember(array_keys($executions), 'execution', $account, $user->realname, $changes);
$this->user->updateUserView(array_keys($executions), 'sprint', array($account));
}
@@ -1817,23 +1820,6 @@ class projectModel extends model
if(empty($project->multiple) and $project->model != 'waterfall') $this->loadModel('execution')->syncNoMultipleSprint($projectID);
/* Log history. */
$actionID = $this->loadModel('action')->create('project', $projectID, 'ManagedTeam');
$oldJoin = array_keys($oldJoin);
$addedAccountList = array_diff($accounts, $oldJoin);
$removedAccountList = array_diff($oldJoin, $accounts);
if(empty($addedAccountList) && empty($removedAccountList)) return !dao::isError();
$users = $this->loadModel('user')->getPairs('noletter');
$addedAccountList = array_map(function($account) use ($users) { return $users[$account]; }, $addedAccountList);
$removedAccountList = array_map(function($account) use ($users) { return $users[$account]; }, $removedAccountList);
if(!empty($addedAccountList)) $changes[] = array('field' => 'addDiff', 'old' => '', 'new' => '', 'diff' => join(',', $addedAccountList));
if(!empty($removedAccountList)) $changes[] = array('field' => 'removeDiff', 'old' => '', 'new' => '', 'diff' => join(',', $removedAccountList));
if(!empty($changes)) $this->action->logHistory($actionID, $changes);
return !dao::isError();
}
+32 -3
View File
@@ -263,7 +263,8 @@ class projectTao extends projectModel
/* Only changed account update userview. */
$oldAccounts = array_keys($oldJoin);
$removedAccounts = array_diff($oldAccounts, $accounts);
$changedAccounts = array_merge($removedAccounts, array_diff($accounts, $oldAccounts));
$addedAccounts = array_diff($accounts, $oldAccounts);
$changedAccounts = array_merge($removedAccounts, $addedAccounts);
$changedAccounts = array_unique($changedAccounts);
$childSprints = $this->dao->select('id')->from(TABLE_PROJECT)
@@ -283,8 +284,21 @@ class projectTao extends projectModel
if(!empty($childSprints)) $this->user->updateUserView($childSprints, 'sprint', $changedAccounts);
if(!empty($linkedProducts)) $this->user->updateUserView(array_keys($linkedProducts), 'product', $changedAccounts);
if(empty($addedAccounts) && empty($removedAccounts)) return;
/* Log history. */
$actionID = $this->loadModel('action')->create('project', $projectID, 'ManagedTeam');
$users = $this->loadModel('user')->getPairs('noletter');
$addedAccountList = array_map(function($account) use ($users) { return zget($users, $account); }, $addedAccounts);
$removedAccountList = array_map(function($account) use ($users) { return zget($users, $account); }, $removedAccounts);
if(!empty($addedAccountList)) $changes[] = array('field' => 'addDiff', 'old' => '', 'new' => '', 'diff' => join(',', $addedAccountList));
if(!empty($removedAccountList)) $changes[] = array('field' => 'removeDiff', 'old' => '', 'new' => '', 'diff' => join(',', $removedAccountList));
if(!empty($changes)) $this->action->logHistory($actionID, $changes);
/* Remove execution members. */
if($this->post->removeExecution == 'yes' and !empty($childSprints) and !empty($removedAccounts))
if($this->post->removeExecution == 'yes' and !empty($childSprints) and !empty($removedAccountList))
{
$this->dao->delete()->from(TABLE_TEAM)
->where('root')->in($childSprints)
@@ -629,16 +643,31 @@ class projectTao extends projectModel
* @param array|int $projectIdList
* @param string $type
* @param string $account
* @param string $realname
* @param array $changes
* @access protected
* @return bool
*/
protected function unlinkTeamMember(int|array $projectIdList, string $type, string $account): bool
protected function unlinkTeamMember(int|array $projectIdList, string $type, string $account, string $realname, array $changes): bool
{
$accountProjects = $this->dao->select('root')->from(TABLE_TEAM)
->where('root')->in($projectIdList)
->andWhere('type')->eq($type)
->andWhere('account')->eq($account)
->fetchPairs();
$this->dao->delete()->from(TABLE_TEAM)
->where('root')->in($projectIdList)
->andWhere('type')->eq($type)
->andWhere('account')->eq($account)
->exec();
$this->loadModel('action');
foreach($accountProjects as $projectID)
{
$actionID = $this->action->create($type, $projectID, $type == 'project' ? 'managedTeam' : 'syncProjectTeam');
$this->action->logHistory($actionID, $changes);
}
return !dao::isError();
}
+1 -1
View File
@@ -16,7 +16,7 @@ jsVar('projectID', $project->id);
jsVar('copyProjectID', $copyProjectID);
jsVar('oldAccountList', array_keys($currentMembers));
jsVar('unlinkExecutionMembers', $lang->project->unlinkExecutionMembers);
jsVar('executionMembers', $executionMembers);
jsVar('executionMembers', array_values($executionMembers));
/* zin: Define the set::module('team') feature bar on main menu. */
$copyTeamBox = '';