diff --git a/module/branch/model.php b/module/branch/model.php index 111fa63718..2201ad1b8c 100644 --- a/module/branch/model.php +++ b/module/branch/model.php @@ -82,12 +82,14 @@ class branchModel extends model * * @param array $products * @param string $params + * @param array $appendBranch * @access public * @return array */ - public function getByProducts($products, $params = '') + public function getByProducts($products, $params = '', $appendBranch = '') { - $branches = $this->dao->select('*')->from(TABLE_BRANCH)->where('product')->in($products)->andWhere('deleted')->eq(0)->orderBy('`order`')->fetchAll(); + $branches = $this->dao->select('*')->from(TABLE_BRANCH)->where('product')->in($products)->andWhere('deleted')->eq(0)->orderBy('`order`')->fetchAll('id'); + if(!empty($appendBranch)) $branches += $this->dao->select('*')->from(TABLE_BRANCH)->where('id')->in($appendBranch)->orderBy('`order`')->fetchAll('id'); $products = $this->loadModel('product')->getByIdList($products); $branchGroups = array(); @@ -154,6 +156,12 @@ class branchModel extends model $case = $this->dao->select('id')->from(TABLE_CASE)->where('branch')->eq($branchID)->andWhere('deleted')->eq(0)->limit(1)->fetch(); $release = $this->dao->select('id')->from(TABLE_RELEASE)->where('branch')->eq($branchID)->andWhere('deleted')->eq(0)->limit(1)->fetch(); $build = $this->dao->select('id')->from(TABLE_BUILD)->where('branch')->eq($branchID)->andWhere('deleted')->eq(0)->limit(1)->fetch(); - return empty($module) and empty($story) and empty($bug) and empty($case) and empty($release) and empty($build) and empty($plan); + $project = $this->dao->select('t1.id')->from(TABLE_PROJECT)->alias('t1') + ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t2')->on('t1.id=t2.project') + ->where('t2.branch')->eq($branchID) + ->andWhere('t1.deleted')->eq(0) + ->limit(1) + ->fetch(); + return empty($module) && empty($story) && empty($bug) && empty($case) && empty($release) && empty($build) && empty($plan) && empty($project); } } diff --git a/module/project/control.php b/module/project/control.php index 60f1303222..baf1643134 100644 --- a/module/project/control.php +++ b/module/project/control.php @@ -1025,9 +1025,11 @@ class project extends control $allProducts = array(0 => '') + $this->loadModel('product')->getPairs('noclosed|nocode'); $linkedProducts = $this->project->getProducts($project->id); + $linkedBranches = array(); foreach($linkedProducts as $product) { if(!isset($allProducts[$product->id])) $allProducts[$product->id] = $product->name; + if($product->branch) $linkedBranches[$product->branch] = $product->branch; } $this->view->title = $title; @@ -1041,7 +1043,7 @@ class project extends control $this->view->groups = $this->loadModel('group')->getPairs(); $this->view->allProducts = $allProducts; $this->view->linkedProducts = $linkedProducts; - $this->view->branchGroups = $this->loadModel('branch')->getByProducts(array_keys($linkedProducts)); + $this->view->branchGroups = $this->loadModel('branch')->getByProducts(array_keys($linkedProducts), '', $linkedBranches); $this->display(); } @@ -1291,6 +1293,11 @@ class project extends control if(!$project) die(js::error($this->lang->notFound) . js::locate('back')); $products = $this->project->getProducts($project->id); + $linkedBranches = array(); + foreach($products as $product) + { + if($product->branch) $linkedBranches[$product->branch] = $product->branch; + } /* Set menu. */ $this->project->setMenu($this->projects, $project->id); @@ -1301,7 +1308,7 @@ class project extends control $this->view->project = $project; $this->view->products = $products; - $this->view->branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products)); + $this->view->branchGroups = $this->loadModel('branch')->getByProducts(array_keys($products), '', $linkedBranches); $this->view->planGroups = $this->project->getPlans($products); $this->view->groups = $this->loadModel('group')->getPairs(); $this->view->actions = $this->loadModel('action')->getList('project', $projectID); @@ -1599,10 +1606,12 @@ class project extends control $allProducts = $this->product->getPairs('noclosed|nocode'); $linkedProducts = $this->project->getProducts($project->id); + $linkedBranches = array(); // Merge allProducts and linkedProducts for closed product. foreach($linkedProducts as $product) { if(!isset($allProducts[$product->id])) $allProducts[$product->id] = $product->name; + if(!empty($product->branch)) $linkedBranches[$product->branch] = $product->branch; } /* Assign. */ @@ -1610,7 +1619,7 @@ class project extends control $this->view->position = $position; $this->view->allProducts = $allProducts; $this->view->linkedProducts = $linkedProducts; - $this->view->branchGroups = $this->loadModel('branch')->getByProducts(array_keys($allProducts)); + $this->view->branchGroups = $this->loadModel('branch')->getByProducts(array_keys($allProducts), '', $linkedBranches); $this->display(); }