* refactor browse method for bug module.

This commit is contained in:
chenfeiCF
2016-03-01 06:00:25 +08:00
parent da0b5e611d
commit 127d2e6a40
2 changed files with 130 additions and 83 deletions
+31 -83
View File
@@ -52,6 +52,7 @@ class bug extends control
* Browse bugs.
*
* @param int $productID
* @param string $branch
* @param string $browseType
* @param int $param
* @param string $orderBy
@@ -63,10 +64,10 @@ class bug extends control
*/
public function browse($productID = 0, $branch = '', $browseType = 'unclosed', $param = 0, $orderBy = '', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
/* Set browseType, productID, moduleID and queryID. */
/* Set browseType, productID, moduleID, queryID and branch. */
$browseType = strtolower($browseType);
$productID = $this->product->saveState($productID, $this->products);
if($branch === '') $branch = $this->session->branch;
$branch = ($branch == '') ? $this->session->branch : $branch;
$moduleID = ($browseType == 'bymodule') ? (int)$param : 0;
$queryID = ($browseType == 'bysearch') ? (int)$param : 0;
@@ -86,98 +87,45 @@ class bug extends control
if($this->app->getViewType() == 'mhtml') $recPerPage = 10;
$pager = pager::init($recTotal, $recPerPage, $pageID);
$projects = $this->loadModel('project')->getPairs();
$projects[0] = '';
/* Get projects. */
$projects = $this->loadModel('project')->getPairs() + array('0' => '');
/* Get bugs. */
$bugs = array();
if($browseType == 'all') $bugs = $this->bug->getAllBugs($productID, $branch, $projects, $sort, $pager);
elseif($browseType == "bymodule")
{
$childModuleIds = $this->tree->getAllChildId($moduleID);
$bugs = $this->bug->getModuleBugs($productID, $branch, $childModuleIds, $projects, $sort, $pager);
}
elseif($browseType == 'assigntome') $bugs = $this->bug->getByAssigntome($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'openedbyme') $bugs = $this->bug->getByOpenedbyme($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'resolvedbyme') $bugs = $this->bug->getByResolvedbyme($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'assigntonull') $bugs = $this->bug->getByAssigntonull($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'unconfirmed') $bugs = $this->bug->getUnconfirmed($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'unresolved') $bugs = $this->bug->getByStatus($productID, $branch, $projects, 'unresolved', $sort, $pager);
elseif($browseType == 'unclosed') $bugs = $this->bug->getByStatus($productID, $branch, $projects, 'unclosed', $sort, $pager);
elseif($browseType == 'toclosed') $bugs = $this->bug->getByStatus($productID, $branch, $projects, 'toclosed', $sort, $pager);
elseif($browseType == 'longlifebugs') $bugs = $this->bug->getByLonglifebugs($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'postponedbugs') $bugs = $this->bug->getByPostponedbugs($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'needconfirm') $bugs = $this->bug->getByNeedconfirm($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'bysearch') $bugs = $this->bug->getBySearch($productID, $queryID, $sort, $pager, $branch);
$childModuleIds = ($browseType == 'bymodule') ? $this->tree->getAllChildId($moduleID) : array();
$bugs = $this->bug->getBugs($productID, $projects, $branch, $browseType, $childModuleIds, $queryID, $sort, $pager);
/* Process the sql, get the conditon partion, save it to session. */
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'bug', $browseType == 'needconfirm' ? false : true);
/* Process bug for check story changed. */
$bugs = $this->loadModel('story')->checkNeedConfirm($bugs);
/* Build the search form. */
$this->config->bug->search['actionURL'] = $this->createLink('bug', 'browse', "productID=$productID&branch=$branch&browseType=bySearch&queryID=myQueryID");
$this->config->bug->search['queryID'] = $queryID;
$this->config->bug->search['params']['product']['values'] = array($productID => $this->products[$productID], 'all' => $this->lang->bug->allProduct);
$this->config->bug->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairs($productID);
$this->config->bug->search['params']['module']['values'] = $this->tree->getOptionMenu($productID, $viewType = 'bug', $startModuleID = 0);
$this->config->bug->search['params']['project']['values'] = $this->product->getProjectPairs($productID);
$this->config->bug->search['params']['openedBuild']['values'] = $this->loadModel('build')->getProductBuildPairs($productID, 0, $params = '');
$this->config->bug->search['params']['resolvedBuild']['values'] = $this->config->bug->search['params']['openedBuild']['values'];
if($this->session->currentProductType == 'normal')
{
unset($this->config->bug->search['fields']['branch']);
unset($this->config->bug->search['params']['branch']);
}
else
{
$this->config->bug->search['fields']['branch'] = $this->lang->product->branch;
$this->config->bug->search['params']['branch']['values'] = array('' => '') + $this->loadModel('branch')->getPairs($productID, 'noempty');
}
$this->loadModel('search')->setSearchParams($this->config->bug->search);
$users = $this->user->getPairs('noletter');
$bugs = $this->loadModel('story')->checkNeedConfirm($bugs);
/* Process the openedBuild and resolvedBuild fields. */
$productIdList = array();
foreach($bugs as $bug) $productIdList[$bug->id] = $bug->product;
$builds = $this->loadModel('build')->getProductBuildPairs(array_unique($productIdList), 0, $params = '');
foreach($bugs as $key => $bug)
{
$openBuildIdList = explode(',', $bug->openedBuild);
$openedBuild = '';
foreach($openBuildIdList as $buildID)
{
$openedBuild .= isset($builds[$buildID]) ? $builds[$buildID] : $buildID;
$openedBuild .= ',';
}
$bug->openedBuild = rtrim($openedBuild, ',');
$bug->resolvedBuild = isset($builds[$bug->resolvedBuild]) ? $builds[$bug->resolvedBuild] : $bug->resolvedBuild;
}
$bugs = $this->bug->processBuildForBugs($bugs);
$memberPairs = $this->user->getPairs('noletter|nodeleted');
$title = $this->products[$productID] . $this->lang->colon . $this->lang->bug->common;
$position[] = html::a($this->createLink('bug', 'browse', "productID=$productID"), $this->products[$productID]);
$position[] = $this->lang->bug->common;
/* Build the search form. */
$actionURL = $this->createLink('bug', 'browse', "productID=$productID&branch=$branch&browseType=bySearch&queryID=myQueryID");
$this->bug->buildSearchForm($productID, $this->products, $queryID, $actionURL);
$this->loadModel('search')->setSearchParams($this->config->bug->search);
$this->view->title = $title;
$this->view->position = $position;
$this->view->productID = $productID;
$this->view->productName = $this->products[$productID];
$this->view->builds = $this->loadModel('build')->getProductBuildPairs($productID);
$this->view->moduleTree = $this->tree->getTreeMenu($productID, $viewType = 'bug', $startModuleID = 0, array('treeModel', 'createBugLink'), '', $branch);
$this->view->browseType = $browseType;
$this->view->bugs = $bugs;
$this->view->users = $users;
$this->view->pager = $pager;
$this->view->param = $param;
$this->view->orderBy = $orderBy;
$this->view->moduleID = $moduleID;
$this->view->memberPairs = $memberPairs;
$this->view->branch = $branch;
$this->view->branches = $this->loadModel('branch')->getPairs($productID);
/* Set view. */
$this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->bug->common;
$this->view->position[] = html::a($this->createLink('bug', 'browse', "productID=$productID"), $this->products[$productID]);
$this->view->position[] = $this->lang->bug->common;
$this->view->productID = $productID;
$this->view->productName = $this->products[$productID];
$this->view->builds = $this->loadModel('build')->getProductBuildPairs($productID);
$this->view->moduleTree = $this->tree->getTreeMenu($productID, $viewType = 'bug', $startModuleID = 0, array('treeModel', 'createBugLink'), '', $branch);
$this->view->browseType = $browseType;
$this->view->bugs = $bugs;
$this->view->users = $this->user->getPairs('noletter');
$this->view->pager = $pager;
$this->view->param = $param;
$this->view->orderBy = $orderBy;
$this->view->moduleID = $moduleID;
$this->view->memberPairs = $this->user->getPairs('noletter|nodeleted');
$this->view->branch = $branch;
$this->view->branches = $this->loadModel('branch')->getPairs($productID);
$this->display();
}
+99
View File
@@ -200,6 +200,43 @@ class bugModel extends model
return $actions;
}
/**
* Get bugs.
*
* @param int $productID
* @param array $projects
* @param int $branch
* @param string $browseType
* @param array $childModuleIds
* @param int $queryID
* @param string $sort
* @param object $pager
* @access public
* @return array
*/
public function getBugs($productID, $projects, $branch, $browseType, $childModuleIds, $queryID, $sort, $pager)
{
/* Get bugs by browse type. */
if($browseType == 'all') $bugs = $this->getAllBugs($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'bymodule') $bugs = $this->getModuleBugs($productID, $branch, $childModuleIds, $projects, $sort, $pager);
elseif($browseType == 'assigntome') $bugs = $this->getByAssigntome($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'openedbyme') $bugs = $this->getByOpenedbyme($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'resolvedbyme') $bugs = $this->getByResolvedbyme($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'assigntonull') $bugs = $this->getByAssigntonull($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'unconfirmed') $bugs = $this->getUnconfirmed($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'unresolved') $bugs = $this->getByStatus($productID, $branch, $projects, 'unresolved', $sort, $pager);
elseif($browseType == 'unclosed') $bugs = $this->getByStatus($productID, $branch, $projects, 'unclosed', $sort, $pager);
elseif($browseType == 'toclosed') $bugs = $this->getByStatus($productID, $branch, $projects, 'toclosed', $sort, $pager);
elseif($browseType == 'longlifebugs') $bugs = $this->getByLonglifebugs($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'postponedbugs') $bugs = $this->getByPostponedbugs($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'needconfirm') $bugs = $this->getByNeedconfirm($productID, $branch, $projects, $sort, $pager);
elseif($browseType == 'bysearch') $bugs = $this->getBySearch($productID, $queryID, $sort, $pager, $branch);
if($bugs) return $bugs;
return array();
}
/**
* Get bugs of a module.
*
@@ -757,6 +794,68 @@ class bugModel extends model
$this->dao->update(TABLE_BUG)->data($bug)->autoCheck()->where('id')->eq((int)$bugID)->exec();
}
/**
* Build search form.
*
* @param int $productID
* @param array $products
* @param int $queryID
* @param string $actionURL
* @access public
* @return void
*/
public function buildSearchForm($productID, $products, $queryID, $actionURL)
{
$this->config->bug->search['actionURL'] = $actionURL;
$this->config->bug->search['queryID'] = $queryID;
$this->config->bug->search['params']['product']['values'] = array($productID => $products[$productID], 'all' => $this->lang->bug->allProduct);
$this->config->bug->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairs($productID);
$this->config->bug->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($productID, $viewType = 'bug', $startModuleID = 0);
$this->config->bug->search['params']['project']['values'] = $this->product->getProjectPairs($productID);
$this->config->bug->search['params']['openedBuild']['values'] = $this->loadModel('build')->getProductBuildPairs($productID, 0, $params = '');
$this->config->bug->search['params']['resolvedBuild']['values'] = $this->config->bug->search['params']['openedBuild']['values'];
if($this->session->currentProductType == 'normal')
{
unset($this->config->bug->search['fields']['branch']);
unset($this->config->bug->search['params']['branch']);
}
else
{
$this->config->bug->search['fields']['branch'] = $this->lang->product->branch;
$this->config->bug->search['params']['branch']['values'] = array('' => '') + $this->loadModel('branch')->getPairs($productID, 'noempty');
}
}
/**
* Process the openedBuild and resolvedBuild fields for bugs.
*
* @param array $bugs
* @access public
* @return array
*/
public function processBuildForBugs($bugs)
{
$productIdList = array();
foreach($bugs as $bug) $productIdList[$bug->id] = $bug->product;
$builds = $this->loadModel('build')->getProductBuildPairs(array_unique($productIdList), 0, $params = '');
/* Process the openedBuild and resolvedBuild fields. */
foreach($bugs as $key => $bug)
{
$openBuildIdList = explode(',', $bug->openedBuild);
$openedBuild = '';
foreach($openBuildIdList as $buildID)
{
$openedBuild .= isset($builds[$buildID]) ? $builds[$buildID] : $buildID;
$openedBuild .= ',';
}
$bug->openedBuild = rtrim($openedBuild, ',');
$bug->resolvedBuild = isset($builds[$bug->resolvedBuild]) ? $builds[$bug->resolvedBuild] : $bug->resolvedBuild;
}
return $bugs;
}
/**
* Extract accounts from some bugs.
*