From fee94264f3cc2db45388c7b3371de1d1ced594ce Mon Sep 17 00:00:00 2001 From: liuhong Date: Wed, 10 May 2023 09:11:38 +0800 Subject: [PATCH] split projectControl::ajaxGetCopyProjects to projectModel::getCopyProjectPairs. --- module/project/control.php | 23 +++++++---------------- module/project/model.php | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/module/project/control.php b/module/project/control.php index b8b3e27080..62a7cde7bd 100755 --- a/module/project/control.php +++ b/module/project/control.php @@ -123,32 +123,23 @@ class project extends control } /** - * Ajax get projects. + * 复制Kanban项目,获取项目数据。 + * Ajax get the kanban copy project. * * @access public * @return void */ public function ajaxGetCopyProjects() { - $data = fixer::input('post')->get(); + /* Get replicable kanban project pairs by model. */ + $projectKeys = $this->project->getCopyProjectPairs($this->post->name, $this->post->model); + $projects = $this->project->getPairsByModel('', 0, '', $projectKeys); - $model = $data->model; - if($data->model == 'agileplus') $model = array('scrum', 'agileplus'); - if($data->model == 'waterfallplus') $model = array('waterfall', 'waterfallplus'); - - $projectPairs = $this->dao->select('id, name')->from(TABLE_PROJECT) - ->where('type')->eq('project') - ->andWhere('deleted')->eq(0) - ->andWhere('vision')->eq($this->config->vision) - ->andWhere('model')->in($model) - ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->projects)->fi() - ->beginIF(trim($data->name))->andWhere('name')->like("%$data->name%")->fi() - ->fetchPairs(); - $projects = $this->project->getPairsByModel('', 0, '', array_keys($projectPairs)); + /* Building render pages requires data. */ $html = empty($projects) ? "
{$this->lang->noData}
" : ''; foreach($projects as $id => $name) { - $active = $data->cpoyProjectID == $id ? 'active' : ''; + $active = $this->post->cpoyProjectID == $id ? 'active' : ''; $html .= "
" . html::icon($this->lang->icons['project'], 'text-muted') . $name . "
"; } echo $html; diff --git a/module/project/model.php b/module/project/model.php index 0df25de042..a5751f8db7 100755 --- a/module/project/model.php +++ b/module/project/model.php @@ -832,6 +832,30 @@ class projectModel extends model ->fetchPairs('id', 'name'); } + /** + * 获取可复制项目的键值对。 + * get the copy project pairs. + * + * @param string $name + * @param string $model + * + * @access public + * @return array + */ + public function getCopyProjectPairs(string $name, string $model = 'kanban'): array + { + $projectPairs = $this->dao->select('id, name')->from(TABLE_PROJECT) + ->where('type')->eq('project') + ->andWhere('deleted')->eq(0) + ->andWhere('vision')->eq($this->config->vision) + ->andWhere('model')->eq($model) + ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->projects)->fi() + ->beginIF(trim($name))->andWhere('name')->like("%$name%")->fi() + ->fetchPairs(); + + return array_keys($projectPairs); + } + /** * 根据项目ID获取关联产品及分支 * Get branches by project id.