* product: refactor browse function.

This commit is contained in:
chentao
2023-05-16 17:16:15 +08:00
parent c708416c5a
commit f71871a6cc
2 changed files with 59 additions and 55 deletions
+24 -19
View File
@@ -118,27 +118,33 @@ class product extends control
$this->loadModel('datatable');
$this->loadModel('execution');
$isProjectStory = $this->app->rawModule == 'projectstory';
$cookieOrderBy = $this->cookie->productStoryOrder ? $this->cookie->productStoryOrder : 'id_desc';
$cookieOrderBy = zget($this->cookie, 'productStoryOrder', 'id_desc');
$showModule = !empty($this->config->datatable->productBrowse->showModule) ? $this->config->datatable->productBrowse->showModule : '';
/* Load pager. */
$this->app->loadClass('pager', true);
if($this->app->getViewType() == 'xhtml') $recPerPage = 10;
$pager = new pager($recTotal, $recPerPage, $pageID);
/* Generate data. */
$showModule = !empty($this->config->datatable->productBrowse->showModule) ? $this->config->datatable->productBrowse->showModule : '';
$productID = $this->app->tab != 'project' ? $this->product->saveVisitState($productID, $this->products) : $productID;
$product = $this->productZen->getBrowseProduct($productID);
$project = $this->loadModel('project')->getByID($projectID);
list($branch, $branchID) = $this->productZen->getBranchAndBranchID($product, $branch);
$orderBy = $orderBy ? $orderBy : $cookieOrderBy;
$productID = $this->app->tab != 'project' ? $this->product->saveVisitState($productID, $this->products) : $productID;
$product = $this->productZen->getBrowseProduct($productID);
$project = $this->loadModel('project')->getByID($projectID);
$branchID = $this->productZen->getBranchID($product, $branch);
$orderBy = $orderBy ? $orderBy : $cookieOrderBy;
$branch = $branchID;
/* ATTENTION: be careful to change the order of follow sentencies. */
/* ATTENTION: be careful to change the order of follow sentences. */
$this->productZen->setMenu4Browse($projectID, $productID, $branch, $storyType);
$this->productZen->saveAndModifyCookie4Browse($productID, $branch, $param, $browseType, $orderBy);
/* Generate data. */
$moduleID = $this->productZen->getModuleId4Browse($param, $browseType);
$moduleTree = $this->productZen->getModuleTree4Browse($projectID, $productID, $branch, $param, $storyType, $browseType);
$showBranch = $this->productZen->canShowBranch4Browse($projectID, $productID, $storyType, $isProjectStory);
$projectProducts = $this->productZen->getProjectProducts4Browse($projectID, $storyType, $isProjectStory);
$productPlans = $this->productZen->getProductPlans4Browse($projectProducts, $projectID, $storyType, $isProjectStory);
list($stories, $pager) = $this->productZen->getStoriesAndPager4Browse($projectID, $productID, $branchID, $moduleID, $param, $storyType, $browseType, $orderBy, $recTotal, $recPerPage, $pageID);
$moduleID = $this->productZen->getModuleId($param, $browseType);
$moduleTree = $this->productZen->getModuleTree($projectID, $productID, $branch, $param, $storyType, $browseType);
$showBranch = $this->productZen->canShowBranch($projectID, $productID, $storyType, $isProjectStory);
$projectProducts = $this->productZen->getProjectProductList($projectID, $storyType, $isProjectStory);
$productPlans = $this->productZen->getProductPlans($projectProducts, $projectID, $storyType, $isProjectStory);
$stories = $this->productZen->getStories($projectID, $productID, $branchID, $moduleID, $param, $storyType, $browseType, $orderBy, $pager);
/* Process the sql, get the conditon partion, save it to session. */
$queryCondition = $this->story->dao->get();
@@ -148,12 +154,13 @@ class product extends control
$storyIdList = $this->productZen->getStoryIdList($stories);
/* Generate data. */
list($branchOpt, $branchTagOpt) = $this->productZen->getBranchAndTagOption4Browse($projectID, $product, $isProjectStory);
$branchOptions = (empty($product) && $isProjectStory) ? $this->productZen->getBranchOptions4Browse($projectProducts, $projectID) : array();
list($branchOpt, $branchTagOpt) = $this->productZen->getBranchAndTagOption($projectID, $product, $isProjectStory);
$branchOptions = (empty($product) && $isProjectStory) ? $this->productZen->getBranchOptions($projectProducts, $projectID) : array();
$storyTasks = $this->loadModel('task')->getStoryTaskCounts($storyIdList);
$storyBugs = $this->loadModel('bug')->getStoryBugCounts($storyIdList);
$storyCases = $this->loadModel('testcase')->getStoryCaseCounts($storyIdList);
$productName = ($isProjectStory and empty($productID)) ? $this->lang->product->all : $this->products[$productID];
$modulePairs = $showModule ? $this->tree->getModulePairs($productID, 'story', $showModule) : array();
/* Save session. */
$this->productZen->saveSession4Browse($product, $storyType, $browseType, $isProjectStory);
@@ -163,8 +170,6 @@ class product extends control
/* Assign. */
$this->view->title = $productName . $this->lang->colon . ($storyType === 'story' ? $this->lang->product->browse : $this->lang->product->requirement);
$this->view->position[] = $productName;
$this->view->position[] = $this->lang->product->browse;
$this->view->productID = $productID;
$this->view->product = $product;
$this->view->productName = $productName;
@@ -199,7 +204,7 @@ class product extends control
$this->view->projectProducts = !empty($projectProducts) ? $projectProducts : array();
$this->view->storyType = $storyType;
$this->view->from = $this->app->tab;
$this->view->modulePairs = $showModule ? $this->tree->getModulePairs($productID, 'story', $showModule) : array();
$this->view->modulePairs = $modulePairs;
$this->view->project = $project;
$this->view->recTotal = $pager->recTotal;
+35 -36
View File
@@ -1058,39 +1058,39 @@ class productZen extends product
* 获取研发需求列表页面关联的产品信息。
* Get the product of the browse page.
*
* @param int $productID
* @param int $productID
* @access protected
* @return object|false
* @return object|null
*/
protected function getBrowseProduct(int $productID): object|false
protected function getBrowseProduct(int $productID): object|null
{
$product = $this->product->getById($productID);
if(empty($product)) return null;
/* If product does not exist in $this->products list, then attach it to the list. */
if($product && !isset($this->products[$product->id])) $this->products[$product->id] = $product->name;
if(!isset($this->products[$product->id])) $this->products[$product->id] = $product->name;
return $product ? $product : false;
return $product;
}
/**
* 获取产品的分支和分支ID。
* Get branch and branchID.
* 获取产品分支ID。
* Get branchID.
*
* @param object $product
* @param string $branch
* @param object|null $product
* @param string $branch
* @access protected
* @return object
* @return string
*/
protected function getBranchAndBranchID(object|bool $product, string $branch): array
protected function getBranchID(object|null $product, string $branch): string
{
if(empty($product) || $product->type == 'normal') return ['all', 'all'];
if(empty($product) || $product->type == 'normal') return 'all';
/* 获取分支和分支ID。*/
$branchPairs = $this->loadModel('branch')->getPairs($product->id, 'all');
$branch = ($this->cookie->preBranch !== '' and $branch === '' and isset($branchPairs[$this->cookie->preBranch])) ? $this->cookie->preBranch : $branch;
$branchID = $branch;
$branchID = ($this->cookie->preBranch !== '' and $branch === '' and isset($branchPairs[$this->cookie->preBranch])) ? $this->cookie->preBranch : $branch;
return [$branch, $branchID];
return $branchID;
}
/**
@@ -1170,7 +1170,7 @@ class productZen extends product
* @access protected
* @return int
*/
protected function getModuleId4Browse(int $param, string $browseType): int
protected function getModuleId(int $param, string $browseType): int
{
if($browseType == 'bymodule') return $param;
@@ -1193,12 +1193,18 @@ class productZen extends product
* @access protected
* @return string
*/
protected function getModuleTree4Browse(int $projectID, int $productID, string &$branch, int $param, string $storyType, string $browseType): string
protected function getModuleTree(int $projectID, int $productID, string &$branch, int $param, string $storyType, string $browseType): string
{
/* Set moduleTree. */
$createModuleLink = $storyType == 'story' ? 'createStoryLink' : 'createRequirementLink';
if($browseType == '') $browseType = 'unclosed';
else $branch = $this->cookie->treeBranch;
if($browseType == '')
{
$browseType = 'unclosed';
}
else
{
$branch = $this->cookie->treeBranch;
}
/* If in project story and not chose product, get project story mdoules. */
if(empty($productID) && $this->app->rawModule == 'projectstory')
@@ -1224,7 +1230,7 @@ class productZen extends product
* @access protected
* @return bool
*/
protected function canShowBranch4Browse(int $projectID, int $productID, string $storyType, bool $isProjectStory): bool
protected function canShowBranch(int $projectID, int $productID, string $storyType, bool $isProjectStory): bool
{
if($isProjectStory && $storyType == 'story') return $this->loadModel('branch')->showBranch($productID, 0, $projectID);
@@ -1241,7 +1247,7 @@ class productZen extends product
* @access protected
* @return array
*/
protected function getProjectProducts4Browse(int $projectID, string $storyType, bool $isProjectStory): array
protected function getProjectProductList(int $projectID, string $storyType, bool $isProjectStory): array
{
if($isProjectStory && $storyType == 'story') return $this->product->getProducts($projectID);
@@ -1259,7 +1265,7 @@ class productZen extends product
* @access protected
* @return array
*/
protected function getProductPlans4Browse(array $projectProducts, int $projectID, string $storyType, bool $isProjectStory): array
protected function getProductPlans(array $projectProducts, int $projectID, string $storyType, bool $isProjectStory): array
{
if($isProjectStory && $storyType == 'story') return $this->loadModel('execution')->getPlans($projectProducts, 'skipParent,unexpired,noclosed', $projectID);
@@ -1268,7 +1274,7 @@ class productZen extends product
/**
* 获取需求列表及分页对象。
* Get stories and the pager object.
* Get stories.
*
* @param int $projectID
* @param int $productID
@@ -1278,23 +1284,16 @@ class productZen extends product
* @param string $storyType
* @param string $browseType
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @param object $pager
* @access protected
* @return array
*/
protected function getStoriesAndPager4Browse(int $projectID, int $productID, string $branchID, int $moduleID, int $param, string $storyType, string $browseType, string $orderBy, int $recTotal, int $recPerPage, int $pageID): array
protected function getStories(int $projectID, int $productID, string $branchID, int $moduleID, int $param, string $storyType, string $browseType, string $orderBy, object $pager): array
{
/* Append id for secend sort. */
$sort = common::appendOrder($orderBy);
if(strpos($sort, 'pri_') !== false) $sort = str_replace('pri_', 'priOrder_', $sort);
/* Load pager. */
$this->app->loadClass('pager', true);
if($this->app->getViewType() == 'xhtml') $recPerPage = 10;
$pager = new pager($recTotal, $recPerPage, $pageID);
$isProjectStory = $this->app->rawModule == 'projectstory';
/* Get stories. */
@@ -1313,7 +1312,7 @@ class productZen extends product
if(!empty($stories)) $stories = $this->story->mergeReviewer($stories);
return array($stories, $pager);
return $stories;
}
/**
@@ -1325,7 +1324,7 @@ class productZen extends product
* @access protected
* @return array
*/
protected function getBranchOptions4Browse(array $projectProducts, int $projectID): array
protected function getBranchOptions(array $projectProducts, int $projectID): array
{
$this->loadModel('branch');
@@ -1346,12 +1345,12 @@ class productZen extends product
* Get options of branch and branch tag.
*
* @param int $productID
* @param object|bool $product
* @param object|null $product
* @param bool $isProjectStory
* @access protected
* @return array[]
*/
protected function getBranchAndTagOption4Browse(int $projectID, object|bool $product, bool $isProjectStory): array
protected function getBranchAndTagOption(int $projectID, object|null $product, bool $isProjectStory): array
{
$branchOption = array();
$branchTagOption = array();