* Refactor company::dynamic.

This commit is contained in:
wangxuepeng
2023-11-22 16:48:07 +08:00
parent b4d61070b4
commit 0fdf559c0b
4 changed files with 203 additions and 103 deletions
+3 -2
View File
@@ -2006,11 +2006,12 @@ class actionModel extends model
* @access public
* @return int
*/
public function getDynamicCount(): int
public function getDynamicCount($period = 'all'): int
{
$condition = $this->session->actionQueryCondition ? $this->session->actionQueryCondition : '1=1';
return $this->dao->select('count(1) as count')->from(TABLE_ACTION)
$table = $this->actionTao->getActionTable($period);
return $this->dao->select('count(1) as count')->from($table)
->where($condition)
->fetch('count');
}
+16 -3
View File
@@ -657,11 +657,11 @@ class actionTao extends actionModel
->beginIF($date)->andWhere('date' . ($direction == 'next' ? '<' : '>') . "'{$date}'")->fi()
->beginIF($account != 'all')->andWhere('actor')->eq($account)->fi()
->beginIF($beginDate)->andWhere('date')->ge($beginDate)->fi()
->beginIF(is_numeric($productID))->andWhere('product')->like("%,$productID,%")->fi()
->beginIF(is_numeric($productID) && $productID)->andWhere('product')->like("%,$productID,%")->fi()
->andWhere('1=1', true)
->beginIF(is_numeric($projectID))->andWhere('project')->eq($projectID)->fi()
->beginIF(is_numeric($projectID) && $projectID)->andWhere('project')->eq($projectID)->fi()
->beginIF(!empty($executions))->andWhere('execution')->in(array_keys($executions))->fi()
->beginIF(is_numeric($executionID))->andWhere('execution')->eq($executionID)->fi()
->beginIF(is_numeric($executionID) && $executionID)->andWhere('execution')->eq($executionID)->fi()
->markRight(1)
/* lite模式下需要排除的一些类型。 */
/* Types excluded from Lite. */
@@ -677,6 +677,19 @@ class actionTao extends actionModel
->fetchAll();
}
/**
* 根据条件获取动态表。
* Get action table by condition.
*
* @param string $period
* @access protected
* @return string
*/
protected function getActionTable(string $period): string
{
return in_array($period, $this->config->action->latestDateList) ? TABLE_ACTIONRECENT : TABLE_ACTION;
}
/**
* 检查Action是否合法。
* Check if action is legal.
+21 -98
View File
@@ -144,47 +144,27 @@ class company extends control
}
/**
* 公司动态。
* Company dynamic.
*
* @param string $browseType
* @param string $param
* @param int $recTotal
* @param string $date
* @param string $direction next|pre
* @param int $userID
* @param int $productID
* @param int $projectID
* @param int $executionID
* @param string $orderBy date_deac|date_asc
* @param string $browseType
* @param string $param
* @param int $recTotal
* @param string $date
* @param string $direction next|pre
* @param int $userID
* @param string|int $productID
* @param string|int $projectID
* @param string|int $executionID
* @param string $orderBy date_deac|date_asc
* @access public
* @return void
*/
public function dynamic($browseType = 'today', $param = '', $recTotal = 0, $date = '', $direction = 'next', $userID = '', $productID = 0, $projectID = 0, $executionID = 0, $orderBy = 'date_desc')
public function dynamic(string $browseType = 'today', string $param = '', int $recTotal = 0, string $date = '', string $direction = 'next', int $userID = 0, string|int $productID = 0, string|int $projectID = 0, string|int $executionID = 0, string $orderBy = 'date_desc')
{
$this->company->setMenu();
$this->app->loadLang('user');
$this->app->loadLang('execution');
$this->loadModel('action');
/* Save session. */
$uri = $this->app->getURI(true);
$this->session->set('productList', $uri, 'product');
$this->session->set('productPlanList', $uri, 'product');
$this->session->set('releaseList', $uri, 'product');
$this->session->set('storyList', $uri, 'product');
$this->session->set('projectList', $uri, 'project');
$this->session->set('riskList', $uri, 'project');
$this->session->set('opportunityList', $uri, 'project');
$this->session->set('trainplanList', $uri, 'project');
$this->session->set('taskList', $uri, 'execution');
$this->session->set('buildList', $uri, 'execution');
$this->session->set('bugList', $uri, 'qa');
$this->session->set('caseList', $uri, 'qa');
$this->session->set('testtaskList', $uri, 'qa');
$this->session->set('effortList', $uri, 'my');
$this->session->set('meetingList', $uri, 'my');
$this->session->set('meetingList', $uri, 'project');
$this->session->set('meetingroomList', $uri, 'admin');
$this->companyZen->saveUriIntoSession();
/* Append id for second sort. */
if($direction == 'next') $orderBy = 'date_desc';
@@ -193,46 +173,11 @@ class company extends control
$queryID = ($browseType == 'bysearch') ? (int)$param : 0;
$date = empty($date) ? '' : date('Y-m-d', $date);
/* Get products' list.*/
$products = $this->loadModel('product')->getPairs('nocode');
$products = array($this->lang->company->product) + $products;
$this->view->products = $products;
/* Set product, project, execution and user. */
$account = $this->companyZen->loadAllSearchModule($userID, $queryID);
/* Get projects' list.*/
$projects = $this->loadModel('project')->getPairsByProgram();
$this->view->projects = array($this->lang->company->project) + $projects;;
/* Get executions' list.*/
$executions = $this->loadModel('execution')->getPairs(0, 'all', 'nocode|multiple');
$executionList = $this->execution->getByIdList(array_keys($executions));
foreach($executionList as $id => $execution)
{
if(isset($projects[$execution->project])) $executions[$execution->id] = $projects[$execution->project] . $executions[$execution->id];
}
$executions = array($this->lang->execution->common) + $executions;
$this->view->executions = $executions;
/* Set account and get users.*/
$user = $userID ? $this->loadModel('user')->getById($userID, 'id') : '';
$account = $user ? $user->account : 'all';
$userIdPairs = $this->loadModel('user')->getPairs('noclosed|nodeleted|noletter|useid');
$userIdPairs[''] = $this->lang->company->user;
$this->view->userIdPairs = $userIdPairs;
$accountPairs = $this->user->getPairs('nodeleted|noletter|all');
$accountPairs[''] = '';
/* The header and position. */
$this->view->title = $this->lang->company->common . $this->lang->colon . $this->lang->company->dynamic;
/* Get actions. */
if($browseType != 'bysearch')
{
if(!$productID) $productID = 'all';
if(!$projectID) $projectID = 'all';
if(!$executionID) $executionID = 'all';
$actions = $this->action->getDynamic($account, $browseType, $orderBy, 50, $productID, $projectID, $executionID, $date, $direction);
}
else
@@ -240,39 +185,17 @@ class company extends control
$actions = $this->action->getDynamicBySearch($queryID, $orderBy, 50, $date, $direction);
}
/* Build search form. */
$executions[0] = '';
$products[0] = '';
$projects[0] = '';
ksort($executions);
ksort($products);
ksort($projects);
$executions['all'] = $this->lang->execution->allExecutions;
$products['all'] = $this->lang->product->allProduct;
$projects['all'] = $this->lang->project->all;
foreach($this->lang->action->search->label as $action => $name)
{
if($action) $this->lang->action->search->label[$action] .= " [ $action ]";
}
$this->config->company->dynamic->search['actionURL'] = $this->createLink('company', 'dynamic', "browseType=bysearch&param=myQueryID");
$this->config->company->dynamic->search['queryID'] = $queryID;
$this->config->company->dynamic->search['params']['action']['values'] = $this->lang->action->search->label;
if($this->config->vision == 'rnd') $this->config->company->dynamic->search['params']['product']['values'] = $products;
$this->config->company->dynamic->search['params']['project']['values'] = $projects;
$this->config->company->dynamic->search['params']['execution']['values'] = $executions;
$this->config->company->dynamic->search['params']['actor']['values'] = $accountPairs;
$this->loadModel('search')->setSearchParams($this->config->company->dynamic->search);
/* 根据日期补充动态数据。*/
/* Supplement action by date.*/
$dateGroups = $this->action->buildDateGroup($actions, $direction, $orderBy);
if(empty($recTotal)) $recTotal = count($dateGroups) < 2 ? count($dateGroups, 1) - count($dateGroups) : $this->action->getDynamicCount();
/* Assign. */
if(empty($recTotal)) $recTotal = !(empty($date) && $browseType == 'all') ? array_sum(array_map('count', $dateGroups)) : $this->action->getDynamicCount();
/* Assign.*/
$this->view->title = $this->lang->company->common . $this->lang->colon . $this->lang->company->dynamic;
$this->view->recTotal = $recTotal;
$this->view->browseType = $browseType;
$this->view->account = $account;
$this->view->accountPairs = $accountPairs;
$this->view->productID = $productID;
$this->view->projectID = $projectID;
$this->view->executionID = $executionID;
+163
View File
@@ -11,4 +11,167 @@ declare(strict_types=1);
*/
class companyZen extends company
{
/**
* 将当前的URI保存到session中。
* Save current uri into session.
*
* @access public
* @return void
*/
public function saveUriIntoSession()
{
$uri = $this->app->getURI(true);
$this->session->set('productList', $uri, 'product');
$this->session->set('productPlanList', $uri, 'product');
$this->session->set('releaseList', $uri, 'product');
$this->session->set('storyList', $uri, 'product');
$this->session->set('projectList', $uri, 'project');
$this->session->set('riskList', $uri, 'project');
$this->session->set('opportunityList', $uri, 'project');
$this->session->set('trainplanList', $uri, 'project');
$this->session->set('taskList', $uri, 'execution');
$this->session->set('buildList', $uri, 'execution');
$this->session->set('bugList', $uri, 'qa');
$this->session->set('caseList', $uri, 'qa');
$this->session->set('testtaskList', $uri, 'qa');
$this->session->set('effortList', $uri, 'my');
$this->session->set('meetingList', $uri, 'my');
$this->session->set('meetingList', $uri, 'project');
$this->session->set('meetingroomList', $uri, 'admin');
}
/**
* 加载所有的搜索模块。
* Load all search module.
*
* @param int $userID
* @param string|int $queryID
* @access public
* @return string
*/
public function loadAllSearchModule(int $userID, string|int $queryID): string
{
return $this->buildDyanmicSearchForm($this->loadProduct(), $this->loadProject(), $this->loadExecution(), $userID, $queryID);
}
/**
* 加载产品搜索模块。
* Load product search module.
*
* @access public
* @return array
*/
public function loadProduct(): array
{
$products = $this->loadModel('product')->getPairs('nocode');
$products = array($this->lang->company->product) + $products;
$this->view->products = $products;
return $products;
}
/**
* 加载项目搜索模块。
* Load project search module.
*
* @access public
* @return array
*/
public function loadProject(): array
{
$projects = $this->loadModel('project')->getPairsByProgram();
$this->view->projects = array($this->lang->company->project) + $projects;;
return $projects;
}
/**
* 加载执行搜索模块。
* Load execution search module.
*
* @access public
* @return array
*/
public function loadExecution(): array
{
$this->app->loadLang('execution');
$executions = $this->loadModel('execution')->getPairs(0, 'all', 'nocode|multiple');
$executionList = $this->execution->getByIdList(array_keys($executions));
foreach($executionList as $execution)
{
if(isset($projects[$execution->project])) $executions[$execution->id] = $projects[$execution->project] . $executions[$execution->id];
}
$executions = array($this->lang->execution->common) + $executions;
$this->view->executions = $executions;
return $executions;
}
/**
* 加载用户模块。
* Load user module.
*
* @access public
* @param int $userID
* @return array
*/
public function loadUserModule(int $userID): array
{
$user = $userID ? $this->loadModel('user')->getById($userID, 'id') : '';
$account = $user ? $user->account : 'all';
$userIdPairs = $this->loadModel('user')->getPairs('noclosed|nodeleted|noletter|useid');
$userIdPairs[''] = $this->lang->company->user;
$this->view->userIdPairs = $userIdPairs;
$accountPairs = $this->user->getPairs('nodeleted|noletter|all');
$accountPairs[''] = '';
$this->view->accountPairs = $accountPairs;
return array($account, $accountPairs);
}
/**
* 构建动态搜索表单。
* Build dynamic search form.
*
* @param array $products
* @param array $projects
* @param array $executions
* @param int $userID
* @param int $queryID
* @access public
* @return string
*/
public function buildDyanmicSearchForm(array $products, array $projects, array $executions, int $userID, int $queryID): string
{
list($account, $accountPairs) = $this->loadUserModule($userID);
$executions[0] = '';
$products[0] = '';
$projects[0] = '';
ksort($executions);
ksort($products);
ksort($projects);
$executions['all'] = $this->lang->execution->allExecutions;
$products['all'] = $this->lang->product->allProduct;
$projects['all'] = $this->lang->project->all;
foreach(array_keys($this->lang->action->search->label) as $action)
{
if($action) $this->lang->action->search->label[$action] .= " [ $action ]";
}
$this->config->company->dynamic->search['actionURL'] = $this->createLink('company', 'dynamic', "browseType=bysearch&param=myQueryID");
$this->config->company->dynamic->search['queryID'] = $queryID;
$this->config->company->dynamic->search['params']['action']['values'] = $this->lang->action->search->label;
if($this->config->vision == 'rnd') $this->config->company->dynamic->search['params']['product']['values'] = $products;
$this->config->company->dynamic->search['params']['project']['values'] = $projects;
$this->config->company->dynamic->search['params']['execution']['values'] = $executions;
$this->config->company->dynamic->search['params']['actor']['values'] = $accountPairs;
$this->loadModel('search')->setSearchParams($this->config->company->dynamic->search);
return $account;
}
}