diff --git a/module/execution/model.php b/module/execution/model.php index df9c0acdb2..a1fcfd5cdc 100644 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -2280,11 +2280,12 @@ class executionModel extends model $data = (array)fixer::input('post')->get(); extract($data); - $executionType = strpos('sprint|stage', $execution->type) !== false ? 'execution' : $execution->type; + $executionID = (int)$executionID; + $executionType = 'execution'; $accounts = array_unique($accounts); $limited = array_values($limited); - $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq((int)$executionID)->andWhere('type')->eq($executionType)->fetchPairs(); - $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq((int)$executionID)->andWhere('type')->eq($executionType)->exec(); + $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq($executionType)->fetchPairs(); + $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq($executionType)->exec(); $executionMember = array(); foreach($accounts as $key => $account) @@ -2297,13 +2298,13 @@ class executionModel extends model $member->hours = $hours[$key]; $member->limited = $limited[$key]; - $member->root = (int)$executionID; + $member->root = $executionID; $member->account = $account; $member->join = isset($oldJoin[$account]) ? $oldJoin[$account] : helper::today(); $member->type = $executionType; $executionMember[$account] = $member; - $this->dao->replace(TABLE_TEAM)->data($member)->exec(); + $this->dao->insert(TABLE_TEAM)->data($member)->exec(); } /* Only changed account update userview. */ @@ -2312,36 +2313,23 @@ class executionModel extends model $changedAccounts = array_merge($changedAccounts, array_diff($oldAccounts, $accounts)); $changedAccounts = array_unique($changedAccounts); - if($executionType == 'execution') - { - $childSprints = $this->dao->select('id')->from(TABLE_EXECUTION)->where('project')->eq($execution->id)->andWhere('type')->in('stage,sprint')->andWhere('deleted')->eq('0')->fetchPairs(); - $linkedProducts = $this->loadModel('product')->getProductPairsByProject($execution->id); - - $this->loadModel('user')->updateUserView(array($executionID), 'execution', $changedAccounts); - if(!empty($childSprints)) $this->user->updateUserView($childSprints, 'sprint', $changedAccounts); - if(!empty($linkedProducts)) $this->user->updateUserView(array_keys($linkedProducts), 'product', $changedAccounts); - } - - /* Add iteration or phase team members to the execution team. */ - if($executionType == 'stage' || $executionType == 'sprint') - { - $this->addExecutionMembers($execution->project, $executionMember); - if($execution->acl != 'open') $this->updateUserView($executionID, 'sprint', $changedAccounts); - } + /* Add the execution team members to the project. */ + $this->addProjectMembers($execution->project, $executionMember); + if($execution->acl != 'open') $this->updateUserView($executionID, 'sprint', $changedAccounts); } /** - * Add iteration or phase team members to the execution team. + * Add the execution team members to the project. * - * @param int $executionID + * @param int $projectID * @param array $members * @access public * @return void */ - public function addExecutionMembers($executionID = 0, $members = array()) + public function addProjectMembers($projectID = 0, $members = array()) { - $executionType = 'execution'; - $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq($executionID)->andWhere('type')->eq($executionType)->fetchPairs(); + $projectType = 'project'; + $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq($projectID)->andWhere('type')->eq($projectType)->fetchPairs(); $accounts = array(); foreach($members as $account => $member) @@ -2349,9 +2337,9 @@ class executionModel extends model if(isset($oldJoin[$member->account])) continue; $accounts[] = $member->account; - $member->root = $executionID; - $member->type = $executionType; - $this->dao->replace(TABLE_TEAM)->data($member)->exec(); + $member->root = $projectID; + $member->type = $projectType; + $this->dao->insert(TABLE_TEAM)->data($member)->exec(); } /* Only changed account update userview. */ @@ -2360,8 +2348,8 @@ class executionModel extends model $changedAccounts = array_merge($changedAccounts, array_diff($oldAccounts, $accounts)); $changedAccounts = array_unique($changedAccounts); - $this->loadModel('user')->updateUserView($executionID, $executionType, $changedAccounts); - $linkedProducts = $this->loadModel('product')->getProductPairsByProject($executionID); + $this->loadModel('user')->updateUserView($projectID, $projectType, $changedAccounts); + $linkedProducts = $this->loadModel('product')->getProductPairsByProject($projectID); if(!empty($linkedProducts)) $this->user->updateUserView(array_keys($linkedProducts), 'product', $changedAccounts); } diff --git a/module/personnel/model.php b/module/personnel/model.php index 1a7655f439..436f40e1ea 100644 --- a/module/personnel/model.php +++ b/module/personnel/model.php @@ -74,11 +74,11 @@ class personnelModel extends model ->orderBy('id_desc') ->fetchAll('id'); if(empty($projects)) return $personnelList; - $accountPairs = $this->getInvolvedProjects($projects); + if(empty($accountPairs)) return $personnelList; - $executionPairs = $this->getInvolvedExecutions($projects); + $executionPairs = $this->getInvolvedExecutions($projects); $taskInvest = $this->getProjectTaskInvest($projects, $accountPairs); $bugAndStoryInvest = $this->getBugAndStoryInvest($accountPairs, $programID); if(isset($this->config->maxVersion)) @@ -267,7 +267,7 @@ class personnelModel extends model return $this->dao->select('account, count(root) as executions')->from(TABLE_TEAM) ->where('root')->in(array_keys($executions)) - ->andWhere('type')->in('stage,sprint') + ->andWhere('type')->in('execution') ->groupBy('account') ->fetchPairs('account'); } diff --git a/module/project/control.php b/module/project/control.php index 6e49f67ac4..485862fd2f 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -1036,7 +1036,7 @@ class project extends control if(!empty($_POST)) { - $this->execution->manageMembers($projectID); + $this->project->manageMembers($projectID); $link = $this->createLink('project', 'manageMembers', "projectID=$projectID"); $this->send(array('message' => $this->lang->saveSuccess, 'result' => 'success', 'locate' => $link)); } diff --git a/module/project/model.php b/module/project/model.php index 830ac2b291..f005c47db4 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -1227,6 +1227,60 @@ class projectModel extends model } } + /** + * Manage team members. + * + * @param int $projectID + * @access public + * @return void + */ + public function manageMembers($projectID) + { + $project = $this->getByID($projectID); + $data = (array)fixer::input('post')->get(); + + extract($data); + $projectID = (int)$projectID; + $projectType = 'project'; + $accounts = array_unique($accounts); + $limited = array_values($limited); + $oldJoin = $this->dao->select('`account`, `join`')->from(TABLE_TEAM)->where('root')->eq($projectID)->andWhere('type')->eq($projectType)->fetchPairs(); + $this->dao->delete()->from(TABLE_TEAM)->where('root')->eq($projectID)->andWhere('type')->eq($projectType)->exec(); + + $projectMember = array(); + foreach($accounts as $key => $account) + { + if(empty($account)) continue; + + $member = new stdclass(); + $member->role = $roles[$key]; + $member->days = $days[$key]; + $member->hours = $hours[$key]; + $member->limited = $limited[$key]; + + $member->root = $projectID; + $member->account = $account; + $member->join = isset($oldJoin[$account]) ? $oldJoin[$account] : helper::today(); + $member->type = $projectType; + + $projectMember[$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); + + $childSprints = $this->dao->select('id')->from(TABLE_PROJECT)->where('project')->eq($projectID)->andWhere('type')->in('stage,sprint')->andWhere('deleted')->eq('0')->fetchPairs(); + $linkedProducts = $this->loadModel('product')->getProductPairsByProject($projectID); + + $this->loadModel('user')->updateUserView(array($projectID), 'project', $changedAccounts); + if(!empty($childSprints)) $this->user->updateUserView($childSprints, 'sprint', $changedAccounts); + if(!empty($linkedProducts)) $this->user->updateUserView(array_keys($linkedProducts), 'product', $changedAccounts); + } + /** * Print datatable cell. *