diff --git a/module/kanban/model.php b/module/kanban/model.php index a4a02a08c0..d9177af9e5 100755 --- a/module/kanban/model.php +++ b/module/kanban/model.php @@ -818,8 +818,11 @@ class kanbanModel extends model } elseif($branchID) { - $branchName = $this->branch->getById($branchID); - $branches = array($branchID => $branchName); + foreach(explode(',', $branchID) as $id) + { + $branchName = $this->branch->getById($id); + $branches[$id] = $branchName; + } } foreach($branches as $id => $name) diff --git a/module/productplan/control.php b/module/productplan/control.php index f4419871cc..36ff2fcbe9 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -977,4 +977,46 @@ class productplan extends control if(isset($parentPlanPairs[$planID])) unset($parentPlanPairs[$planID]); return print(html::select('parent', array(0 => '') + $parentPlanPairs, 0, 'class="form-control"')); } + + /** + * AJAX: Get diff branches tips. + * + * @param int $productID + * @param int $parentID + * @param string $branches + * @access public + * @return void + */ + public function ajaxGetDiffBranchesTip($productID = 0, $parentID = 0, $branches = '') + { + if(empty($parentID) or empty($productID)) return; + + /* If it has children, return. */ + $parentBranch = $this->productplan->getByID($parentID); + if($parentBranch->parent == '-1') return; + + /* Find diff branches between parent plan and child plan. */ + $diffBranches = array(); + $diffBranchesTip = ''; + $product = $this->loadModel('product')->getByID($productID); + $branchPairs = $this->loadModel('branch')->getPairs($productID); + foreach(explode(',', $parentBranch->branch) as $parentBranchID) + { + if(empty($parentBranchID)) continue; + if(strpos(",$branches,", ",$parentBranchID,") === false) + { + $diffBranches[$parentBranchID] = $parentBranchID; + $diffBranchesTip .= "{$branchPairs[$parentBranchID]},"; + } + } + if(empty($diffBranchesTip)) return; + + /* Find stories and bugs in diff branches. */ + $unlinkStories = $this->dao->select('*')->from(TABLE_STORY)->where('branch')->in($diffBranches)->andWhere("CONCAT(',', plan, ',')")->like("%,{$parentID},%")->fetchAll('id'); + $unlinkBugs = $this->dao->select('*')->from(TABLE_BUG)->where('branch')->in($diffBranches)->andWhere('plan')->eq($parentID)->fetchAll('id'); + if(empty($unlinkStories) and empty($unlinkBugs)) return; + + $this->lang->productplan->diffBranchesTip = str_replace('@branch@', $this->lang->product->branchName[$product->type], $this->lang->productplan->diffBranchesTip); + printf($this->lang->productplan->diffBranchesTip, trim($diffBranchesTip, ',')); + } } diff --git a/module/productplan/js/create.js b/module/productplan/js/create.js index bc7db62c3b..4c4be3f040 100644 --- a/module/productplan/js/create.js +++ b/module/productplan/js/create.js @@ -65,6 +65,8 @@ $('#future').on('change', function() $('#branch').change(function() { + if(parentPlanID) return; + var branchIdList = $(this).val(); if(!branchIdList) return; @@ -86,3 +88,18 @@ $('#branch').change(function() $('#parent').chosen(); }) }); + +$('#submit').click(function() +{ + var parentPlan = $('#parent').val(); + var branches = $('#branch').val(); + if(parentPlan != 0 && branches) + { + link = createLink('productplan', 'ajaxGetDiffBranchesTip', "produtID=" + productID + "&parentID=" + parentPlan + "&branches=" + branches.toString()); + $.post(link, function(diffBranchesTip) + { + if((diffBranchesTip != '' && confirm(diffBranchesTip)) || !diffBranchesTip) $('form#dataform').submit(); + }); + return false; + } +}); diff --git a/module/productplan/js/edit.js b/module/productplan/js/edit.js index 0de68fe3d0..1bf541a2ed 100644 --- a/module/productplan/js/edit.js +++ b/module/productplan/js/edit.js @@ -86,5 +86,19 @@ $('#future').on('change', function() } }); - $('#future').change(); + +$('#submit').click(function() +{ + var parentPlan = $('#parent').val(); + var branches = $('#branch').val(); + if(parentPlan != 0 && branches) + { + link = createLink('productplan', 'ajaxGetDiffBranchesTip', "produtID=" + productID + "&parentID=" + parentPlan + "&branches=" + branches.toString()); + $.post(link, function(diffBranchesTip) + { + if((diffBranchesTip != '' && confirm(diffBranchesTip)) || !diffBranchesTip) $('form#dataform').submit(); + }); + return false; + } +}); diff --git a/module/productplan/lang/de.php b/module/productplan/lang/de.php index 0776e1a3be..31d4eaf9d7 100644 --- a/module/productplan/lang/de.php +++ b/module/productplan/lang/de.php @@ -136,6 +136,7 @@ $lang->productplan->beginGreaterChildTip = "The start date of the parent plan[%s $lang->productplan->endLetterChildTip = "The completion date of the parent plan[%s]: %s, cannot be less than the completion date of the child plan: %s."; $lang->productplan->beginLetterParentTip = "The start date of the child plan[%s]: %s, cannot be less than the start date of the parent plan: %s."; $lang->productplan->endGreaterParentTip = "The completion date of the child plan[%s]: %s, cannot be greater than the completion date of the parent plan: %s."; +$lang->productplan->diffBranchesTip = "The @branch@ %s of parent plan is not linked with the child plan. @branch@'s stories and bugs whill be removed from the plan. Do you want to save?"; $lang->productplan->featureBar['browse']['all'] = 'Alle'; $lang->productplan->featureBar['browse']['undone'] = 'Undone'; diff --git a/module/productplan/lang/en.php b/module/productplan/lang/en.php index 41b5fe348c..e2f19d5f63 100644 --- a/module/productplan/lang/en.php +++ b/module/productplan/lang/en.php @@ -136,6 +136,7 @@ $lang->productplan->beginGreaterChildTip = "The start date of the parent plan[%s $lang->productplan->endLetterChildTip = "The completion date of the parent plan[%s]: %s, cannot be less than the completion date of the child plan: %s."; $lang->productplan->beginLetterParentTip = "The start date of the child plan[%s]: %s, cannot be less than the start date of the parent plan: %s."; $lang->productplan->endGreaterParentTip = "The completion date of the child plan[%s]: %s, cannot be greater than the completion date of the parent plan: %s."; +$lang->productplan->diffBranchesTip = "The @branch@ %s of parent plan is not linked with the child plan. @branch@'s stories and bugs whill be removed from the plan. Do you want to save?"; $lang->productplan->featureBar['browse']['all'] = 'All'; $lang->productplan->featureBar['browse']['undone'] = 'Undone'; diff --git a/module/productplan/lang/fr.php b/module/productplan/lang/fr.php index dc5390ac80..337fb049ef 100644 --- a/module/productplan/lang/fr.php +++ b/module/productplan/lang/fr.php @@ -136,6 +136,7 @@ $lang->productplan->beginGreaterChildTip = "The start date of the parent plan[%s $lang->productplan->endLetterChildTip = "The completion date of the parent plan[%s]: %s, cannot be less than the completion date of the child plan: %s."; $lang->productplan->beginLetterParentTip = "The start date of the child plan[%s]: %s, cannot be less than the start date of the parent plan: %s."; $lang->productplan->endGreaterParentTip = "The completion date of the child plan[%s]: %s, cannot be greater than the completion date of the parent plan: %s."; +$lang->productplan->diffBranchesTip = "The @branch@ %s of parent plan is not linked with the child plan. @branch@'s stories and bugs whill be removed from the plan. Do you want to save?"; $lang->productplan->featureBar['browse']['all'] = 'Tous'; $lang->productplan->featureBar['browse']['undone'] = 'Undone'; diff --git a/module/productplan/lang/zh-cn.php b/module/productplan/lang/zh-cn.php index 119714e9de..cec7d028c0 100644 --- a/module/productplan/lang/zh-cn.php +++ b/module/productplan/lang/zh-cn.php @@ -136,6 +136,7 @@ $lang->productplan->beginGreaterChildTip = "父计划[%s]的开始日期:%s, $lang->productplan->endLetterChildTip = "父计划[%s]的完成日期:%s,不能小于子计划的完成日期: %s"; $lang->productplan->beginLetterParentTip = "子计划[%s]的开始日期:%s,不能小于父计划的开始日期: %s"; $lang->productplan->endGreaterParentTip = "子计划[%s]的完成日期:%s,不能大于父计划的完成日期: %s"; +$lang->productplan->diffBranchesTip = "父计划的@branch@ %s 未被子计划关联,对应@branch@的需求和bug将自动从计划中移除,是否保存?"; $lang->productplan->featureBar['browse']['all'] = '全部'; $lang->productplan->featureBar['browse']['undone'] = '未完成'; diff --git a/module/productplan/model.php b/module/productplan/model.php index bf7c2870a9..27e53a301b 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -554,24 +554,10 @@ class productplanModel extends model $planID = $this->dao->lastInsertID(); $this->file->updateObjectID($this->post->uid, $planID, 'plan'); $this->loadModel('score')->create('productplan', 'create', $planID); - if(!empty($plan->parent)) + if(!empty($plan->parent) and $parentPlan->parent == '0') { - if($parentPlan->parent == '0') - { - $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 = str_replace(",{$plan->parent},", ",$planID,", ",$story->plan,"); - $storyPlan = trim($storyPlan, ','); - - $this->dao->update(TABLE_STORY)->set('plan')->eq($storyPlan)->where('id')->eq($storyID)->exec(); - } - } + $plan->id = $planID; + $this->transferStoriesAndBugs($plan); } return $planID; } @@ -597,7 +583,7 @@ class productplanModel extends model ->get(); $product = $this->loadModel('product')->getByID($oldPlan->product); - if($product->type != 'normal' and !isset($_POST['branch'])) + if($product->type != 'normal' and $oldPlan->parent != -1 and !isset($_POST['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); @@ -649,25 +635,7 @@ class productplanModel extends model if(!dao::isError()) { $this->file->updateObjectID($this->post->uid, $planID, 'plan'); - if(!empty($plan->parent)) - { - if($parentPlan->parent == '0') - { - $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 = str_replace(",{$plan->parent},", ",$planID,", ",$story->plan,"); - $storyPlan = trim($storyPlan, ','); - - $this->dao->update(TABLE_STORY)->set('plan')->eq($storyPlan)->where('id')->eq($storyID)->exec(); - } - } - } + if(!empty($plan->parent) and $parentPlan->parent == '0') $this->transferStoriesAndBugs($plan); return common::createChanges($oldPlan, $plan); } } @@ -1304,4 +1272,47 @@ class productplanModel extends model if($product->type == 'normal') unset($this->config->productplan->search['fields']['branch']); $this->loadModel('search')->setSearchParams($this->config->productplan->search); } + + /** + * Transfer stories and bugs to new plan. + * + * @param object $plan + * @access public + * @return void + */ + public function transferStoriesAndBugs($plan) + { + $this->dao->update(TABLE_PRODUCTPLAN)->set('parent')->eq('-1')->where('id')->eq($plan->parent)->andWhere('parent')->eq('0')->exec(); + + /* Transfer stories linked with the parent plan to the child plan. */ + $stories = $this->dao->select('*')->from(TABLE_STORY)->where("CONCAT(',', plan, ',')")->like("%,{$plan->parent},%")->fetchAll('id'); + $unlinkStories = array(); + foreach($stories as $storyID => $story) + { + if(!empty($story->branch) and strpos(",$plan->branch,", ",$story->branch,") === false) + { + $unlinkStories[$storyID] = $storyID; + $storyPlan = str_replace(",{$plan->parent},", ',', ",$story->plan,"); + } + else + { + $storyPlan = str_replace(",{$plan->parent},", ",$plan->id,", ",$story->plan,"); + } + $storyPlan = trim($storyPlan, ','); + + $this->dao->update(TABLE_STORY)->set('plan')->eq($storyPlan)->where('id')->eq($storyID)->exec(); + } + if(!empty($unlinkStories)) $this->dao->delete()->from(TABLE_PLANSTORY)->where('plan')->eq($plan->parent)->andWhere('story')->in($unlinkStories)->exec(); + $this->dao->update(TABLE_PLANSTORY)->set('plan')->eq($plan->id)->where('plan')->eq($plan->parent)->exec(); + + /* Transfer bugs linked with the parent plan to the child plan. */ + $bugs = $this->dao->select('*')->from(TABLE_BUG)->where('plan')->eq($plan->parent)->fetchAll('id'); + $unlinkBugs = array(); + foreach($bugs as $bugID => $bug) + { + if(!empty($bug->branch) and strpos(",$plan->branch,", ",$bug->branch,") === false) $unlinkBugs[$bugID] = $bugID; + } + if(!empty($unlinkBugs)) $this->dao->update(TABLE_BUG)->set('plan')->eq(0)->where('plan')->eq($plan->parent)->andWhere('id')->in($unlinkBugs)->exec(); + $this->dao->update(TABLE_BUG)->set('plan')->eq($plan->id)->where('plan')->eq($plan->parent)->exec(); + } } diff --git a/module/productplan/view/batchedit.html.php b/module/productplan/view/batchedit.html.php index 6aab7a43e0..61021133eb 100644 --- a/module/productplan/view/batchedit.html.php +++ b/module/productplan/view/batchedit.html.php @@ -44,7 +44,7 @@ type != 'normal'):?>