From e0d72a4c2573a77b372a71bebd210ca25a836161 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 31 Dec 2021 09:40:46 +0800 Subject: [PATCH 1/4] * Refactoring code for update status. --- module/action/lang/en.php | 4 + module/action/lang/zh-cn.php | 4 + module/productplan/control.php | 36 ++++- module/productplan/css/browse.css | 3 +- module/productplan/model.php | 152 +++++++----------- module/productplan/view/browsebylist.html.php | 2 +- 6 files changed, 101 insertions(+), 100 deletions(-) diff --git a/module/action/lang/en.php b/module/action/lang/en.php index b5635e3da8..28d8adc3e8 100755 --- a/module/action/lang/en.php +++ b/module/action/lang/en.php @@ -321,6 +321,10 @@ $lang->action->label->importfromgitlab = 'Issue associate created'; $lang->action->label->archived = 'Archived'; $lang->action->label->restore = 'Restore'; $lang->action->label->mergedbranch = 'Merge Branch'; +$lang->action->label->startedbychild = 'started'; +$lang->action->label->finishedbychild = 'finished'; +$lang->action->label->closedbychild = 'closed'; +$lang->action->label->activatedbychild = 'activated'; /* Dynamic information is grouped by object. */ $lang->action->dynamicAction = new stdclass; diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index ee4a3f4e0a..edd3f69f31 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -321,6 +321,10 @@ $lang->action->label->importfromgitlab = '从Gitlab关联创建了'; $lang->action->label->archived = '归档了'; $lang->action->label->restore = '还原了'; $lang->action->label->mergedbranch = '合并分支'; +$lang->action->label->startedbychild = '开始了'; +$lang->action->label->finishedbychild = '完成了'; +$lang->action->label->closedbychild = '关闭了'; +$lang->action->label->activatedbychild = '激活了'; /* 动态信息按照对象分组 */ $lang->action->dynamicAction = new stdclass(); diff --git a/module/productplan/control.php b/module/productplan/control.php index d972011030..9bfee95a7a 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -408,6 +408,12 @@ class productplan extends control $changes = $this->productplan->updateStatus($planID, 'doing'); if(dao::isError()) die(js::error(dao::getError())); + $actionID = $this->loadModel('action')->create('productplan', $planID, 'started'); + $this->action->logHistory($actionID, $changes); + + if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); + if(dao::isError()) die(js::error(dao::getError())); + die(js::reload('parent')); } } @@ -415,7 +421,14 @@ class productplan extends control { if(!empty($_POST)) { - $changes = $this->productplan->updateStatus($planID, 'doing'); + $_POST['status'] = 'doing'; + $changes = $this->productplan->updateStatus($planID, 'doing'); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + + $actionID = $this->loadModel('action')->create('productplan', $planID, 'started'); + $this->action->logHistory($actionID, $changes); + + if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess,'locate' => 'parent')); @@ -445,6 +458,13 @@ class productplan extends control $changes = $this->productplan->updateStatus($planID, 'done'); if(dao::isError()) die(js::error(dao::getError())); + $actionID = $this->loadModel('action')->create('productplan', $planID, 'finished'); + $this->action->logHistory($actionID, $changes); + + $plan = $this->productplan->getByID($planID); + if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); + if(dao::isError()) die(js::error(dao::getError())); + die(js::reload('parent')); } } @@ -468,6 +488,13 @@ class productplan extends control $changes = $this->productplan->updateStatus($planID, 'closed'); if(dao::isError()) die(js::error(dao::getError())); + $actionID = $this->loadModel('action')->create('productplan', $planID, 'closed'); + $this->action->logHistory($actionID, $changes); + + $plan = $this->productplan->getByID($planID); + if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); + if(dao::isError()) die(js::error(dao::getError())); + die(js::reload('parent')); } } @@ -491,6 +518,13 @@ class productplan extends control $changes = $this->productplan->updateStatus($planID, 'doing'); if(dao::isError()) die(js::error(dao::getError())); + $actionID = $this->loadModel('action')->create('productplan', $planID, 'activated'); + $this->action->logHistory($actionID, $changes); + + $plan = $this->productplan->getByID($planID); + if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); + if(dao::isError()) die(js::error(dao::getError())); + die(js::reload('parent')); } } diff --git a/module/productplan/css/browse.css b/module/productplan/css/browse.css index b5607f9b1b..6faa03c442 100644 --- a/module/productplan/css/browse.css +++ b/module/productplan/css/browse.css @@ -24,7 +24,8 @@ td.c-branch {overflow: hidden; text-align: left !important; text-overflow: ellip .plan-name {position: relative; display: flex; align-items: center;} .plan-name > span {flex: none;} -#productplanList .c-title.has-child > .plan-name.expired > a {overflow:hidden; max-width: calc(100% - 62px);} +[lang^='zh-'] #productplanList .c-title.has-child > .plan-name.expired > a {overflow:hidden; max-width: calc(100% - 62px);} +[lang^='en'] #productplanList .c-title.has-child > .plan-name.expired > a {overflow:hidden; max-width: calc(100% - 67px);} #productplanList .c-title.has-child > .plan-name > a {overflow:hidden; max-width: calc(100% - 16px);} #productplanList .c-title > .plan-name.expired > a {overflow:hidden; max-width: calc(100% - 46px);} #productplanList .plan-name.expired > .label.label-danger {margin-left:3px; } diff --git a/module/productplan/model.php b/module/productplan/model.php index 7d34e98a37..686a05e7e7 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -505,19 +505,14 @@ class productplanModel extends model * Update a plan's status. * * @param int $planID - * @param string $status + * @param string $status doing|done|closed * @access public - * @return string + * @return array */ public function updateStatus($planID, $status = '') { $planID = (int)$planID; $oldPlan = $this->getByID($planID); - if($oldPlan->parent > 0) - { - $parentPlan = $this->getByID($oldPlan->parent); - $parentChange = false; - } if($status == 'doing' and !empty($_POST)) { @@ -529,114 +524,77 @@ class productplanModel extends model $this->checkDate4Plan($oldPlan, $plan->begin, $plan->end); if(dao::isError()) return false; + $plan = $this->loadModel('file')->processImgURL($plan, $this->config->productplan->editor->start['id'], $this->post->uid); $this->dao->update(TABLE_PRODUCTPLAN) ->data($plan) ->autoCheck() ->batchCheck($this->config->productplan->start->requiredFields, 'notempty') - ->checkIF(!empty($_POST['begin']) && !empty($_POST['end']), 'end', 'ge', $plan->begin) + ->checkIF(!empty($plan->begin) and !empty($plan->end), 'end', 'ge', $plan->begin) ->where('id')->eq($planID) ->exec(); - - $this->file->updateObjectID($this->post->uid, $planID, 'productplan'); - - if(isset($parentPlan) and $parentPlan->status != 'doing') - { - $this->dao->update(TABLE_PRODUCTPLAN)->set('status')->eq($status)->where('id')->eq($oldPlan->parent)->exec(); - $parentChange = true; - } - } - elseif($status == 'doing' and isset($parentPlan) and $parentPlan->status != 'doing') - { - $this->dao->update(TABLE_PRODUCTPLAN) - ->set('`status`')->eq($status) - ->where('id')->eq($planID) - ->orWhere('id')->eq($oldPlan->parent) - ->exec(); - if($parentPlan->status != 'doing') $parentChange = true; - } - elseif($status == 'done' and isset($parentPlan)) - { - $parentDone = true; - $childPlans = $this->dao->select('*')->from(TABLE_PRODUCTPLAN)->where('parent')->eq($oldPlan->parent)->andWhere('deleted')->eq(0)->fetchAll(); - foreach($childPlans as $childPlan ) - { - if(in_array($childPlan->status, array('wait', 'doing')) and $planID != $childPlan->id) - { - $parentDone = false; - break; - } - } - if($parentDone) $parentChange = true; - $this->dao->update(TABLE_PRODUCTPLAN) - ->set('`status`')->eq($status) - ->where('id')->eq($planID) - ->beginIF($parentDone)->orWhere('id')->eq($oldPlan->parent)->fi() - ->exec(); - } - elseif($status == 'closed' and isset($parentPlan)) - { - $parentClosed = true; - $childPlans = $this->dao->select('*')->from(TABLE_PRODUCTPLAN)->where('parent')->eq($oldPlan->parent)->andWhere('deleted')->eq(0)->fetchAll(); - foreach($childPlans as $childPlan) - { - if(in_array($childPlan->status, array('wait', 'doing', 'done')) and $planID != $childPlan->id) - { - $parentClosed = false; - break; - } - } - if($parentClosed) $parentChange = true; - $this->dao->update(TABLE_PRODUCTPLAN) - ->set('`status`')->eq($status) - ->where('id')->eq($planID) - ->beginIF($parentClosed)->orWhere('id')->eq($oldPlan->parent)->fi() - ->exec(); } else { - $this->dao->update(TABLE_PRODUCTPLAN) - ->set('`status`')->eq($status) - ->where('id')->eq($planID) - ->exec(); + $plan = new stdClass(); + $plan->status = $status; + $this->dao->update(TABLE_PRODUCTPLAN)->data($plan)->where('id')->eq($planID)->exec(); } if(dao::isError()) return false; - if(!isset($plan)) $plan = $this->getByID($planID); - if(!dao::isError()) + if(isset($this->post->uid)) $this->file->updateObjectID($this->post->uid, $planID, 'productplan'); + return common::createChanges($oldPlan, $plan); + } + + /** + * Update a parent plan's status. + * + * @param int $parentID + * @access public + * @return void + */ + public function updateParentStatus($parentID) + { + $method = $this->app->rawMethod; + $needChange = true; + $parentPlan = $this->getByID($parentID); + $childStatus = $this->dao->select('status')->from(TABLE_PRODUCTPLAN)->where('parent')->eq($parentID)->andWhere('deleted')->eq(0)->fetchPairs('status', 'status'); + + if(isset($childStatus['doing'])) { - $method = $this->app->rawMethod; - if($method == 'start') - { - $action = 'started'; - if(isset($parentChange) and $parentChange) $parentAction = 'startedbychild'; - } - elseif($method == 'finish') - { - $action = 'finished'; - if(isset($parentChange) and $parentChange) $parentAction = 'finishedbychild'; - } - elseif($method == 'close') - { - $action = 'closed'; - if(isset($parentChange) and $parentChange) $parentAction = 'closedbychild'; - } - elseif($method == 'activate') - { - $action = 'activated'; - if(isset($parentChange) and $parentChange) $parentAction = 'activatedbychild'; - } + $parentStatus = 'doing'; + if($parentPlan->status != $parentStatus and $method == 'start') $parentAction = 'startedbychild'; + if($parentPlan->status != $parentStatus and $method == 'activate') $parentAction = 'activatedbychild'; - if(isset($action)) - { - $changes = common::createChanges($oldPlan, $plan); - $actionID = $this->loadModel('action')->create('productplan', $planID, $action); - $this->action->loghistory($actionID, $changes); + } + elseif(isset($childStatus['wait']) and count($childStatus) == 1) + { + $parentStatus = 'wait'; + } + elseif(isset($childStatus['wait'])) + { + $parentStatus = 'doing'; + if($parentPlan->status != $parentStatus and $method == 'start') $parentAction = 'startedbychild'; + } + elseif(isset($childStatus['closed']) and count($childStatus) == 1) + { + $parentStatus = 'closed'; + if($parentPlan->status != $parentStatus) $parentAction = 'closedbychild'; + } + else + { + $parentStatus = 'done'; + if($parentPlan->status != $parentStatus) $parentAction = 'finishedbychild'; + } - if(isset($parentChange) and $parentChange) $actionID = $this->action->create('productplan', $oldPlan->parent, $parentAction, '', $parentAction); - } + if($parentPlan->status != $parentStatus) + { + $this->dao->update(TABLE_PRODUCTPLAN)->set('status')->eq($parentStatus)->where('id')->eq($parentID)->exec(); + if(dao::isError()) return false; + + if(isset($parentAction)) $this->loadModel('action')->create('productplan', $parentID, $parentAction, '', $parentAction); } } diff --git a/module/productplan/view/browsebylist.html.php b/module/productplan/view/browsebylist.html.php index e8211be927..5c33f531ec 100644 --- a/module/productplan/view/browsebylist.html.php +++ b/module/productplan/view/browsebylist.html.php @@ -159,7 +159,7 @@ $attr = "data-id='{$plan->id}' data-width='550px'"; $isOnlyBody = true; } - common::printIcon('productplan', 'start', "planID=$plan->id", $plan, 'list', 'play', '', $class, $isOnlyBody); + common::printIcon('productplan', 'start', "planID=$plan->id", $plan, 'list', 'play', '', $class, $isOnlyBody, $attr); common::printIcon('productplan', 'finish', "planID=$plan->id", $plan, 'list', 'checked', '', $class, false, $attr); common::printIcon('productplan', 'close', "planID=$plan->id", $plan, 'list', 'off', '', $class, false, $attr); } From 0894fd48980f79ade80404dded180268df5b7237 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 31 Dec 2021 09:47:22 +0800 Subject: [PATCH 2/4] * Modify judgment for split child plan. --- module/productplan/view/browsebylist.html.php | 2 +- module/productplan/view/view.html.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/module/productplan/view/browsebylist.html.php b/module/productplan/view/browsebylist.html.php index 5c33f531ec..f86a8d11d1 100644 --- a/module/productplan/view/browsebylist.html.php +++ b/module/productplan/view/browsebylist.html.php @@ -191,7 +191,7 @@ common::printIcon('productplan', 'edit', "planID=$plan->id", $plan, 'list'); if(common::hasPriv('productplan', 'create', $plan)) { - if($plan->parent > 0 or in_array($plan->status, array('done', 'closed'))) + if($plan->parent > 0) { echo " "; } diff --git a/module/productplan/view/view.html.php b/module/productplan/view/view.html.php index e966ae107a..74e0cd9add 100644 --- a/module/productplan/view/view.html.php +++ b/module/productplan/view/view.html.php @@ -63,8 +63,7 @@ common::printLink('productplan', 'activate', "planID=$plan->id", "{$lang->productplan->activateAB}", '', "class='btn btn-link {$class}' target='hiddenwin' title='{$lang->productplan->activate}'", '', false, $plan); } - $class = in_array($plan->status, array('done', 'closed')) ? 'disabled' : ''; - if(common::hasPriv('productplan', 'create', $plan) and $plan->parent <= 0) echo html::a($this->createLink('productplan', 'create', "product={$plan->product}&branch={$plan->branch}&parent={$plan->id}"), " " . $this->lang->productplan->children , '', "class='btn btn-link {$class}' title='{$this->lang->productplan->children}'"); + if(common::hasPriv('productplan', 'create', $plan) and $plan->parent <= 0) echo html::a($this->createLink('productplan', 'create', "product={$plan->product}&branch={$plan->branch}&parent={$plan->id}"), " " . $this->lang->productplan->children , '', "class='btn btn-link' title='{$this->lang->productplan->children}'"); if(common::hasPriv('productplan', 'edit', $plan)) echo html::a($this->createLink('productplan', 'edit', "planID=$plan->id"), " " . $this->lang->edit, '', "class='btn btn-link' title='{$this->lang->edit}'"); if(common::hasPriv('productplan', 'delete', $plan) and $plan->parent >= 0) echo html::a($this->createLink('productplan', 'delete', "planID=$plan->id"), " " . $this->lang->delete, '', "class='btn btn-link' title='{$this->lang->delete}' target='hiddenwin'"); } From 3dd747f40a8d45bfae712877d762cdfde7dceb69 Mon Sep 17 00:00:00 2001 From: liumengyi Date: Fri, 31 Dec 2021 10:59:37 +0800 Subject: [PATCH 3/4] * Modify judgment for split chid plan. --- module/action/lang/en.php | 1 + module/action/lang/zh-cn.php | 1 + module/action/model.php | 2 +- module/productplan/control.php | 5 +++++ module/productplan/lang/en.php | 4 ++-- module/productplan/lang/zh-cn.php | 1 + module/productplan/view/browsebylist.html.php | 8 ++++---- module/productplan/view/view.html.php | 3 ++- 8 files changed, 17 insertions(+), 8 deletions(-) diff --git a/module/action/lang/en.php b/module/action/lang/en.php index 28d8adc3e8..582cec1915 100755 --- a/module/action/lang/en.php +++ b/module/action/lang/en.php @@ -325,6 +325,7 @@ $lang->action->label->startedbychild = 'started'; $lang->action->label->finishedbychild = 'finished'; $lang->action->label->closedbychild = 'closed'; $lang->action->label->activatedbychild = 'activated'; +$lang->action->label->createchild = 'activated'; /* Dynamic information is grouped by object. */ $lang->action->dynamicAction = new stdclass; diff --git a/module/action/lang/zh-cn.php b/module/action/lang/zh-cn.php index edd3f69f31..f59b472f70 100755 --- a/module/action/lang/zh-cn.php +++ b/module/action/lang/zh-cn.php @@ -325,6 +325,7 @@ $lang->action->label->startedbychild = '开始了'; $lang->action->label->finishedbychild = '完成了'; $lang->action->label->closedbychild = '关闭了'; $lang->action->label->activatedbychild = '激活了'; +$lang->action->label->createchild = '激活了'; /* 动态信息按照对象分组 */ $lang->action->dynamicAction = new stdclass(); diff --git a/module/action/model.php b/module/action/model.php index ca1ef97a30..f7ee21a64f 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -707,7 +707,7 @@ class actionModel extends model { $desc = $this->lang->$objectType->action->rejectreviewed; } - elseif($action->objectType == 'productplan' and in_array($action->action, array('startedbychild','finishedbychild','closedbychild','activatedbychild'))) + elseif($action->objectType == 'productplan' and in_array($action->action, array('startedbychild','finishedbychild','closedbychild','activatedbychild', 'createchild'))) { $desc = $this->lang->$objectType->action->changebychild; } diff --git a/module/productplan/control.php b/module/productplan/control.php index 9bfee95a7a..427733e5cd 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -66,6 +66,9 @@ class productplan extends control $this->executeHooks($planID); + if($parent > 0) $this->productplan->updateParentStatus($parent); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'id' => $planID)); if(isonlybody()) return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'closeModal' => true, 'callback' => 'parent.refreshPlan()')); return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => $this->createLink('productplan', 'browse', "productID=$productID&branch=$branchID&browseType=wait"))); @@ -357,6 +360,8 @@ class productplan extends control if($plan->parent > 0) $this->view->parentPlan = $this->productplan->getById($plan->parent); if($plan->parent == '-1') $this->view->childrenPlans = $this->productplan->getChildren($plan->id); + if($plan->branch > 0) $this->view->branchStatus = $this->loadModel('branch')->getById($plan->branch, $plan->product, 'status'); + $this->loadModel('datatable'); $this->view->modulePairs = $this->loadModel('tree')->getOptionMenu($plan->product, 'story', 0, 'all'); $this->view->title = "PLAN #$plan->id $plan->title/" . zget($products, $plan->product, ''); diff --git a/module/productplan/lang/en.php b/module/productplan/lang/en.php index a8abcabed2..5fd0639707 100644 --- a/module/productplan/lang/en.php +++ b/module/productplan/lang/en.php @@ -18,12 +18,11 @@ $lang->productplan->delete = "Delete Plan"; $lang->productplan->start = "Start Plan"; $lang->productplan->finish = "Finish Plan"; $lang->productplan->close = "Close Plan"; +$lang->productplan->activate = "Activate Plan"; $lang->productplan->startAB = "Start"; $lang->productplan->finishAB = "Finish"; $lang->productplan->closeAB = "Close"; $lang->productplan->activateAB = "Activate"; -$lang->productplan->view = "Plan Detail"; -$lang->productplan->activate = "Activate Plan"; $lang->productplan->view = "View"; $lang->productplan->bugSummary = "Total %s Bugs on this page."; $lang->productplan->basicInfo = 'Basic Info'; @@ -102,6 +101,7 @@ $lang->productplan->parentActionList['startedbychild'] = 'starting productplan->parentActionList['finishedbychild'] = 'finishing all productplan sets the plan status as Done.'; $lang->productplan->parentActionList['closedbychild'] = 'closing all productplan sets the plan status as Closed.'; $lang->productplan->parentActionList['activatedbychild'] = 'activating the productplan sets the plan status as Doing.'; +$lang->productplan->parentActionList['createchild'] = 'creating a child productplan sets the plan status as Doing.'; $lang->productplan->endList[7] = '1 Week'; $lang->productplan->endList[14] = '2 Weeks'; diff --git a/module/productplan/lang/zh-cn.php b/module/productplan/lang/zh-cn.php index ac6197f574..9cb4d9e489 100644 --- a/module/productplan/lang/zh-cn.php +++ b/module/productplan/lang/zh-cn.php @@ -101,6 +101,7 @@ $lang->productplan->parentActionList['startedbychild'] = '系统判断由于 $lang->productplan->parentActionList['finishedbychild'] = '系统判断由于子计划 全部完成 ,将计划状态置为 已完成 。'; $lang->productplan->parentActionList['closedbychild'] = '系统判断由于子计划 全部关闭 ,将计划状态置为 已关闭 。'; $lang->productplan->parentActionList['activatedbychild'] = '系统判断由于子计划 激活 ,将计划状态置为 进行中 。'; +$lang->productplan->parentActionList['createchild'] = '系统判断由于 创建 子计划 ,将计划状态置为 进行中 。'; $lang->productplan->endList[7] = '一星期'; $lang->productplan->endList[14] = '两星期'; diff --git a/module/productplan/view/browsebylist.html.php b/module/productplan/view/browsebylist.html.php index f86a8d11d1..236571474e 100644 --- a/module/productplan/view/browsebylist.html.php +++ b/module/productplan/view/browsebylist.html.php @@ -78,7 +78,6 @@ loadModel('file');?> - end < $today and in_array($plan->status, array('wait', 'doing'))) + if($plan->expired and in_array($plan->status, array('wait', 'doing'))) { $class .= ' expired'; $expired = "{$this->lang->productplan->expired}"; @@ -164,7 +163,8 @@ common::printIcon('productplan', 'close', "planID=$plan->id", $plan, 'list', 'off', '', $class, false, $attr); } - $attr = $plan->expired ? "disabled='disabled'" : ''; + $attr = $plan->expired ? "disabled='disabled'" : ''; + $disabled = ''; if(common::hasPriv('execution', 'create', $plan) and $plan->parent >= 0) { $disabled = ''; @@ -197,7 +197,7 @@ } else { - echo html::a($this->createLink('productplan', 'create', "product=$productID&branch=$branch&parent={$plan->id}"), "", '', "class='btn' title='{$this->lang->productplan->children}'"); + echo html::a($this->createLink('productplan', 'create', "product=$productID&branch=$branch&parent={$plan->id}"), "", '', "class='btn {$disabled}' title='{$this->lang->productplan->children}'"); } } diff --git a/module/productplan/view/view.html.php b/module/productplan/view/view.html.php index 74e0cd9add..23c5979e8c 100644 --- a/module/productplan/view/view.html.php +++ b/module/productplan/view/view.html.php @@ -63,7 +63,8 @@ common::printLink('productplan', 'activate', "planID=$plan->id", "{$lang->productplan->activateAB}", '', "class='btn btn-link {$class}' target='hiddenwin' title='{$lang->productplan->activate}'", '', false, $plan); } - if(common::hasPriv('productplan', 'create', $plan) and $plan->parent <= 0) echo html::a($this->createLink('productplan', 'create', "product={$plan->product}&branch={$plan->branch}&parent={$plan->id}"), " " . $this->lang->productplan->children , '', "class='btn btn-link' title='{$this->lang->productplan->children}'"); + $class= (isset($branchStatus) and $branchStatus == 'closed') ? 'disabled' : ''; + if(common::hasPriv('productplan', 'create', $plan) and $plan->parent <= 0) echo html::a($this->createLink('productplan', 'create', "product={$plan->product}&branch={$plan->branch}&parent={$plan->id}"), " " . $this->lang->productplan->children , '', "class='btn btn-link {$class}' title='{$this->lang->productplan->children}'"); if(common::hasPriv('productplan', 'edit', $plan)) echo html::a($this->createLink('productplan', 'edit', "planID=$plan->id"), " " . $this->lang->edit, '', "class='btn btn-link' title='{$this->lang->edit}'"); if(common::hasPriv('productplan', 'delete', $plan) and $plan->parent >= 0) echo html::a($this->createLink('productplan', 'delete', "planID=$plan->id"), " " . $this->lang->delete, '', "class='btn btn-link' title='{$this->lang->delete}' target='hiddenwin'"); } From ad25920cf05edc0286822bba132fd5a8058e1c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E5=B9=BF=E6=98=8E?= Date: Fri, 31 Dec 2021 11:06:31 +0800 Subject: [PATCH 4/4] * Refactor code. --- module/action/model.php | 2 +- module/productplan/control.php | 70 +++++----------- module/productplan/model.php | 145 ++++++++++++++++++--------------- 3 files changed, 101 insertions(+), 116 deletions(-) diff --git a/module/action/model.php b/module/action/model.php index f7ee21a64f..8e38ef3475 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -467,7 +467,7 @@ class actionModel extends model $name = $this->dao->select('name')->from(TABLE_TESTSUITE)->where('id')->eq($action->extra)->fetch('name'); if($name) $action->extra = common::hasPriv('caselib', 'browse') ? html::a(helper::createLink('caselib', 'browse', "libID=$action->extra"), $name) : $name; } - elseif(strpos('importfromstorylib,importfromrisklib,importfromissuelib,importfromopportunitylib', $actionName)!== false) + elseif(strpos('importfromstorylib,importfromrisklib,importfromissuelib,importfromopportunitylib', $actionName) !== false) { $name = $this->dao->select('name')->from(TABLE_ASSETLIB)->where('id')->eq($action->extra)->fetch('name'); if($name) $action->extra = common::hasPriv('assetlib', $action->objectType) ? html::a(helper::createLink('assetlib', $action->objectType, "libID=$action->extra"), $name) : $name; diff --git a/module/productplan/control.php b/module/productplan/control.php index 427733e5cd..9194f92b85 100644 --- a/module/productplan/control.php +++ b/module/productplan/control.php @@ -402,6 +402,18 @@ class productplan extends control public function start($planID, $confirm = 'no') { $plan = $this->productplan->getByID($planID); + + if($_POST) + { + $changes = $this->productplan->start($planID); + if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); + + $actionID = $this->loadModel('action')->create('productplan', $planID, 'started'); + $this->action->logHistory($actionID, $changes); + + return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess, 'locate' => 'parent')); + } + if(!isonlybody()) { if($confirm == 'no') @@ -410,35 +422,14 @@ class productplan extends control } else { - $changes = $this->productplan->updateStatus($planID, 'doing'); + $this->productplan->updateStatus($planID, 'doing', 'started'); + if(dao::isError()) die(js::error(dao::getError())); - - $actionID = $this->loadModel('action')->create('productplan', $planID, 'started'); - $this->action->logHistory($actionID, $changes); - - if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); - if(dao::isError()) die(js::error(dao::getError())); - die(js::reload('parent')); } } else { - if(!empty($_POST)) - { - $_POST['status'] = 'doing'; - $changes = $this->productplan->updateStatus($planID, 'doing'); - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - - $actionID = $this->loadModel('action')->create('productplan', $planID, 'started'); - $this->action->logHistory($actionID, $changes); - - if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); - if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - - return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess,'locate' => 'parent')); - } - $this->view->plan = $plan; $this->display(); } @@ -460,16 +451,9 @@ class productplan extends control } else { - $changes = $this->productplan->updateStatus($planID, 'done'); + $this->productplan->updateStatus($planID, 'done', 'finished'); + if(dao::isError()) die(js::error(dao::getError())); - - $actionID = $this->loadModel('action')->create('productplan', $planID, 'finished'); - $this->action->logHistory($actionID, $changes); - - $plan = $this->productplan->getByID($planID); - if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); - if(dao::isError()) die(js::error(dao::getError())); - die(js::reload('parent')); } } @@ -490,16 +474,9 @@ class productplan extends control } else { - $changes = $this->productplan->updateStatus($planID, 'closed'); + $this->productplan->updateStatus($planID, 'closed', 'closed'); + if(dao::isError()) die(js::error(dao::getError())); - - $actionID = $this->loadModel('action')->create('productplan', $planID, 'closed'); - $this->action->logHistory($actionID, $changes); - - $plan = $this->productplan->getByID($planID); - if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); - if(dao::isError()) die(js::error(dao::getError())); - die(js::reload('parent')); } } @@ -520,16 +497,9 @@ class productplan extends control } else { - $changes = $this->productplan->updateStatus($planID, 'doing'); + $this->productplan->updateStatus($planID, 'doing', 'activated'); + if(dao::isError()) die(js::error(dao::getError())); - - $actionID = $this->loadModel('action')->create('productplan', $planID, 'activated'); - $this->action->logHistory($actionID, $changes); - - $plan = $this->productplan->getByID($planID); - if($plan->parent > 0) $this->productplan->updateParentStatus($plan->parent); - if(dao::isError()) die(js::error(dao::getError())); - die(js::reload('parent')); } } diff --git a/module/productplan/model.php b/module/productplan/model.php index 686a05e7e7..029480952a 100644 --- a/module/productplan/model.php +++ b/module/productplan/model.php @@ -494,6 +494,7 @@ class productplanModel extends model ->checkIF(!$this->post->future && !empty($_POST['begin']) && !empty($_POST['end']), 'end', 'ge', $plan->begin) ->where('id')->eq((int)$planID) ->exec(); + if(!dao::isError()) { $this->file->updateObjectID($this->post->uid, $planID, 'plan'); @@ -501,101 +502,115 @@ class productplanModel extends model } } + /** + * Start a plan. + * + * @param int $planID + * @access public + * @return array + */ + public function start($planID) + { + $oldPlan = $this->getByID($planID); + $plan = fixer::input('post') + ->add('status', 'doing') + ->stripTags($this->config->productplan->editor->start['id'], $this->config->allowedTags) + ->remove('uid') + ->get(); + + $this->checkDate4Plan($oldPlan, $plan->begin, $plan->end); + if(dao::isError()) return false; + + $plan = $this->loadModel('file')->processImgURL($plan, $this->config->productplan->editor->start['id'], $this->post->uid); + + $this->dao->update(TABLE_PRODUCTPLAN) + ->data($plan) + ->autoCheck() + ->batchCheck($this->config->productplan->start->requiredFields, 'notempty') + ->checkIF(!empty($plan->begin) and !empty($plan->end), 'end', 'ge', $plan->begin) + ->where('id')->eq($planID) + ->exec(); + + if(dao::isError()) return false; + + if($oldPlan->parent > 0) $this->updateParentStatus($oldPlan->parent, 'started'); + $this->file->updateObjectID($this->post->uid, $planID, 'productplan'); + + return common::createChanges($oldPlan, $plan); + } + /** * Update a plan's status. * * @param int $planID * @param string $status doing|done|closed + * @param string $action started|finished|closed|activated * @access public * @return array */ - public function updateStatus($planID, $status = '') + public function updateStatus($planID, $status = '', $action = '') { - $planID = (int)$planID; $oldPlan = $this->getByID($planID); - if($status == 'doing' and !empty($_POST)) - { - $plan = fixer::input('post') - ->add('status', $status) - ->stripTags($this->config->productplan->editor->start['id'], $this->config->allowedTags) - ->remove('uid') - ->get(); + $plan = new stdclass(); + $plan->status = $status; - $this->checkDate4Plan($oldPlan, $plan->begin, $plan->end); - if(dao::isError()) return false; - - $plan = $this->loadModel('file')->processImgURL($plan, $this->config->productplan->editor->start['id'], $this->post->uid); - - $this->dao->update(TABLE_PRODUCTPLAN) - ->data($plan) - ->autoCheck() - ->batchCheck($this->config->productplan->start->requiredFields, 'notempty') - ->checkIF(!empty($plan->begin) and !empty($plan->end), 'end', 'ge', $plan->begin) - ->where('id')->eq($planID) - ->exec(); - } - else - { - $plan = new stdClass(); - $plan->status = $status; - $this->dao->update(TABLE_PRODUCTPLAN)->data($plan)->where('id')->eq($planID)->exec(); - } + $this->dao->update(TABLE_PRODUCTPLAN)->data($plan)->where('id')->eq($planID)->exec(); if(dao::isError()) return false; - if(isset($this->post->uid)) $this->file->updateObjectID($this->post->uid, $planID, 'productplan'); - return common::createChanges($oldPlan, $plan); + $changes = common::createChanges($oldPlan, $plan); + $actionID = $this->loadModel('action')->create('productplan', $planID, $action); + $this->action->logHistory($actionID, $changes); + + if($oldPlan->parent > 0) $this->updateParentStatus($oldPlan->parent, $action); + + return !dao::isError(); } /** * Update a parent plan's status. * * @param int $parentID + * @param string $action started|finished|closed|activated * @access public * @return void */ - public function updateParentStatus($parentID) + public function updateParentStatus($parentID, $action) { - $method = $this->app->rawMethod; - $needChange = true; - $parentPlan = $this->getByID($parentID); - $childStatus = $this->dao->select('status')->from(TABLE_PRODUCTPLAN)->where('parent')->eq($parentID)->andWhere('deleted')->eq(0)->fetchPairs('status', 'status'); + $parent = $this->getByID($parentID); + $childStatus = $this->dao->select('status')->from(TABLE_PRODUCTPLAN)->where('parent')->eq($parentID)->andWhere('deleted')->eq(0)->fetchPairs(); - if(isset($childStatus['doing'])) + switch($action) { - $parentStatus = 'doing'; - if($parentPlan->status != $parentStatus and $method == 'start') $parentAction = 'startedbychild'; - if($parentPlan->status != $parentStatus and $method == 'activate') $parentAction = 'activatedbychild'; - - } - elseif(isset($childStatus['wait']) and count($childStatus) == 1) - { - $parentStatus = 'wait'; - } - elseif(isset($childStatus['wait'])) - { - $parentStatus = 'doing'; - if($parentPlan->status != $parentStatus and $method == 'start') $parentAction = 'startedbychild'; - } - elseif(isset($childStatus['closed']) and count($childStatus) == 1) - { - $parentStatus = 'closed'; - if($parentPlan->status != $parentStatus) $parentAction = 'closedbychild'; - } - else - { - $parentStatus = 'done'; - if($parentPlan->status != $parentStatus) $parentAction = 'finishedbychild'; + case 'started': + $parentStatus = 'doing'; + $parentAction = $parent->status != 'doing' ? 'startedbychild' : ''; + break; + case 'finished': + if(count($childStatus) == 1 and $parent->status != 'done') + { + $parentStatus = 'done'; + $parentAction = 'finishedbychild'; + } + break; + case 'closed': + if(count($childStatus) == 1 and $parent->status != 'closed') + { + $parentAction = 'closedbychild'; + $parentStatus = 'closed'; + } + break; + case 'activated': + $parentStatus = 'doing'; + $parentAction = $parent->status != 'doing' ? 'activatedbychild' : ''; + break; } - if($parentPlan->status != $parentStatus) - { - $this->dao->update(TABLE_PRODUCTPLAN)->set('status')->eq($parentStatus)->where('id')->eq($parentID)->exec(); - if(dao::isError()) return false; + if(isset($parentStatus)) $this->dao->update(TABLE_PRODUCTPLAN)->set('status')->eq($parentStatus)->where('id')->eq($parentID)->exec(); + if(isset($parentAction)) $this->loadModel('action')->create('productplan', $parentID, $parentAction, '', $parentAction); - if(isset($parentAction)) $this->loadModel('action')->create('productplan', $parentID, $parentAction, '', $parentAction); - } + return !dao::isError(); } /**