diff --git a/module/program/model.php b/module/program/model.php index 5d43f79be3..ae462612af 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1263,45 +1263,6 @@ class programModel extends model ->fetch('count'); } - /** - * Create stakeholder for a program. - * - * @param int $programID - * @access public - * @return void - */ - public function createStakeholder($programID = 0) - { - $data = (array)fixer::input('post')->get(); - - $accounts = array_unique($data['accounts']); - $oldJoin = $this->dao->select('`user`, createdDate')->from(TABLE_STAKEHOLDER)->where('objectID')->eq((int)$programID)->andWhere('objectType')->eq('program')->fetchPairs(); - $this->dao->delete()->from(TABLE_STAKEHOLDER)->where('objectID')->eq((int)$programID)->andWhere('objectType')->eq('program')->exec(); - - foreach($accounts as $account) - { - if(empty($account)) continue; - - $stakeholder = new stdclass(); - $stakeholder->objectID = $programID; - $stakeholder->objectType = 'program'; - $stakeholder->user = $account; - $stakeholder->createdBy = $this->app->user->account; - $stakeholder->createdDate = isset($oldJoin[$account]) ? $oldJoin[$account] : helper::today(); - - $this->dao->insert(TABLE_STAKEHOLDER)->data($stakeholder)->exec(); - } - - /* If any account changed, update his view. */ - $oldAccounts = array_keys($oldJoin); - $changedAccounts = array_diff($accounts, $oldAccounts); - $changedAccounts = array_merge($changedAccounts, array_diff($oldAccounts, $accounts)); - $changedAccounts = array_unique($changedAccounts); - - $this->loadModel('user')->updateUserView($programID, 'program', $changedAccounts); - return $this->updateChildUserView($programID, $changedAccounts); - } - /** * 更新项目集及子项的用户视图。 * Update user view of program and its children. diff --git a/module/program/test/model/updatechilduserview.php b/module/program/test/model/updatechilduserview.php new file mode 100644 index 0000000000..4708cb01ce --- /dev/null +++ b/module/program/test/model/updatechilduserview.php @@ -0,0 +1,22 @@ +#!/usr/bin/env php +gen(20); +zdTable('product')->gen(20); +zdTable('userview')->gen(5); + +/** + +title=测试 programModel::updateChildUserView(); +timeout=0 +cid=1 + +*/ + +$programTester = new programTest(); + +r($programTester->updateChildUserViewTest(0, array('test1', 'test2'))) && p('', '|') && e(',2'); // 获取项目集2下未完成的项目和项目集数量 +r($programTester->updateChildUserViewTest(2, array('test1', 'test2'))) && p() && e('0'); // 获取项目集1下未完成的项目和项目集数量 diff --git a/module/program/test/program.class.php b/module/program/test/program.class.php index e0cb5c98e2..077a79604f 100644 --- a/module/program/test/program.class.php +++ b/module/program/test/program.class.php @@ -135,6 +135,21 @@ class programTest return $this->program->getStakeholdersByPrograms($programID); } + /** + * Test updateChildUserView method. + * + * @param int $programID + * @param array $accounts + * @access public + * @return void + */ + public function updateChildUserViewTest($programID, $accounts = array()) + { + $stakeHolder = $this->program->updateChildUserView($programID, $accounts); + + return $this->program->dao->select('*')->from(TABLE_USERVIEW)->where('account')->eq('test2')->fetch('programs'); + } + /** * Create default program. *