From bcb443b1bd96870cc8ce3ae13f342d49d57659cc Mon Sep 17 00:00:00 2001 From: tianshujie Date: Thu, 31 Aug 2023 17:00:39 +0800 Subject: [PATCH] * Refactor manageMembers method. --- module/execution/config/form.php | 8 +++ module/execution/control.php | 20 +++---- module/execution/js/managemembers.ui.js | 2 +- module/execution/model.php | 63 ++++++---------------- module/execution/ui/managemembers.html.php | 16 +++--- module/execution/zen.php | 29 ++++++++++ 6 files changed, 73 insertions(+), 65 deletions(-) diff --git a/module/execution/config/form.php b/module/execution/config/form.php index 9420eb99e6..cfd5a581b8 100644 --- a/module/execution/config/form.php +++ b/module/execution/config/form.php @@ -14,3 +14,11 @@ $config->execution->form->setkanban['minColWidth'] = array('type' => 'int', $config->execution->form->setkanban['maxColWidth'] = array('type' => 'int', 'required' => false); $config->execution->form->fixfirst['estimate'] = array('type' => 'float', 'required' => false); + +$config->execution->form->managemembers['account'] = array('type' => 'string', 'required' => false, 'default' => '', 'base' => true); +$config->execution->form->managemembers['role'] = array('type' => 'string', 'required' => false, 'default' => ''); +$config->execution->form->managemembers['days'] = array('type' => 'int', 'required' => false, 'default' => 0); +$config->execution->form->managemembers['hours'] = array('type' => 'float', 'required' => false, 'default' => 0); +$config->execution->form->managemembers['limited'] = array('type' => 'string', 'required' => false, 'default' => 'no'); +$config->execution->form->managemembers['type'] = array('type' => 'string', 'required' => false, 'default' => 'execution'); +$config->execution->form->managemembers['root'] = array('type' => 'int', 'required' => false, 'default' => 0); diff --git a/module/execution/control.php b/module/execution/control.php index 55536cf8a6..67b2a469c9 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -2908,6 +2908,7 @@ class execution extends control } /** + * 维护执行的团队成员 * Manage members of the execution. * * @param int $executionID @@ -2918,25 +2919,24 @@ class execution extends control */ public function manageMembers(int $executionID = 0, int $team2Import = 0, int $dept = 0) { + $execution = $this->execution->getByID($executionID); if(!empty($_POST)) { - $this->execution->manageMembers($executionID); + $memberDataList = $this->executionZen->buildMembersForManageMembers($execution); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + + $this->execution->manageMembers($execution, $memberDataList); if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError())); $this->loadModel('action')->create('team', $executionID, 'managedTeam'); - return $this->send(array('message' => $this->lang->saveSuccess, 'result' => 'success', 'load' => array('back' => true))); + return $this->sendSuccess(array('load' => array('back' => true))); } - /* Load model. */ - $this->loadModel('user'); $this->loadModel('dept'); - - $execution = $this->execution->getById($executionID); $deptUsers = empty($dept) ? array() : $this->dept->getDeptUserPairs($dept); $currentMembers = $this->execution->getTeamMembers($executionID); $members2Import = $this->execution->getMembers2Import($team2Import, array_keys($currentMembers)); - $teams2Import = $this->loadModel('personnel')->getCopiedObjects($executionID, 'sprint', true); /* Append users for get users. */ $appendUsers = array(); @@ -2952,11 +2952,11 @@ class execution extends control $this->view->title = $this->lang->execution->manageMembers . $this->lang->colon . $execution->name; $this->view->execution = $execution; - $this->view->users = $this->user->getPairs('noclosed|nodeleted|devfirst', $appendUsers); + $this->view->users = $this->loadModel('user')->getPairs('noclosed|nodeleted|devfirst', $appendUsers); $this->view->roles = $this->user->getUserRoles(array_keys($this->view->users)); $this->view->dept = $dept; - $this->view->depts = $this->loadModel('dept')->getOptionMenu(); - $this->view->teams2Import = $teams2Import; + $this->view->depts = $this->dept->getOptionMenu(); + $this->view->teams2Import = $this->loadModel('personnel')->getCopiedObjects($executionID, 'sprint', true); $this->view->team2Import = $team2Import; $this->view->teamMembers = $this->executionZen->buildMembers($currentMembers, $members2Import, $deptUsers, $execution->days); $this->display(); diff --git a/module/execution/js/managemembers.ui.js b/module/execution/js/managemembers.ui.js index 183e6916a0..ef72b70839 100644 --- a/module/execution/js/managemembers.ui.js +++ b/module/execution/js/managemembers.ui.js @@ -67,7 +67,7 @@ function choseTeam2Copy() */ window.setRole = function(roleID) { - const account = $(`input[name='accounts\[${roleID}\]']`).val(); + const account = $(`input[name='account\[${roleID}\]']`).val(); const role = roles[account]; const $role = $('#role' + roleID); $role.val(role); diff --git a/module/execution/model.php b/module/execution/model.php index 4a1fd8bada..bfbb4939cf 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -3614,70 +3614,41 @@ class executionModel extends model } /** + * 维护执行团队成员。 * Manage team members. * - * @param int $executionID + * @param object $execution + * @param array $members * @access public * @return void */ - public function manageMembers($executionID) + public function manageMembers(object $execution, array $members) { - $execution = $this->getByID($executionID); - $data = (array)fixer::input('post')->get(); - - extract($data); - $executionID = (int)$executionID; - $executionType = 'execution'; - $accounts = array_unique($accounts); - $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq($executionType)->fetchPairs(); - - foreach($accounts as $key => $account) - { - if(empty($account)) continue; - - if(!empty($execution->days) and (int)$days[$key] > $execution->days) - { - dao::$errors['days'] = sprintf($this->lang->execution->daysGreaterProject, $execution->days); - return false; - } - if((float)$hours[$key] > 24) - { - dao::$errors['hours'] = $this->lang->execution->errorHours; - return false; - } - } - - $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq($executionType)->exec(); + $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq($execution->id)->andWhere('type')->eq('execution')->fetchPairs(); + $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq($execution->id)->andWhere('type')->eq('execution')->exec(); + $accountList = array(); $executionMember = array(); - foreach($accounts as $key => $account) + foreach($members as $member) { - if(empty($account)) continue; + if(in_array($member->account, $accountList)) continue;; - $member = new stdclass(); - $member->role = $roles[$key]; - $member->days = $days[$key]; - $member->hours = $hours[$key]; - $member->limited = $limited[$key]; + $member->join = isset($oldJoin[$member->account]) ? $oldJoin[$member->account] : helper::today(); + $executionMember[$member->account] = $member; + $accountList[] = $member->account; - $member->root = $executionID; - $member->account = $account; - $member->join = isset($oldJoin[$account]) ? $oldJoin[$account] : helper::today(); - $member->type = $executionType; - - $executionMember[$account] = $member; $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); /* Add the execution team members to the project. */ if($execution->project) $this->addProjectMembers($execution->project, $executionMember); - if($execution->acl != 'open') $this->updateUserView($executionID, 'sprint', $changedAccounts); + if($execution->acl != 'open') $this->updateUserView($execution->id, 'sprint', $changedAccountList); } /** diff --git a/module/execution/ui/managemembers.html.php b/module/execution/ui/managemembers.html.php index 296e40e27c..aa72082681 100644 --- a/module/execution/ui/managemembers.html.php +++ b/module/execution/ui/managemembers.html.php @@ -72,15 +72,15 @@ foreach($teamMembers as $member) $member->memberType == 'default' ? h::td( input ( - set::id("realnames{$i}"), - set::name("realnames[$i]"), + set::id("realname{$i}"), + set::name("realname[$i]"), set::value($member->realname), set::readonly(true), ), input ( - set::id("accounts{$i}"), - set::name("accounts[$i]"), + set::id("account{$i}"), + set::name("account[$i]"), set::value($member->account), set::type('hidden'), ), @@ -88,7 +88,7 @@ foreach($teamMembers as $member) picker ( set::id("account{$i}"), - set::name("accounts[$i]"), + set::name("account[$i]"), set::value($member->account), set::items($users), set('data-max-list-count', $config->maxCount), @@ -100,7 +100,7 @@ foreach($teamMembers as $member) input ( set::id("role{$i}"), - set::name("roles[$i]"), + set::name("role[$i]"), set::value($member->role), ) ), @@ -162,7 +162,7 @@ h::table picker ( set::id("account{$i}"), - set::name("accounts[$i]"), + set::name("account[$i]"), set::items($users), set('data-max-list-count', $config->maxCount), set('onchange', "setRole('{$i}')"), @@ -173,7 +173,7 @@ h::table input ( set::id("role{$i}"), - set::name("roles[$i]"), + set::name("role[$i]"), ) ), h::td diff --git a/module/execution/zen.php b/module/execution/zen.php index fa99786e31..2898a26b64 100644 --- a/module/execution/zen.php +++ b/module/execution/zen.php @@ -325,6 +325,35 @@ class executionZen extends execution return $teamMembers; } + /** + * 构造待更新的团队成员数据。 + * Construct the team member data to be updated. + * + * @param object $execution + * @access protected + * @return array + */ + protected function buildMembersForManageMembers(object $execution) + { + $members = form::batchData()->get(); + + foreach($members as $rowIndex => $member) + { + $member->root = $execution->id; + if(!empty($execution->days) and $member->days > $execution->days) + { + dao::$errors["days[$rowIndex]"] = sprintf($this->lang->execution->daysGreaterProject, $execution->days); + return false; + } + if($member->hours > 24) + { + dao::$errors["hours[$rowIndex]"] = $this->lang->execution->errorHours; + return false; + } + } + return $members; + } + /** * 设置最近五次执行。 * Set the recent five executions.