From 45ff3731970c3193b2cd7cbbb69b01415e8c96e9 Mon Sep 17 00:00:00 2001 From: chenfeiCF Date: Thu, 17 Nov 2016 09:02:25 +0800 Subject: [PATCH] * finish task #2694. --- module/project/control.php | 97 ++++++++++++------------------ module/project/js/story.js | 1 + module/project/model.php | 72 +++++++++++++++++++++- module/project/view/story.html.php | 1 + module/story/model.php | 63 +++++++++++++++---- 5 files changed, 160 insertions(+), 74 deletions(-) diff --git a/module/project/control.php b/module/project/control.php index 8799a214d1..244211d17c 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -190,7 +190,7 @@ class project extends control /* Build the search form. */ $actionURL = $this->createLink('project', 'task', "projectID=$projectID&status=bySearch¶m=myQueryID"); $this->config->project->search['onMenuBar'] = 'yes'; - $this->project->buildSearchForm($projectID, $this->projects, $queryID, $actionURL); + $this->project->buildTaskSearchForm($projectID, $this->projects, $queryID, $actionURL); /* team member pairs. */ $memberPairs = array(); @@ -539,17 +539,11 @@ class project extends control $project = $this->commonAction($projectID); - /* Header and position. */ - $title = $project->name . $this->lang->colon . $this->lang->project->story; - $position[] = html::a($this->createLink('project', 'browse', "projectID=$projectID"), $project->name); - $position[] = $this->lang->project->story; - /* Load pager. */ $this->app->loadClass('pager', $static = true); $pager = new pager($recTotal, $recPerPage, $pageID); - /* The pager. */ - $stories = $this->story->getProjectStories($projectID, $sort, $type, $param, $pager); + $stories = $this->story->getProjectStories($projectID, $sort, $type, $param, $pager); $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story', false); $storyTasks = $this->task->getStoryTaskCounts(array_keys($stories), $projectID); $users = $this->user->getPairs('noletter'); @@ -561,8 +555,25 @@ class project extends control /* Get project's product. */ $productID = 0; - $products = $this->loadModel('product')->getProductsByProject($projectID); - if($products) $productID = key($products); + $productPairs = $this->loadModel('product')->getProductsByProject($projectID); + if($productPairs) $productID = key($productPairs); + + /* Build the search form. */ + $modules = array(); + $products = $this->project->getProducts($projectID); + foreach($products as $product) + { + $productModules = $this->loadModel('tree')->getOptionMenu($product->id); + foreach($productModules as $moduleID => $moduleName) $modules[$moduleID] = $moduleName; + } + $actionURL = $this->createLink('project', 'story', "projectID=$projectID&orderBy=$orderBy&type=bySearch&queryID=myQueryID"); + $branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products), 'noempty'); + $this->project->buildStorySearchForm($products, $branchGroups, $modules, $queryID, $actionURL, 'projectStory'); + + /* Header and position. */ + $title = $project->name . $this->lang->colon . $this->lang->project->story; + $position[] = html::a($this->createLink('project', 'browse', "projectID=$projectID"), $project->name); + $position[] = $this->lang->project->story; /* Assign. */ $this->view->title = $title; @@ -578,7 +589,7 @@ class project extends control $this->view->tabID = 'story'; $this->view->users = $users; $this->view->pager = $pager; - $this->view->branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products), 'noempty'); + $this->view->branchGroups = $branchGroups; $this->display(); } @@ -1688,62 +1699,25 @@ class project extends control $queryID = ($browseType == 'bySearch') ? (int)$param : 0; - $branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products), 'noempty'); - $branchPairs = array(); - $productType = 'normal'; - $productNum = count($products); - $branches = array(); - $modules = array(); - $this->loadModel('tree'); + /* Set modules and branches. */ + $modules = array(); + $branches = array(); + $productType = 'normal'; foreach($products as $product) { - $productPairs[$product->id] = $product->name; + $productModules = $this->loadModel('tree')->getOptionMenu($product->id); + foreach($productModules as $moduleID => $moduleName) $modules[$moduleID] = $moduleName; if($product->type != 'normal') { - $branches[$product->branch] = $product->branch; $productType = $product->type; - if($product->branch) - { - $branchPairs[$product->branch] = ($productNum > 1 ? $product->name . '/' : '') . $branchGroups[$product->id][$product->branch]; - } - else - { - $productBranches = isset($branchGroups[$product->id]) ? $branchGroups[$product->id] : array(0); - if($productNum > 1) - { - foreach($productBranches as $branchID => $branchName) $productBranches[$branchID] = $product->name . '/' . $branchName; - } - $branchPairs += $productBranches; - } + $branches[$product->branch] = $product->branch; } - foreach($this->tree->getOptionMenu($product->id) as $moduleID => $moduleName) $modules[$moduleID] = $moduleName; } - /* Build search form. */ - if(count($products) >= 2) unset($this->config->product->search['fields']['module']); - $this->config->product->search['actionURL'] = $this->createLink('project', 'linkStory', "projectID=$projectID&browseType=bySearch&queryID=myQueryID"); - $this->config->product->search['queryID'] = $queryID; - $this->config->product->search['params']['product']['values'] = $productPairs + array('all' => $this->lang->product->allProductsOfProject); - $this->config->product->search['params']['plan']['values'] = $this->loadModel('productplan')->getForProducts($products); - if(count($products) == 1) $this->config->product->search['params']['module']['values'] = $modules; - unset($this->lang->story->statusList['draft']); - if($productType == 'normal') - { - unset($this->config->product->search['fields']['branch']); - unset($this->config->product->search['params']['branch']); - } - else - { - $this->config->product->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$productType]); - $this->config->product->search['params']['branch']['values'] = array('' => '') + $branchPairs; - } - $this->config->product->search['params']['status'] = array('operator' => '=', 'control' => 'select', 'values' => $this->lang->story->statusList); - - $this->loadModel('search')->setSearchParams($this->config->product->search); - - $title = $project->name . $this->lang->colon . $this->lang->project->linkStory; - $position[] = html::a($browseLink, $project->name); - $position[] = $this->lang->project->linkStory; + /* Build the search form. */ + $actionURL = $this->createLink('project', 'linkStory', "projectID=$projectID&browseType=bySearch&queryID=myQueryID"); + $branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products), 'noempty'); + $this->project->buildStorySearchForm($products, $branchGroups, $modules, $queryID, $actionURL); if($browseType == 'bySearch') { @@ -1755,6 +1729,11 @@ class project extends control } $prjStories = $this->story->getProjectStoryPairs($projectID); + /* Assign. */ + $title = $project->name . $this->lang->colon . $this->lang->project->linkStory; + $position[] = html::a($browseLink, $project->name); + $position[] = $this->lang->project->linkStory; + $this->view->title = $title; $this->view->position = $position; $this->view->project = $project; diff --git a/module/project/js/story.js b/module/project/js/story.js index babe4e8d1a..1f62e91ff6 100644 --- a/module/project/js/story.js +++ b/module/project/js/story.js @@ -1,5 +1,6 @@ $(function() { + ajaxGetSearchForm(); fixedTfootAction('#projectStoryForm'); fixedTheadOfList('#storyList'); }); diff --git a/module/project/model.php b/module/project/model.php index 20b13fbd34..b12564f22a 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -967,6 +967,74 @@ class projectModel extends model return $query->fetchAll('id'); } + /** + * Build story search form. + * + * @param array $products + * @param array $branchGroups + * @param array $modules + * @param int $queryID + * @param string $actionURL + * @param string $type + * @access public + * @return void + */ + public function buildStorySearchForm($products, $branchGroups, $modules, $queryID, $actionURL, $type = 'projectStory') + { + $branchPairs = array(); + $productType = 'normal'; + $productNum = count($products); + foreach($products as $product) + { + $productPairs[$product->id] = $product->name; + if($product->type != 'normal') + { + $productType = $product->type; + if($product->branch) + { + $branchPairs[$product->branch] = (count($products) > 1 ? $product->name . '/' : '') . $branchGroups[$product->id][$product->branch]; + } + else + { + $productBranches = isset($branchGroups[$product->id]) ? $branchGroups[$product->id] : array(0); + if(count($products) > 1) + { + foreach($productBranches as $branchID => $branchName) $productBranches[$branchID] = $product->name . '/' . $branchName; + } + $branchPairs += $productBranches; + } + } + } + + /* Build search form. */ + if($type == 'projectStory') + { + $this->config->product->search['module'] = 'projectStory'; + unset($this->config->product->search['fields']['stage']); + unset($this->config->product->search['params']['stage']); + } + $this->config->product->search['actionURL'] = $actionURL; + $this->config->product->search['queryID'] = $queryID; + $this->config->product->search['params']['product']['values'] = $productPairs + array('all' => $this->lang->product->allProductsOfProject); + $this->config->product->search['params']['plan']['values'] = $this->loadModel('productplan')->getForProducts($products); + if(count($products) == 1) $this->config->product->search['params']['module']['values'] = $modules; + unset($this->lang->story->statusList['draft']); + if(count($products) >= 2) unset($this->config->product->search['fields']['module']); + if($productType == 'normal') + { + unset($this->config->product->search['fields']['branch']); + unset($this->config->product->search['params']['branch']); + } + else + { + $this->config->product->search['fields']['branch'] = sprintf($this->lang->product->branch, $this->lang->product->branchName[$productType]); + $this->config->product->search['params']['branch']['values'] = array('' => '') + $branchPairs; + } + $this->config->product->search['params']['status'] = array('operator' => '=', 'control' => 'select', 'values' => $this->lang->story->statusList); + + $this->loadModel('search')->setSearchParams($this->config->product->search); + } + /** * Get projects to import * @@ -1917,7 +1985,7 @@ class projectModel extends model } /** - * Build search form. + * Build task search form. * * @param int $projectID * @param array $projects @@ -1926,7 +1994,7 @@ class projectModel extends model * @access public * @return void */ - public function buildSearchForm($projectID, $projects, $queryID, $actionURL) + public function buildTaskSearchForm($projectID, $projects, $queryID, $actionURL) { $this->config->project->search['actionURL'] = $actionURL; $this->config->project->search['queryID'] = $queryID; diff --git a/module/project/view/story.html.php b/module/project/view/story.html.php index 6365ef3e9f..ae862fc9da 100644 --- a/module/project/view/story.html.php +++ b/module/project/view/story.html.php @@ -35,6 +35,7 @@ ?> +
diff --git a/module/story/model.php b/module/story/model.php index cb7e0030da..9b8c01e86a 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -1504,19 +1504,56 @@ class storyModel extends model { if(defined('TUTORIAL')) return $this->loadModel('tutorial')->getProjectStories(); - $modules = ($type == 'byModule' and $param) ? $this->dao->select('*')->from(TABLE_MODULE)->where('path')->like("%,$param,%")->andWhere('type')->eq('story')->fetchPairs('id', 'id') : array(); - $stories = $this->dao->select('distinct t1.*, t2.*,t3.branch as productBranch,t4.type as productType,t2.version as version')->from(TABLE_PROJECTSTORY)->alias('t1') - ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') - ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t3')->on('t1.project = t3.project') - ->leftJoin(TABLE_PRODUCT)->alias('t4')->on('t2.product = t4.id') - ->where('t1.project')->eq((int)$projectID) - ->beginIF($type == 'byProduct')->andWhere('t1.product')->eq($param)->fi() - ->beginIF($type == 'byBrach')->andWhere('t2.branch')->eq($param)->fi() - ->beginIF($type == 'byModule' and $param)->andWhere('t2.module')->in($modules)->fi() - ->andWhere('t2.deleted')->eq(0) - ->orderBy($orderBy) - ->page($pager, 't2.id') - ->fetchAll('id'); + if($type == 'bySearch') + { + $queryID = (int)$param; + $products = $this->loadModel('project')->getProducts($projectID); + + if($this->session->projectStoryQuery == false) $this->session->set('projectStoryQuery', ' 1 = 1'); + if($queryID) + { + $query = $this->loadModel('search')->getQuery($queryID); + if($query) + { + $this->session->set('projectStoryQuery', $query->sql); + $this->session->set('projectStoryForm', $query->form); + } + } + + $allProduct = "`product` = 'all'"; + $storyQuery = $this->session->projectStoryQuery; + if(strpos($this->session->projectStoryQuery, $allProduct) !== false) + { + $storyQuery = str_replace($allProduct, '1', $this->session->projectStoryQuery); + } + $storyQuery = preg_replace('/`(\w+)`/', 't2.`$1`', $storyQuery); + + $stories = $this->dao->select('distinct t1.*, t2.*, t3.branch as productBranch, t4.type as productType, t2.version as version')->from(TABLE_PROJECTSTORY)->alias('t1') + ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') + ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t3')->on('t1.project = t3.project') + ->leftJoin(TABLE_PRODUCT)->alias('t4')->on('t2.product = t4.id') + ->where($storyQuery) + ->andWhere('t1.project')->eq((int)$projectID) + ->orderBy($orderBy) + ->page($pager) + ->fetchAll('id'); + } + else + { + $modules = ($type == 'byModule' and $param) ? $this->dao->select('*')->from(TABLE_MODULE)->where('path')->like("%,$param,%")->andWhere('type')->eq('story')->fetchPairs('id', 'id') : array(); + $stories = $this->dao->select('distinct t1.*, t2.*,t3.branch as productBranch,t4.type as productType,t2.version as version')->from(TABLE_PROJECTSTORY)->alias('t1') + ->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id') + ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t3')->on('t1.project = t3.project') + ->leftJoin(TABLE_PRODUCT)->alias('t4')->on('t2.product = t4.id') + ->where('t1.project')->eq((int)$projectID) + ->beginIF($type == 'byProduct')->andWhere('t1.product')->eq($param)->fi() + ->beginIF($type == 'byBrach')->andWhere('t2.branch')->eq($param)->fi() + ->beginIF($type == 'byModule' and $param)->andWhere('t2.module')->in($modules)->fi() + ->andWhere('t2.deleted')->eq(0) + ->orderBy($orderBy) + ->page($pager, 't2.id') + ->fetchAll('id'); + } $query = $this->dao->get(); $branches = array();