diff --git a/module/program/control.php b/module/program/control.php index 23ff841b66..7dfedb9695 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -564,9 +564,7 @@ class program extends control $account = $this->dao->select('user')->from(TABLE_STAKEHOLDER)->where('id')->eq($stakeholderID)->fetch('user'); $this->dao->delete()->from(TABLE_STAKEHOLDER)->where('id')->eq($stakeholderID)->exec(); - $this->loadModel('user')->updateUserView($programID, 'program', array($account)); - $this->updateChildUserView($programID, $account); - + $this->program->updateChildUserView($programID, array($account)); return $this->send(array('result' => 'success', 'load' => true)); } @@ -592,31 +590,10 @@ class program extends control $account = $this->dao->select('user')->from(TABLE_STAKEHOLDER)->where('id')->in($stakeholderIDList)->fetchPairs('user'); $this->dao->delete()->from(TABLE_STAKEHOLDER)->where('id')->in($stakeholderIDList)->exec(); - $this->loadModel('user')->updateUserView($programID, 'program', $account); - $this->updateChildUserView($programID, $account); - + $this->program->updateChildUserView($programID, $account); return $this->send(array('result' => 'success', 'load' => true)); } - /** - * Update children user view. - * - * @param int $programID - * @param array $account - * @access protected - * @return void - */ - protected function updateChildUserView($programID = 0, $account = array()) - { - $childPGMList = $this->dao->select('id')->from(TABLE_PROJECT)->where('path')->like("%,$programID,%")->andWhere('type')->eq('program')->fetchPairs(); - $childPRJList = $this->dao->select('id')->from(TABLE_PROJECT)->where('path')->like("%,$programID,%")->andWhere('type')->eq('project')->fetchPairs(); - $childProducts = $this->dao->select('id')->from(TABLE_PRODUCT)->where('program')->eq($programID)->fetchPairs(); - - if(!empty($childPGMList)) $this->user->updateUserView($childPGMList, 'program', array($account)); - if(!empty($childPRJList)) $this->user->updateUserView($childPRJList, 'project', array($account)); - if(!empty($childProducts)) $this->user->updateUserView($childProducts, 'product', array($account)); - } - /** * Export program. * diff --git a/module/program/model.php b/module/program/model.php index e172d95bfc..5d43f79be3 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1299,15 +1299,30 @@ class programModel extends model $changedAccounts = array_unique($changedAccounts); $this->loadModel('user')->updateUserView($programID, 'program', $changedAccounts); + return $this->updateChildUserView($programID, $changedAccounts); + } - /* Update children user view. */ - $childPrograms = $this->dao->select('id')->from(TABLE_PROJECT)->where('path')->like("%,$programID,%")->andWhere('type')->eq('program')->fetchPairs(); - $childProjects = $this->dao->select('id')->from(TABLE_PROJECT)->where('path')->like("%,$programID,%")->andWhere('type')->eq('project')->fetchPairs(); - $childProducts = $this->dao->select('id')->from(TABLE_PRODUCT)->where('program')->eq($programID)->fetchPairs(); + /** + * 更新项目集及子项的用户视图。 + * Update user view of program and its children. + * + * @param int $programID + * @param array $account + * @access public + * @return bool + */ + public function updateChildUserView(int $programID = 0, array $accounts = array()): bool + { + $this->loadModel('user')->updateUserView($programID, 'program', $accounts); - if(!empty($childPrograms)) $this->user->updateUserView($childPrograms, 'program', $changedAccounts); - if(!empty($childProjects)) $this->user->updateUserView($childProjects, 'project', $changedAccounts); - if(!empty($childProducts)) $this->user->updateUserView($childProducts, 'product', $changedAccounts); + $programList = $this->dao->select('id')->from(TABLE_PROJECT)->where('path')->like("%,$programID,%")->andWhere('type')->eq('program')->fetchPairs(); + $projectList = $this->loadModel('project')->getPairsByProgram($programID, 'all', true); + $productList = $this->loadModel('product')->getPairs('', $programID); + + if(!empty($programList)) $this->user->updateUserView($programList, 'program', $accounts); + if(!empty($projectList)) $this->user->updateUserView(array_keys($projectList), 'project', $accounts); + if(!empty($productList)) $this->user->updateUserView(array_keys($productList), 'product', $accounts); + return !dao::isError(); } /**