From e9600a6322bce6d15658acfb4d1a932bb55af95b Mon Sep 17 00:00:00 2001 From: tianshujie Date: Fri, 1 Sep 2023 11:07:13 +0800 Subject: [PATCH] * Refactor manageProducts method. --- module/execution/config/form.php | 11 +++++ module/execution/control.php | 70 +++++++------------------------- module/execution/model.php | 31 +++++++------- module/execution/zen.php | 53 ++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 70 deletions(-) diff --git a/module/execution/config/form.php b/module/execution/config/form.php index cfd5a581b8..81a40453f3 100644 --- a/module/execution/config/form.php +++ b/module/execution/config/form.php @@ -22,3 +22,14 @@ $config->execution->form->managemembers['hours'] = array('type' => 'float', 'r $config->execution->form->managemembers['limited'] = array('type' => 'string', 'required' => false, 'default' => 'no'); $config->execution->form->managemembers['type'] = array('type' => 'string', 'required' => false, 'default' => 'execution'); $config->execution->form->managemembers['root'] = array('type' => 'int', 'required' => false, 'default' => 0); + +$config->execution->form->manageproducts['products'] = array('type' => 'array', 'required' => false, 'default' => array()); +$config->execution->form->manageproducts['branch'] = array('type' => 'array', 'required' => false, 'default' => array()); + +$config->execution->form->create['products'] = array('type' => 'array', 'required' => false, 'default' => array()); +$config->execution->form->create['branch'] = array('type' => 'array', 'required' => false, 'default' => array()); +$config->execution->form->create['plans'] = array('type' => 'array', 'required' => false, 'default' => array()); + +$config->execution->form->edit['products'] = array('type' => 'array', 'required' => false, 'default' => array()); +$config->execution->form->edit['branch'] = array('type' => 'array', 'required' => false, 'default' => array()); +$config->execution->form->edit['plans'] = array('type' => 'array', 'required' => false, 'default' => array()); diff --git a/module/execution/control.php b/module/execution/control.php index b01a4807ae..e7e3f26745 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -1680,10 +1680,11 @@ class execution extends control $_POST['plans'] = array_filter($_POST['plans']); } + $postData = form::data()->get(); $executionID = $this->execution->create($copyExecutionID); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->execution->updateProducts($executionID); + $this->execution->updateProducts($executionID, $postData); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); $comment = $project->hasProduct ? implode(',', $_POST['products']) : ''; @@ -1845,12 +1846,13 @@ class execution extends control if(!empty($_POST)) { + $postData = form::data()->get(); $oldPlans = $this->dao->select('plan')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($executionID)->andWhere('plan')->ne(0)->fetchPairs('plan'); $oldProducts = $this->product->getProducts($executionID, 'all', '', true, $linkedProductIdList); $changes = $this->execution->update($executionID); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); - $this->execution->updateProducts($executionID); + $this->execution->updateProducts($executionID, $postData); if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError())); if($action == 'undelete') { @@ -2827,30 +2829,30 @@ class execution extends control } /** + * 维护关联产品。 * Manage products. * * @param int $executionID * @access public * @return void */ - public function manageProducts($executionID) + public function manageProducts(int $executionID) { - /* use first execution if executionID does not exist. */ + /* Use first execution if executionID does not exist. */ if(!isset($this->executions[$executionID])) $executionID = key($this->executions); - $this->loadModel('product'); - $execution = $this->execution->getById($executionID); - $project = $this->loadModel('project')->getByID($execution->project); - if(!$project->hasProduct) return print(js::error($this->lang->project->cannotManageProducts) . js::locate('back')); - if($project->model == 'waterfall' or $project->model == 'waterfallplus') return print(js::error(sprintf($this->lang->execution->cannotManageProducts, zget($this->lang->project->modelList, $project->model))) . js::locate('back')); + $execution = $this->execution->getByID($executionID); + $project = $this->project->getByID($execution->project); + if(!$project->hasProduct) return $this->sendError($this->lang->project->cannotManageProducts, true); + if($project->model == 'waterfall' || $project->model == 'waterfallplus') return $this->sendError(sprintf($this->lang->execution->cannotManageProducts, zget($this->lang->project->modelList, $project->model)), true); if(!empty($_POST)) { - $oldProducts = $this->product->getProducts($executionID); - - $this->execution->updateProducts($executionID); + $postData = form::data()->get(); + $this->execution->updateProducts($executionID, $postData); if(dao::isError()) return $this->sendError(dao::getError()); + $oldProducts = $this->loadModel('product')->getProducts($executionID); $oldProducts = array_keys($oldProducts); $newProducts = $this->product->getProducts($executionID); $newProducts = array_keys($newProducts); @@ -2863,49 +2865,7 @@ class execution extends control /* Set menu. */ $this->execution->setMenu($execution->id); - /* Title and position. */ - $branches = $this->project->getBranchesByProject($executionID); - $linkedProductIdList = empty($branches) ? array() : array_keys($branches); - $allProducts = $this->product->getProductPairsByProject($execution->project, 'all', implode(',', $linkedProductIdList)); - $linkedProducts = $this->product->getProducts($execution->id, 'all', '', true, $linkedProductIdList); - $linkedBranches = array(); - $executionStories = $this->project->getStoriesByProject($executionID); - - /* If the story of the product which linked the execution, you don't allow to remove the product. */ - $unmodifiableProducts = array(); - $unmodifiableBranches = array(); - $linkedStoryIDList = array(); - $linkedBranchIdList = array(); - foreach($linkedProducts as $productID => $linkedProduct) - { - $linkedBranches[$productID] = array(); - if(!isset($allProducts[$productID])) $allProducts[$productID] = $linkedProduct->name; - foreach($branches[$productID] as $branchID => $branch) - { - $linkedBranches[$productID][$branchID] = $branchID; - $linkedBranchIdList[$branchID] = $branchID; - if(!empty($executionStories[$productID][$branchID])) - { - array_push($unmodifiableProducts, $productID); - array_push($unmodifiableBranches, $branchID); - $linkedStoryIDList[$productID][$branchID] = $executionStories[$productID][$branchID]->storyIDList; - } - } - } - - /* Assign. */ - $this->view->title = $this->lang->execution->manageProducts . $this->lang->colon . $execution->name; - $this->view->allProducts = $allProducts; - $this->view->execution = $execution; - $this->view->linkedProducts = $linkedProducts; - $this->view->unmodifiableProducts = $unmodifiableProducts; - $this->view->unmodifiableBranches = $unmodifiableBranches; - $this->view->linkedBranches = $linkedBranches; - $this->view->linkedStoryIDList = $linkedStoryIDList; - $this->view->branchGroups = $this->execution->getBranchByProduct(array_keys($allProducts), $execution->project, 'ignoreNormal|noclosed', $linkedBranchIdList); - $this->view->allBranches = $this->execution->getBranchByProduct(array_keys($allProducts), $execution->project, 'ignoreNormal'); - - $this->display(); + $this->executionZen->assignManageProductsVars($execution); } /** diff --git a/module/execution/model.php b/module/execution/model.php index 0feb0f8248..4d98745f9a 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -482,8 +482,6 @@ class executionModel extends model /* Update the path. */ $this->setTreePath($executionID); - $this->updateProducts($executionID); - /* Set team of execution. */ $members = isset($_POST['teamMembers']) ? $_POST['teamMembers'] : array(); array_push($members, $sprint->PO, $sprint->QD, $sprint->PM, $sprint->RD, $sprint->openedBy); @@ -2762,17 +2760,18 @@ class executionModel extends model } /** + * 更新执行关联的产品信息。 * Update products of a execution. * * @param int $executionID - * @param array $products + * @param object $postData * @access public * @return void */ - public function updateProducts($executionID, $products = '') + public function updateProducts($executionID, object $postData) { $this->loadModel('user'); - $products = isset($_POST['products']) ? $_POST['products'] : $products; + $products = $postData->products; $oldProducts = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->eq((int)$executionID)->fetchGroup('product', 'branch'); $this->dao->delete()->from(TABLE_PROJECTPRODUCT)->where('project')->eq((int)$executionID)->exec(); $members = array_keys($this->getTeamMembers($executionID)); @@ -2782,8 +2781,8 @@ class executionModel extends model return true; } - $branches = isset($_POST['branch']) ? $_POST['branch'] : array(); - $plans = isset($_POST['plans']) ? $_POST['plans'] : array(); + $branches = isset($postData->branch) ? $postData->branch : array(); + $plans = isset($postData->plans) ? $postData->plans : array(); $existedProducts = array(); foreach($products as $i => $productID) @@ -2792,9 +2791,7 @@ class executionModel extends model if(!isset($existedProducts[$productID])) $existedProducts[$productID] = array(); $oldPlan = 0; - $branch = isset($branches[$i]) ? $branches[$i] : 0; - - if(!is_array($branch)) $branch = array($branch); + $branch = isset($branches[$i]) ? (array) $branches[$i] : array(); foreach($branch as $branchID) { @@ -5416,12 +5413,16 @@ class executionModel extends model foreach($extendFields as $field) $_POST[$field->field] = $project->field; if(isset($this->config->setCode) and $this->config->setCode == 1) $_POST['code'] = $project->code; - $projectProducts = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($projectID)->fetchAll(); + $updateProductsData = new stdclass(); + $updateProductsData->products = array(); + $updateProductsData->branch = array(); + $updateProductsData->plans = array(); + $projectProducts = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($projectID)->fetchAll(); foreach($projectProducts as $projectProduct) { - $_POST['products'][] = $projectProduct->product; - $_POST['branch'][] = $projectProduct->branch; - if($projectProduct->plan) $_POST['plans'][$projectProduct->product] = explode(',', trim($projectProduct->plan, ',')); + $updateProductsData->products[] = $projectProduct->product; + $updateProductsData->branch[] = $projectProduct->branch; + if($projectProduct->plan) $updateProductsData->plans[$projectProduct->product] = explode(',', trim($projectProduct->plan, ',')); } $teamMembers = $this->dao->select('*')->from(TABLE_TEAM)->where('type')->eq('project')->andWhere('root')->eq($projectID)->fetchPairs('account', 'account'); @@ -5432,7 +5433,7 @@ class executionModel extends model if($executionID) { $this->update($executionID); - $this->updateProducts($executionID); + $this->updateProducts($executionID, $updateProductsData); } $_POST = $postData; diff --git a/module/execution/zen.php b/module/execution/zen.php index 2898a26b64..d6b97a49ef 100644 --- a/module/execution/zen.php +++ b/module/execution/zen.php @@ -65,6 +65,59 @@ class executionZen extends execution $this->view->allPlans = $allPlans; } + /** + * 展示维护产品相关变量。 + * Show the manage products related variables. + * + * @param object $execution + * @access protected + * @return void + */ + protected function assignManageProductsVars(object $execution) + { + $branches = $this->project->getBranchesByProject($execution->id); + $linkedProductIdList = empty($branches) ? array() : array_keys($branches); + $allProducts = $this->loadModel('product')->getProductPairsByProject($execution->project, 'all', implode(',', $linkedProductIdList)); + $linkedProducts = $this->product->getProducts($execution->id, 'all', '', true, $linkedProductIdList); + $linkedBranches = array(); + $executionStories = $this->project->getStoriesByProject($execution->id); + + /* If the story of the product which linked the execution, you don't allow to remove the product. */ + $unmodifiableProducts = array(); + $unmodifiableBranches = array(); + $linkedStoryIDList = array(); + $linkedBranchIdList = array(); + foreach($linkedProducts as $productID => $linkedProduct) + { + $linkedBranches[$productID] = array(); + if(!isset($allProducts[$productID])) $allProducts[$productID] = $linkedProduct->name; + foreach($branches[$productID] as $branchID => $branch) + { + $linkedBranches[$productID][$branchID] = $branchID; + $linkedBranchIdList[$branchID] = $branchID; + if(!empty($executionStories[$productID][$branchID])) + { + array_push($unmodifiableProducts, $productID); + array_push($unmodifiableBranches, $branchID); + $linkedStoryIDList[$productID][$branchID] = $executionStories[$productID][$branchID]->storyIDList; + } + } + } + + $this->view->title = $this->lang->execution->manageProducts . $this->lang->colon . $execution->name; + $this->view->execution = $execution; + $this->view->linkedProducts = $linkedProducts; + $this->view->unmodifiableProducts = $unmodifiableProducts; + $this->view->unmodifiableBranches = $unmodifiableBranches; + $this->view->linkedBranches = $linkedBranches; + $this->view->linkedStoryIDList = $linkedStoryIDList; + $this->view->allProducts = $allProducts; + $this->view->branchGroups = $this->execution->getBranchByProduct(array_keys($allProducts), $execution->project, 'ignoreNormal|noclosed', $linkedBranchIdList); + $this->view->allBranches = $this->execution->getBranchByProduct(array_keys($allProducts), $execution->project, 'ignoreNormal'); + + $this->display(); + } + /** * 展示任务看板的相关变量。 * Show the task Kanban related variables.