diff --git a/module/bug/model.php b/module/bug/model.php index f20a1d0af6..e2c7b1c1da 100644 --- a/module/bug/model.php +++ b/module/bug/model.php @@ -530,7 +530,7 @@ class bugModel extends model ->andWhere('tostory')->eq(0) ->andWhere('toTask')->eq(0) ->beginIF(!empty($products))->andWhere('product')->in($products)->fi() - ->beginIF($branch)->andWhere('branch')->in("0,$branch")->fi() + ->beginIF($branch !== '' and $branch !== 'all')->andWhere('branch')->in("0,$branch")->fi() ->beginIF(!empty($executions))->andWhere('execution')->in($executions)->fi() ->beginIF($excludeBugs)->andWhere('id')->notIN($excludeBugs)->fi() ->andWhere('deleted')->eq(0) @@ -2499,7 +2499,7 @@ class bugModel extends model } $allBranch = "`branch` = 'all'"; - if($branch !== 'all' and strpos($bugQuery, '`branch` =') === false) $bugQuery .= " AND `branch` in($branch)"; + if($branch !== 'all' and strpos($bugQuery, '`branch` =') === false) $bugQuery .= " AND `branch` in('$branch')"; if(strpos($bugQuery, $allBranch) !== false) $bugQuery = str_replace($allBranch, '1', $bugQuery); $allProject = "`project` = 'all'"; diff --git a/module/execution/control.php b/module/execution/control.php index dc9d109154..7c3e5b42d1 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -771,7 +771,7 @@ class execution extends control $storyBugs = $this->loadModel('bug')->getStoryBugCounts($storyIdList, $executionID); $storyCases = $this->loadModel('testcase')->getStoryCaseCounts($storyIdList); - $plans = $this->execution->getPlans($products, true, true); + $plans = $this->execution->getPlans($products, 'skipParent|withMainPlan'); $allPlans = array('' => ''); if(!empty($plans)) { @@ -1284,7 +1284,7 @@ class execution extends control $projectID = $copyExecution->project; $products = $this->loadModel('product')->getProducts($copyExecutionID); $branches = $this->project->getBranchesByProject($copyExecutionID); - $plans = $this->loadModel('productplan')->getGroupByProduct(array_keys($products), true, 'unexpired'); + $plans = $this->loadModel('productplan')->getGroupByProduct(array_keys($products), 'skipParent|unexpired'); $branchGroups = $this->execution->getBranchByProduct(array_keys($products), $projectID); $linkedBranches = array(); @@ -1501,7 +1501,7 @@ class execution extends control $linkedBranches = array(); $linkedProducts = $this->product->getProducts($executionID); $branches = $this->project->getBranchesByProject($executionID); - $plans = $this->productplan->getGroupByProduct(array_keys($linkedProducts), true); + $plans = $this->productplan->getGroupByProduct(array_keys($linkedProducts), 'skipParent'); $executionStories = $this->project->getStoriesByProject($executionID); /* If the story of the product which linked the execution, you don't allow to remove the product. */ @@ -1514,6 +1514,7 @@ class execution extends control { $linkedBranches[$productID][$branchID] = $branchID; $productPlans[$productID][$branchID] = isset($plans[$productID][$branchID]) ? $plans[$productID][$branchID] : array(); + if($branchID != BRANCH_MAIN and isset($plans[$productID][BRANCH_MAIN])) $productPlans[$productID][$branchID] += $plans[$productID][BRANCH_MAIN]; if(!empty($executionStories[$productID][$branchID])) { array_push($unmodifiableProducts, $productID); @@ -2492,7 +2493,7 @@ class execution extends control $this->loadModel('branch'); foreach($products as $product) { - $productModules = $this->tree->getOptionMenu($product->id, 'story', 0, array_keys(array(BRANCH_MAIN) + $branches[$product->id])); + $productModules = $this->tree->getOptionMenu($product->id, 'story', 0, $branches[$product->id]); foreach($productModules as $branch => $branchModules) { foreach($branchModules as $moduleID => $moduleName) $modules[$moduleID] = ((count($products) >= 2 and $moduleID != 0) ? $product->name : '') . $moduleName; diff --git a/module/execution/js/common.js b/module/execution/js/common.js index 931619845d..19313ec0a8 100644 --- a/module/execution/js/common.js +++ b/module/execution/js/common.js @@ -162,13 +162,10 @@ function loadBranches(product) $inputgroup.addClass('has-branch').append(data); $inputgroup.find('select:last').attr('name', 'branch[' + index + ']').attr('id', 'branch' + index).attr('onchange', "loadPlans('#products" + index + "', this.value)").chosen(); } - }); - setTimeout(function() - { - var branchID = $('#branch0').val(); + var branchID = $('#branch' + index).val(); loadPlans(product, branchID); - },100) + }); } function loadPlans(product, branchID) diff --git a/module/execution/model.php b/module/execution/model.php index 79c404459c..3e4d3cd85d 100644 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -1728,18 +1728,6 @@ class executionModel extends model if($branchID != BRANCH_MAIN) $branchPairs[$branchID] = ((count($products) > 1) ? $product->name . '/' : '') . $branchGroups[$product->id][$branchID]; } } - else - { - $productBranches = isset($branchGroups[$product->id]) ? $branchGroups[$product->id] : array(0); - if(count($products) > 1) - { - foreach($productBranches as $branchID => $branchName) - { - if($branchID !== BRANCH_MAIN) $productBranches[$branchID] = $product->name . '/' . $branchName; - } - } - $branchPairs += $productBranches; - } } } @@ -3667,14 +3655,15 @@ class executionModel extends model * Get plans by $productID. * * @param int|array $productID - * @param bool $skipParent + * @param string $param withMainPlan|skipParent * @return mixed */ - public function getPlans($products, $skipParent = false, $withMainPlan = false) + public function getPlans($products, $param = '') { $this->loadModel('productplan'); - $branchIDList = $withMainPlan ? array(BRANCH_MAIN) : array(); + $param = strtolower($param); + $branchIDList = strpos($param, 'withmainplan') !== false ? array(BRANCH_MAIN => BRANCH_MAIN) : array(); foreach($products as $product) { foreach($product->branches as $branchID) $branchIDList[$branchID] = $branchID; @@ -3684,7 +3673,7 @@ class executionModel extends model ->where('product')->in(array_keys($products)) ->andWhere('deleted')->eq(0) ->andWhere('branch')->in($branchIDList)->fi() - ->beginIF($skipParent)->andWhere('parent')->ne(-1)->fi() + ->beginIF(strpos($param, 'skipparent') !== false)->andWhere('parent')->ne(-1)->fi() ->orderBy('begin desc') ->fetchAll('id'); diff --git a/module/productplan/control.php b/module/productplan/control.php index 8cd9a5eb48..2f899559f5 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -417,10 +417,8 @@ class productplan extends control $this->config->product->search['queryID'] = $queryID; $this->config->product->search['style'] = 'simple'; $this->config->product->search['params']['product']['values'] = $products + array('all' => $this->lang->product->allProductsOfProject); - $this->config->product->search['params']['plan']['values'] = $this->productplan->getPairs($plan->product, $plan->branch, '', true); - - $modules = $this->loadModel('tree')->getOptionMenu($plan->product, 'story', 0, $plan->branch ? array(BRANCH_MAIN, $plan->branch) : array(BRANCH_MAIN)); - $this->config->product->search['params']['module']['values'] = $plan->branch ? $modules[BRANCH_MAIN] + $modules[$plan->branch] : $modules[BRANCH_MAIN]; + $this->config->product->search['params']['plan']['values'] = $this->productplan->getPairsForStory($plan->product, $plan->branch, 'skipParent|withMainPlan'); + $this->config->product->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($plan->product, 'story', 0, $plan->branch); $storyStatusList = $this->lang->story->statusList; unset($storyStatusList['closed']); $this->config->product->search['params']['status'] = array('operator' => '=', 'control' => 'select', 'values' => $storyStatusList); @@ -442,7 +440,7 @@ class productplan extends control if($browseType == 'bySearch') { - $allStories = $this->story->getBySearch($plan->product, $plan->branch ? "0,{$plan->branch}" : 0, $queryID, 'id', '', 'story', array_keys($planStories), $pager); + $allStories = $this->story->getBySearch($plan->product, "0,{$plan->branch}", $queryID, 'id', '', 'story', array_keys($planStories), $pager); } else { @@ -559,13 +557,12 @@ class productplan extends control $this->config->bug->search['actionURL'] = $this->createLink('productplan', 'view', "planID=$planID&type=bug&orderBy=$orderBy&link=true¶m=" . helper::safe64Encode('&browseType=bySearch&queryID=myQueryID')); $this->config->bug->search['queryID'] = $queryID; $this->config->bug->search['style'] = 'simple'; - $this->config->bug->search['params']['plan']['values'] = $this->productplan->getPairs($productID, $plan->branch, '', true); + $this->config->bug->search['params']['plan']['values'] = $this->productplan->getPairsForStory($productID, $plan->branch, 'skipParent|withMainPlan'); $this->config->bug->search['params']['execution']['values'] = $this->loadModel('product')->getExecutionPairsByProduct($plan->product, $plan->branch); $this->config->bug->search['params']['openedBuild']['values'] = $this->loadModel('build')->getProductBuildPairs($productID, $branch = 0, $params = ''); $this->config->bug->search['params']['resolvedBuild']['values'] = $this->build->getProductBuildPairs($productID, $branch = 0, $params = ''); if($this->config->systemMode == 'new') $this->config->bug->search['params']['project']['values'] = $this->product->getProjectPairsByProduct($productID, $plan->branch); - $modules = $this->loadModel('tree')->getOptionMenu($plan->product, 'bug', 0, $plan->branch ? array(BRANCH_MAIN, $plan->branch) : array(BRANCH_MAIN)); - $this->config->bug->search['params']['module']['values'] = $plan->branch ? $modules[BRANCH_MAIN] + $modules[$plan->branch] : $modules[BRANCH_MAIN]; + $this->config->bug->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($plan->product, 'bug', 0, $plan->branch); unset($this->config->bug->search['fields']['product']); if($this->session->currentProductType == 'normal') @@ -586,11 +583,11 @@ class productplan extends control if($browseType == 'bySearch') { - $allBugs = $this->bug->getBySearch($productID, $plan->branch ? "0,{$plan->branch}" : 0, $queryID, 'id_desc', array_keys($planBugs), $pager); + $allBugs = $this->bug->getBySearch($productID, $plan->branch, $queryID, 'id_desc', array_keys($planBugs), $pager); } else { - $allBugs = $this->bug->getActiveBugs($productID, "0,{$plan->branch}", $executions, array_keys($planBugs), $pager); + $allBugs = $this->bug->getActiveBugs($productID, $plan->branch, $executions, array_keys($planBugs), $pager); } $this->view->allBugs = $allBugs; diff --git a/module/productplan/model.php b/module/productplan/model.php index 333d7b8de2..568c89058d 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -212,35 +212,24 @@ class productplanModel extends model * * @param array|int $product * @param int $branch - * @param bool $skipParent + * @param string $param skipParent|withMainPlan|unexpired * @access public * @return array */ - public function getPairsForStory($product = 0, $branch = '', $skipParent = false) + public function getPairsForStory($product = 0, $branch = '', $param = '') { - $date = date('Y-m-d'); - $plans = $this->dao->select('id,title,parent,begin,end')->from(TABLE_PRODUCTPLAN) + $date = date('Y-m-d'); + $param = strtolower($param); + $branch = strpos($param, 'withmainplan') !== false ? "0,$branch" : $branch; + $plans = $this->dao->select('id,title,parent,begin,end')->from(TABLE_PRODUCTPLAN) ->where('product')->in($product) ->andWhere('deleted')->eq(0) - ->andWhere('end')->ge($date) + ->beginIF(strpos($param, 'unexpired') !== false)->andWhere('end')->ge($date)->fi() ->beginIF($branch !== 'all' or $branch !== '')->andWhere("branch")->in($branch)->fi() - ->beginIF($skipParent)->andWhere('parent')->ne(-1)->fi() + ->beginIF(strpos($param, 'skipparent') !== false)->andWhere('parent')->ne(-1)->fi() ->orderBy('begin desc') ->fetchAll('id'); - if(!$plans) - { - $plans = $this->dao->select('id,title,parent,begin,end')->from(TABLE_PRODUCTPLAN) - ->where('product')->in($product) - ->andWhere('deleted')->eq(0) - ->andWhere('end')->lt($date) - ->beginIF($branch !== 'all' or $branch !== '')->andWhere("branch")->in($branch)->fi() - ->beginIF($skipParent)->andWhere('parent')->ne(-1)->fi() - ->orderBy('begin desc') - ->limit(5) - ->fetchAll('id'); - } - $plans = $this->reorder4Children($plans); $planPairs = array(); $parentTitle = array(); @@ -286,19 +275,19 @@ class productplanModel extends model * Get plan group by product id list. * * @param string|array $products - * @param bool $skipParent - * @param string $expired + * @param string $param skipParent|unexpired * @access public * @return array */ - public function getGroupByProduct($products = '', $skipParent = false, $expired = '') + public function getGroupByProduct($products = '', $param = '') { $date = date('Y-m-d'); + $param = strtolower($param); $plans = $this->dao->select('id,title,parent,begin,end,product,branch')->from(TABLE_PRODUCTPLAN) ->where('deleted')->eq(0) ->beginIF($products)->andWhere('product')->in($products)->fi() - ->beginIF($skipParent)->andWhere('parent')->ne(-1)->fi() - ->beginIF($expired == 'unexpired')->andWhere('end')->ge($date)->fi() + ->beginIF(strpos($param, 'skipparent') !== false)->andWhere('parent')->ne(-1)->fi() + ->beginIF(strpos($param, 'unexpired') !== false)->andWhere('end')->ge($date)->fi() ->orderBy('id_desc') ->fetchAll('id'); @@ -422,18 +411,21 @@ class productplanModel extends model $this->loadModel('score')->create('productplan', 'create', $planID); if(!empty($plan->parent)) { - $this->dao->update(TABLE_PRODUCTPLAN)->set('parent')->eq('-1')->where('id')->eq($plan->parent)->andWhere('parent')->eq('0')->exec(); - - /* Transfer stories and bugs linked with the parent plan to the child plan. */ - $this->dao->update(TABLE_PLANSTORY)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec(); - $this->dao->update(TABLE_BUG)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec(); - $stories = $this->dao->select('*')->from(TABLE_STORY)->where('plan')->like("%{$plan->parent}%")->fetchAll('id'); - foreach($stories as $storyID => $story) + $parentPlan = $this->getByID($plan->parent); + if($parentPlan->parent == '0') { - $storyPlan = trim($story->plan, ','); - if(strpos(",$storyPlan,", ",{$plan->parent},") === false) continue; - $storyPlan = str_replace(",{$plan->parent},", ",$planID,", ",$storyPlan,"); - $this->dao->update(TABLE_STORY)->set('plan')->eq($storyPlan)->where('id')->eq($storyID)->exec(); + $this->dao->update(TABLE_PRODUCTPLAN)->set('parent')->eq('-1')->where('id')->eq($plan->parent)->andWhere('parent')->eq('0')->exec(); + + /* Transfer stories and bugs linked with the parent plan to the child plan. */ + $this->dao->update(TABLE_PLANSTORY)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec(); + $this->dao->update(TABLE_BUG)->set('plan')->eq($planID)->where('plan')->eq($plan->parent)->exec(); + $stories = $this->dao->select('*')->from(TABLE_STORY)->where("CONCAT(',', plan, ',')")->like("%,{$plan->parent},%")->fetchAll('id'); + foreach($stories as $storyID => $story) + { + $storyPlan = trim($story->plan, ','); + $storyPlan = str_replace(",{$plan->parent},", ",$planID,", ",$storyPlan,"); + $this->dao->update(TABLE_STORY)->set('plan')->eq($storyPlan)->where('id')->eq($storyID)->exec(); + } } } return $planID; diff --git a/module/project/control.php b/module/project/control.php index 1e50c7fbb1..b250b2a388 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -542,7 +542,7 @@ class project extends control $linkedProducts = $this->loadModel('product')->getProducts($projectID); $parentProject = $this->program->getByID($project->parent); $branches = $this->project->getBranchesByProject($projectID); - $plans = $this->productplan->getGroupByProduct(array_keys($linkedProducts), true); + $plans = $this->productplan->getGroupByProduct(array_keys($linkedProducts), 'skipParent'); $projectStories = $this->project->getStoriesByProject($projectID); $projectBranches = $this->project->getBranchGroupByProject($projectID, array_keys($linkedProducts)); diff --git a/module/release/control.php b/module/release/control.php index 5f84c20297..2b85d3eb10 100644 --- a/module/release/control.php +++ b/module/release/control.php @@ -418,10 +418,9 @@ class release extends control $this->config->product->search['actionURL'] = $this->createLink('release', 'view', "releaseID=$releaseID&type=story&link=true¶m=" . helper::safe64Encode('&browseType=bySearch&queryID=myQueryID')); $this->config->product->search['queryID'] = $queryID; $this->config->product->search['style'] = 'simple'; - $this->config->product->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairs($release->product, $release->branch, '', true); + $this->config->product->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairsForStory($release->product, $release->branch, 'skipParent|withMainPlan'); $this->config->product->search['params']['status'] = array('operator' => '=', 'control' => 'select', 'values' => $this->lang->story->statusList); - $modules = $this->loadModel('tree')->getOptionMenu($release->product, 'story', 0, $release->branch ? array(BRANCH_MAIN, $release->branch) : array(BRANCH_MAIN)); - $this->config->product->search['params']['module']['values'] = $release->branch ? $modules[BRANCH_MAIN] + $modules[$release->branch] : $modules[BRANCH_MAIN]; + $this->config->product->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($release->product, 'story', 0, $release->branch);; if($this->session->currentProductType == 'normal') { unset($this->config->product->search['fields']['branch']); @@ -537,12 +536,11 @@ class release extends control $this->config->bug->search['actionURL'] = $this->createLink('release', 'view', "releaseID=$releaseID&type=$type&link=true¶m=" . helper::safe64Encode('&browseType=bySearch&queryID=myQueryID')); $this->config->bug->search['queryID'] = $queryID; $this->config->bug->search['style'] = 'simple'; - $this->config->bug->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairs($release->product, $release->branch, '', true); + $this->config->bug->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairsForStory($release->product, $release->branch, 'skipParent|withMainPlan'); $this->config->bug->search['params']['execution']['values'] = $this->loadModel('product')->getExecutionPairsByProduct($release->product, $release->branch); $this->config->bug->search['params']['openedBuild']['values'] = $this->loadModel('build')->getProductBuildPairs($release->product, $branch = 0, $params = ''); $this->config->bug->search['params']['resolvedBuild']['values'] = $this->config->bug->search['params']['openedBuild']['values']; - $modules = $this->loadModel('tree')->getOptionMenu($release->product, 'bug', 0, $release->branch ? array(BRANCH_MAIN, $release->branch) : array(BRANCH_MAIN)); - $this->config->bug->search['params']['module']['values'] = $release->branch ? $modules[BRANCH_MAIN] + $modules[$release->branch] : $modules[BRANCH_MAIN]; + $this->config->bug->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($release->product, 'bug', 0, $release->branch); if($this->session->currentProductType == 'normal') { unset($this->config->bug->search['fields']['branch']); diff --git a/module/story/control.php b/module/story/control.php index fed4248cd6..a0df5f627b 100644 --- a/module/story/control.php +++ b/module/story/control.php @@ -310,7 +310,7 @@ class story extends control $this->view->users = $users; $this->view->moduleID = $moduleID ? $moduleID : (int)$this->cookie->lastStoryModule; $this->view->moduleOptionMenu = $moduleOptionMenu; - $this->view->plans = $this->loadModel('productplan')->getPairsForStory($productID, $branch, true); + $this->view->plans = $this->loadModel('productplan')->getPairsForStory($productID, $branch, 'skipParent'); $this->view->planID = $planID; $this->view->source = $source; $this->view->sourceNote = $sourceNote; @@ -464,7 +464,7 @@ class story extends control $moduleOptionMenu['ditto'] = $this->lang->story->ditto; - $plans = $this->loadModel('productplan')->getPairsForStory($productID, $branch === 'all' ? 0 : $branch, true); + $plans = $this->loadModel('productplan')->getPairsForStory($productID, $branch === 'all' ? 0 : $branch, 'skipParent'); $plans['ditto'] = $this->lang->story->ditto; $priList = (array)$this->lang->story->priList; @@ -666,7 +666,7 @@ class story extends control $this->view->stories = $stories; $this->view->users = $users; $this->view->product = $product; - $this->view->plans = $this->loadModel('productplan')->getPairs($story->product, $story->branch, '', true); + $this->view->plans = $this->loadModel('productplan')->getPairsForStory($story->product, $story->branch, 'skipParent'); $this->view->products = $myProducts + $othersProducts; $this->view->branches = $branches; $this->view->reviewers = implode(',', $reviewerList); diff --git a/module/testcase/control.php b/module/testcase/control.php index b718917aca..a3313df26c 100644 --- a/module/testcase/control.php +++ b/module/testcase/control.php @@ -1596,7 +1596,7 @@ class testcase extends control if($product->type != 'normal') $fields['branchValue'] = $this->lang->product->branchName[$product->type]; $projectID = $this->app->tab == 'project' ? $this->session->project : 0; - $branches = $this->loadModel('branch')->getPairs($productID, '' ,$projectID); + $branches = $this->loadModel('branch')->getPairs($productID, '' , $projectID); foreach($branches as $branchID => $branchName) $branches[$branchID] = $branchName . "(#$branchID)"; $modules = $this->loadModel('tree')->getOptionMenu($productID, 'case');