* refactor browse method for product module.

This commit is contained in:
chenfeiCF
2016-03-01 08:28:35 +08:00
parent c7168f7db7
commit 12ec619856
2 changed files with 96 additions and 44 deletions
+9 -44
View File
@@ -117,7 +117,7 @@ class product extends control
/* Set product, module and query. */
$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;
@@ -131,61 +131,26 @@ class product extends control
/* Append id for secend sort. */
$sort = $this->loadModel('common')->appendOrder($orderBy);
/* Set header and position. */
$this->view->title = $this->products[$productID]. $this->lang->colon . $this->lang->product->browse;
$this->view->position[] = $this->products[$productID];
$this->view->position[] = $this->lang->product->browse;
/* Load pager. */
$this->app->loadClass('pager', $static = true);
if($this->app->getViewType() == 'mhtml') $recPerPage = 10;
$pager = new pager($recTotal, $recPerPage, $pageID);
/* Get stories. */
$stories = array();
if($browseType == 'unclosed')
{
$unclosedStatus = $this->lang->story->statusList;
unset($unclosedStatus['closed']);
$stories = $this->story->getProductStories($productID, $branch, 0, array_keys($unclosedStatus), $sort, $pager);
}
if($browseType == 'allstory') $stories = $this->story->getProductStories($productID, $branch, 0, 'all', $sort, $pager);
if($browseType == 'bymodule') $stories = $this->story->getProductStories($productID, $branch, $this->tree->getAllChildID($moduleID), 'all', $sort, $pager);
if($browseType == 'bysearch') $stories = $this->story->getBySearch($productID, $queryID, $sort, $pager, '', $branch);
if($browseType == 'assignedtome')$stories = $this->story->getByAssignedTo($productID, $branch, $this->app->user->account, $sort, $pager);
if($browseType == 'openedbyme') $stories = $this->story->getByOpenedBy($productID, $branch, $this->app->user->account, $sort, $pager);
if($browseType == 'reviewedbyme')$stories = $this->story->getByReviewedBy($productID, $branch, $this->app->user->account, $sort, $pager);
if($browseType == 'closedbyme') $stories = $this->story->getByClosedBy($productID, $branch, $this->app->user->account, $sort, $pager);
if($browseType == 'draftstory') $stories = $this->story->getByStatus($productID, $branch, 'draft', $sort, $pager);
if($browseType == 'activestory') $stories = $this->story->getByStatus($productID, $branch, 'active', $sort, $pager);
if($browseType == 'changedstory')$stories = $this->story->getByStatus($productID, $branch, 'changed', $sort, $pager);
if($browseType == 'willclose') $stories = $this->story->getWillClose($productID, $branch, $sort, $pager);
if($browseType == 'closedstory') $stories = $this->story->getByStatus($productID, $branch, 'closed', $sort, $pager);
$stories = $this->product->getStories($productID, $branch, $browseType, $queryID, $moduleID, $sort, $pager);
/* Process the sql, get the conditon partion, save it to session. */
$this->loadModel('common')->saveQueryCondition($this->dao->get(), 'story');
/* Build search form. */
$this->config->product->search['actionURL'] = $this->createLink('product', 'browse', "productID=$productID&branch=$branch&browseType=bySearch&queryID=myQueryID");
$this->config->product->search['queryID'] = $queryID;
$this->config->product->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairs($productID);
$this->config->product->search['params']['product']['values'] = array($productID => $this->products[$productID], 'all' => $this->lang->product->allProduct);
$this->config->product->search['params']['module']['values'] = $this->tree->getOptionMenu($productID, $viewType = 'story', $startModuleID = 0);
if($this->session->currentProductType == 'normal')
{
unset($this->config->product->search['fields']['branch']);
unset($this->config->product->search['params']['branch']);
}
else
{
$this->config->product->search['fields']['branch'] = $this->lang->product->branch;
$this->config->product->search['params']['branch']['values'] = array('' => '') + $this->loadModel('branch')->getPairs($productID, 'noempty');
}
$actionURL = $this->createLink('product', 'browse', "productID=$productID&branch=$branch&browseType=bySearch&queryID=myQueryID");
$this->product->buildSearchForm($productID, $this->products, $queryID, $actionURL);
$this->loadModel('search')->setSearchParams($this->config->product->search);
$storyIdList = array();
foreach($stories as $story) $storyIdList[$story->id] = $story->id;
/* Set view. */
$this->view->title = $this->products[$productID]. $this->lang->colon . $this->lang->product->browse;
$this->view->position[] = $this->products[$productID];
$this->view->position[] = $this->lang->product->browse;
$this->view->productID = $productID;
$this->view->productName = $this->products[$productID];
$this->view->moduleID = $moduleID;
@@ -201,7 +166,7 @@ class product extends control
$this->view->moduleID = $moduleID;
$this->view->branch = $branch;
$this->view->branches = $this->loadModel('branch')->getPairs($productID);
$this->view->storyStages = $this->story->getStoryStages($storyIdList);
$this->view->storyStages = $this->product->getStoryStages($stories);
$this->display();
}
+87
View File
@@ -342,6 +342,93 @@ class productModel extends model
if(!dao::isError()) return common::createChanges($oldProduct, $product);
}
/**
* Get stories.
*
* @param int $productID
* @param int $branch
* @param string $browseType
* @param int $queryID
* @param int $moduleID
* @param string $sort
* @param object $pager
* @access public
* @return array
*/
public function getStories($productID, $branch, $browseType, $queryID, $moduleID, $sort, $pager)
{
$this->loadModel('story');
/* Get stories by browseType. */
if($browseType == 'unclosed')
{
$unclosedStatus = $this->lang->story->statusList;
unset($unclosedStatus['closed']);
$stories = $this->story->getProductStories($productID, $branch, 0, array_keys($unclosedStatus), $sort, $pager);
}
if($browseType == 'allstory') $stories = $this->story->getProductStories($productID, $branch, 0, 'all', $sort, $pager);
if($browseType == 'bymodule') $stories = $this->story->getProductStories($productID, $branch, $this->loadModel('tree')->getAllChildID($moduleID), 'all', $sort, $pager);
if($browseType == 'bysearch') $stories = $this->story->getBySearch($productID, $queryID, $sort, $pager, '', $branch);
if($browseType == 'assignedtome') $stories = $this->story->getByAssignedTo($productID, $branch, $this->app->user->account, $sort, $pager);
if($browseType == 'openedbyme') $stories = $this->story->getByOpenedBy($productID, $branch, $this->app->user->account, $sort, $pager);
if($browseType == 'reviewedbyme') $stories = $this->story->getByReviewedBy($productID, $branch, $this->app->user->account, $sort, $pager);
if($browseType == 'closedbyme') $stories = $this->story->getByClosedBy($productID, $branch, $this->app->user->account, $sort, $pager);
if($browseType == 'draftstory') $stories = $this->story->getByStatus($productID, $branch, 'draft', $sort, $pager);
if($browseType == 'activestory') $stories = $this->story->getByStatus($productID, $branch, 'active', $sort, $pager);
if($browseType == 'changedstory') $stories = $this->story->getByStatus($productID, $branch, 'changed', $sort, $pager);
if($browseType == 'willclose') $stories = $this->story->getWillClose($productID, $branch, $sort, $pager);
if($browseType == 'closedstory') $stories = $this->story->getByStatus($productID, $branch, 'closed', $sort, $pager);
if($stories) return $stories;
return array();
}
/**
* Get story stages.
*
* @param array $stories.
* @access public
* @return array
*/
public function getStoryStages($stories)
{
/* Set story id list. */
$storyIdList = array();
foreach($stories as $story) $storyIdList[$story->id] = $story->id;
return $this->loadModel('story')->getStoryStages($storyIdList);
}
/**
* Build search form.
*
* @param int $productID
* @param array $products
* @param int $queryID
* @param int $actionURL
* @access public
* @return void
*/
public function buildSearchForm($productID, $products, $queryID, $actionURL)
{
$this->config->product->search['actionURL'] = $actionURL;
$this->config->product->search['queryID'] = $queryID;
$this->config->product->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairs($productID);
$this->config->product->search['params']['product']['values'] = array($productID => $products[$productID], 'all' => $this->lang->product->allProduct);
$this->config->product->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($productID, $viewType = 'story', $startModuleID = 0);
if($this->session->currentProductType == 'normal')
{
unset($this->config->product->search['fields']['branch']);
unset($this->config->product->search['params']['branch']);
}
else
{
$this->config->product->search['fields']['branch'] = $this->lang->product->branch;
$this->config->product->search['params']['branch']['values'] = array('' => '') + $this->loadModel('branch')->getPairs($productID, 'noempty');
}
}
/**
* Get projects of a product in pairs.
*