From 55976aeb2659f5f2b2a126e02fe235d7e4b1af8f Mon Sep 17 00:00:00 2001 From: leiyong <1549684884@qq.com> Date: Thu, 19 Nov 2020 17:32:08 +0800 Subject: [PATCH] * Query the program and project logic when upgrading. --- module/upgrade/control.php | 12 +++++----- module/upgrade/js/mergeprogram.js | 4 ++-- module/upgrade/model.php | 27 ++++++++++++++++++++-- module/upgrade/view/createprogram.html.php | 2 +- 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/module/upgrade/control.php b/module/upgrade/control.php index 0f0af5ef92..f97fb0fa46 100644 --- a/module/upgrade/control.php +++ b/module/upgrade/control.php @@ -428,26 +428,26 @@ class upgrade extends control $this->view->noMergedSprints = $noMergedSprints; } - $programs = $this->dao->select('*')->from(TABLE_PROJECT)->where('deleted')->eq(0)->andWhere('type')->eq('program')->fetchPairs('id', 'name'); + $programs = $this->upgrade->getProgramPairs(); $this->view->title = $this->lang->upgrade->mergeProgram; $this->view->programs = $programs; - $this->view->projects = $this->dao->select('*')->from(TABLE_PROJECT)->where('deleted')->eq(0)->andWhere('type')->eq('project')->andWhere('parent')->eq(key($programs))->fetchPairs('id', 'name'); + $this->view->projects = $this->upgrade->getProjectPairsByProgram(key($programs)); $this->view->users = $this->loadModel('user')->getPairs('noclosed|noempty'); $this->view->groups = $this->loadModel('group')->getPairs(); $this->display(); } /** - * Gets the program under the project set. + * Get the project of the program it belongs to. * - * @param int $programID + * @param int $programID * @access public * @return void */ - public function ajaxGetProjectByProgram($programID = 0) + public function ajaxGetProjectPairsByProgram($programID = 0) { - $projects = $this->dao->select('*')->from(TABLE_PROJECT)->where('deleted')->eq(0)->andWhere('type')->eq('project')->andWhere('parent')->eq($programID)->fetchPairs('id', 'name'); + $projects = $this->upgrade->getProjectPairsByProgram($programID); die(html::select('projects', $projects, '', 'class="form-control"')); } diff --git a/module/upgrade/js/mergeprogram.js b/module/upgrade/js/mergeprogram.js index d95afd2882..d8cb8e0dcb 100644 --- a/module/upgrade/js/mergeprogram.js +++ b/module/upgrade/js/mergeprogram.js @@ -109,10 +109,10 @@ $(function() toggleProject($('form #newProject0')); }); -function projectByProgram(obj) +function getProjectByProgram(obj) { var programID = $(obj).val(); - var link = createLink('upgrade', 'ajaxGetProjectByProgram', 'programID=' + programID); + var link = createLink('upgrade', 'ajaxGetProjectPairsByProgram', 'programID=' + programID); $.post(link, function(data) { $('#projects').replaceWith(data); diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 8b09013573..2c2407570c 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -1413,6 +1413,29 @@ class upgradeModel extends model return $this->app->getAppRoot() . 'db' . DS . 'update' . $version . '.sql'; } + /** + * Gets program key-value pairs. + * + * @access public + * @return string + */ + public function getProgramPairs() + { + return $this->dao->select('*')->from(TABLE_PROGRAM)->where('deleted')->eq(0)->andWhere('type')->eq('program')->orderBy('id_asc')->fetchPairs('id', 'name'); + } + + /** + * Get the project of the program it belongs to. + * + * @param string $programID + * @access public + * @return string + */ + public function getProjectPairsByProgram($programID = 0) + { + return $this->dao->select('*')->from(TABLE_PROJECT)->where('deleted')->eq(0)->andWhere('type')->eq('project')->andWhere('parent')->eq($programID)->fetchPairs('id', 'name'); + } + /** * Execute a sql. * @@ -3938,7 +3961,7 @@ class upgradeModel extends model $this->dao->insert(TABLE_PROJECT)->data($program) ->batchcheck('name,begin', 'notempty') ->checkIF($program->end != '', 'end', 'gt', $program->begin) - ->check('name', 'unique', "deleted='0'") + ->check('name', 'unique', "deleted='0' and type= 'program'") ->exec(); if(dao::isError()) return false; @@ -3976,7 +3999,7 @@ class upgradeModel extends model $this->dao->insert(TABLE_PROJECT)->data($project) ->batchcheck('name', 'notempty') - ->check('name', 'unique', "deleted='0'") + ->check('name', 'unique', "deleted='0' and type = 'project'") ->exec(); if(dao::isError()) return false; diff --git a/module/upgrade/view/createprogram.html.php b/module/upgrade/view/createprogram.html.php index bf857b4952..0a06bf7fec 100644 --- a/module/upgrade/view/createprogram.html.php +++ b/module/upgrade/view/createprogram.html.php @@ -5,7 +5,7 @@ upgrade->existPGM;?>
- +