diff --git a/module/productplan/control.php b/module/productplan/control.php index 780601d007..38ac2d476b 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -84,7 +84,7 @@ class productplan extends control } $this->commonAction($productID, $branchID); - $lastPlan = $this->productplan->getLast($productID, $branchID, $parent); + $lastPlan = $this->productplan->getLast($productID, '', $parent); $product = $this->loadModel('product')->getById($productID); if($lastPlan) @@ -117,7 +117,7 @@ class productplan extends control $this->view->branches = $branchPairs; $this->view->defaultBranch = $defaultBranch; $this->view->parent = $parent; - $this->view->parentPlanPairs = $this->productplan->getTopPlanPairs($productID, $branchID, 'done,closed'); + $this->view->parentPlanPairs = $this->productplan->getTopPlanPairs($productID, '', 'done,closed'); $this->display(); } @@ -973,6 +973,6 @@ class productplan extends control public function ajaxGetTopPlan($productID, $branch = 0) { $parentPlanPairs = $this->productplan->getTopPlanPairs($productID, $branch); - return print(html::select('parent', array('0' => '') + $parentPlanPairs, '', 'class="form-control"')); + return print(html::select('parent', array(0 => '') + $parentPlanPairs, 0, 'class="form-control"')); } } diff --git a/module/productplan/css/browse.css b/module/productplan/css/browse.css index 0c62007c4c..8a0fe5b64d 100644 --- a/module/productplan/css/browse.css +++ b/module/productplan/css/browse.css @@ -1,7 +1,7 @@ .table td.content div {height: 25px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; float: left; max-width: calc(100% - 20px);} .table td.content .more {position: absolute; right: 16px;} .table td.content .more .icon {color: #838a9d;} -td.c-branch {overflow: hidden; text-align: left !important; text-overflow: ellipsis; white-space: nowrap;} +td.c-branch {overflow: hidden; text-align: left !important; white-space: nowrap;} .table-children {border-left: 2px solid #cbd0db; border-right: 2px solid #cbd0db;} .table tbody > tr.table-children.table-child-top {border-top: 2px solid #cbd0db;} diff --git a/module/productplan/js/create.js b/module/productplan/js/create.js index bbf0718f74..bc7db62c3b 100644 --- a/module/productplan/js/create.js +++ b/module/productplan/js/create.js @@ -65,9 +65,12 @@ $('#future').on('change', function() $('#branch').change(function() { - var branchID = $(this).val(); - var lastPlanLink = createLink('productplan', 'ajaxGetLast', "productID=" + productID + "&branch=" + branchID); - var topPlanLink = createLink('productplan', 'ajaxGetTopPlan', "productID=" + productID + "&branch=" + branchID); + var branchIdList = $(this).val(); + if(!branchIdList) return; + + var branchIdList = branchIdList.toString(); + var lastPlanLink = createLink('productplan', 'ajaxGetLast', "productID=" + productID + "&branch=" + branchIdList); + var topPlanLink = createLink('productplan', 'ajaxGetTopPlan', "productID=" + productID + "&branch=" + branchIdList); $.post(lastPlanLink, function(data) { diff --git a/module/productplan/model.php b/module/productplan/model.php index 0ff986ebe6..7fe3f12f32 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -52,15 +52,28 @@ class productplanModel extends model * @access public * @return object */ - public function getLast($productID, $branch = 0, $parent = 0) + public function getLast($productID, $branch = '', $parent = 0) { + $branchQuery = ''; + if($branch !== '') + { + $branchQuery .= '('; + $branchCount = count(explode(',', $branch)); + foreach(explode(',', $branch) as $index => $branchID) + { + $branchQuery .= "CONCAT(',', branch, ',') LIKE '%,$branchID,%'"; + if($index < $branchCount - 1) $branchQuery .= ' AND '; + } + $branchQuery .= ')'; + } + return $this->dao->select('*')->from(TABLE_PRODUCTPLAN) ->where('deleted')->eq(0) ->beginIF($parent <= 0)->andWhere('parent')->le((int)$parent)->fi() ->beginIF($parent > 0)->andWhere('parent')->eq((int)$parent)->fi() ->andWhere('product')->eq((int)$productID) ->andWhere('end')->ne($this->config->productplan->future) - ->andWhere('branch')->eq($branch) + ->beginIF($branch !== '' and !empty($branchQuery))->andWhere($branchQuery)->fi() ->orderBy('end desc') ->limit(1) ->fetch(); @@ -216,9 +229,22 @@ class productplanModel extends model */ public function getTopPlanPairs($productID, $branch = '', $exclude = '') { + $branchQuery = ''; + if($branch !== '') + { + $branchQuery .= '('; + $branchCount = count(explode(',', $branch)); + foreach(explode(',', $branch) as $index => $branchID) + { + $branchQuery .= "CONCAT(',', branch, ',') LIKE '%,$branchID,%'"; + if($index < $branchCount - 1) $branchQuery .= ' AND '; + } + $branchQuery .= ')'; + } + $planPairs = $this->dao->select("id,title")->from(TABLE_PRODUCTPLAN) ->where('product')->eq($productID) - ->beginIF($branch !== '')->andWhere('branch')->eq($branch)->fi() + ->beginIF($branch !== '' and !empty($branchQuery))->andWhere($branchQuery)->fi() ->andWhere('parent')->le(0) ->andWhere('deleted')->eq(0) ->beginIF($exclude)->andWhere('status')->notin($exclude) @@ -450,6 +476,8 @@ class productplanModel extends model ->setIF($this->post->future || empty($_POST['end']), 'end', $this->config->productplan->future) ->setDefault('createdBy', $this->app->user->account) ->setDefault('createdDate', helper::now()) + ->setDefault('branch', 0) + ->join('branch', ',') ->remove('delta,uid,future') ->get(); @@ -466,6 +494,12 @@ class productplanModel extends model } } + $product = $this->loadModel('product')->getByID($plan->product); + if($product->type != 'normal' and empty($plan->branch)) + { + $this->lang->product->branch = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]); + dao::$errors['branch'] = sprintf($this->lang->error->notempty, $this->lang->product->branch); + } if(!$this->post->future and strpos($this->config->productplan->create->requiredFields, 'begin') !== false and empty($_POST['begin'])) { dao::$errors['begin'] = sprintf($this->lang->error->notempty, $this->lang->productplan->begin); @@ -477,8 +511,7 @@ class productplanModel extends model if(dao::isError()) return false; $plan = $this->loadModel('file')->processImgURL($plan, $this->config->productplan->editor->create['id'], $this->post->uid); - $this->dao->insert(TABLE_PRODUCTPLAN) - ->data($plan) + $this->dao->insert(TABLE_PRODUCTPLAN)->data($plan) ->autoCheck() ->batchCheck($this->config->productplan->create->requiredFields, 'notempty') ->checkIF(!$this->post->future && !empty($_POST['begin']) && !empty($_POST['end']), 'end', 'ge', $plan->begin) diff --git a/module/productplan/view/browsebylist.html.php b/module/productplan/view/browsebylist.html.php index a81c574f0e..b5a0bf9f68 100644 --- a/module/productplan/view/browsebylist.html.php +++ b/module/productplan/view/browsebylist.html.php @@ -161,7 +161,9 @@ status)?> session->currentProductType != 'normal'):?> - parent != '-1') echo $branchOption[$plan->branch];?> + + branch) as $branchID) $planBranches .= $branchOption[$branchID] . ',';?> + '>parent != '-1') echo trim($planBranches, ',');?> begin == $config->productplan->future ? $lang->productplan->future : $plan->begin;?> end == $config->productplan->future ? $lang->productplan->future : $plan->end;?> diff --git a/module/productplan/view/create.html.php b/module/productplan/view/create.html.php index 823eb1a0e4..e5180a7d3d 100644 --- a/module/productplan/view/create.html.php +++ b/module/productplan/view/create.html.php @@ -38,7 +38,7 @@ type != 'normal'):?> product->branch;?> - + @@ -50,7 +50,7 @@ productplan->parent;?> - '') + $parentPlanPairs, '', "class='form-control chosen'");?> + '') + $parentPlanPairs, 0, "class='form-control chosen'");?> diff --git a/module/productplan/view/edit.html.php b/module/productplan/view/edit.html.php index 2deed208bc..1f0df1c99d 100644 --- a/module/productplan/view/edit.html.php +++ b/module/productplan/view/edit.html.php @@ -33,7 +33,7 @@ type != 'normal' and $plan->parent != '-1'):?> product->branch;?> - branch, "onchange='getConflictStories($plan->id, this.value); 'class='form-control'");?> + branch, "onchange='getConflictStories($plan->id, this.value); 'class='form-control chosen' multiple");?>