From 129307a891f6e9266112a2abffeb4b36a73d10ea Mon Sep 17 00:00:00 2001 From: chaideqing Date: Wed, 15 Nov 2023 15:25:09 +0800 Subject: [PATCH] * Merge module-execution to Merge184. --- module/execution/control.php | 43 +++++++++++++++++++++++++----- module/execution/model.php | 38 +++++++++++++++++++++----- module/execution/view/all.html.php | 2 +- 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/module/execution/control.php b/module/execution/control.php index efaeec33a1..dfa824c32b 100644 --- a/module/execution/control.php +++ b/module/execution/control.php @@ -1546,6 +1546,7 @@ class execution extends control /* Execution not found to prevent searching for. */ if(!isset($this->executions[$execution->id])) $this->executions = $this->execution->getPairs($execution->project, 'all', 'nocode'); + if(!$this->loadModel('common')->checkPrivByObject('execution', $executionID)) return $this->execution->accessDenied(); $execution->projectInfo = $this->loadModel('project')->getByID($execution->project); $programList = array_filter(explode(',', $execution->projectInfo->path)); @@ -1639,6 +1640,7 @@ class execution extends control */ public function taskKanban(int $executionID, string $browseType = 'all', string $orderBy = 'order_asc', string $groupBy = '') { + if(!$this->loadModel('common')->checkPrivByObject('execution', $executionID)) return $this->execution->accessDenied(); /* Load model and language. */ $this->app->loadLang('task'); $this->app->loadLang('bug'); @@ -2493,6 +2495,29 @@ class execution extends control */ public function ajaxGetDropMenu(int $executionID, string $module, string $method, string $extra = '') { + $this->view->link = $this->executionZen->getLink($module, $method, $extra); + $this->view->module = $module; + $this->view->method = $method; + $this->view->executionID = $executionID; + $this->view->extra = $extra; + + $cacheProjectsKey = $this->config->cacheKeys->execution->ajaxGetDropMenuProjects; + $cacheExecutionsKey = $this->config->cacheKeys->execution->ajaxGetDropMenuExecutions; + + if(helper::isCacheEnabled()) + { + $projects = $this->cache->get($cacheProjectsKey); + $projectExecutions = $this->cache->get($cacheExecutionsKey); + + if(!empty($projects) && !empty($projectExecutions)) + { + $this->view->projects = $projects; + $this->view->projectExecutions = $projectExecutions; + $this->display(); + return; + } + } + $projects = $this->loadModel('program')->getProjectList(0, 'all', 0, 'order_asc', '', true); /* 获取所有项目的列表。*/ $executionGroups = $this->dao->select('*')->from(TABLE_EXECUTION) /* 按照项目分组,获取有权限访问的执行列表。*/ ->where('deleted')->eq('0') @@ -2540,10 +2565,12 @@ class execution extends control $projectExecutions[$execution->project][] = $execution; } - $this->view->link = $this->executionZen->getLink($module, $method, $extra); - $this->view->module = $module; - $this->view->method = $method; - $this->view->extra = $extra; + if($this->config->cache->enable) + { + $this->cache->set($cacheProjectsKey, $projectPairs); + $this->cache->set($cacheExecutionsKey, $projectExecutions); + } + $this->view->projects = $projectPairs; /* 项目ID为索引,项目名称为值的数组 [projectID => projectName]。 */ $this->view->projectExecutions = $projectExecutions; /* 项目对应的执行列表 [projectID => execution]。*/ $this->view->executionID = $executionID; @@ -2667,12 +2694,12 @@ class execution extends control * @access public * @return void */ - public function all(string $status = 'undone', string $orderBy = 'order_asc', int $productID = 0, string $param = '', int $recTotal = 0, int $recPerPage = 100, int $pageID = 1) + public function all(string $status = 'undone', string $orderBy = 'order_asc', int $productID = 0, string $param = '', int $recTotal = 0, int $recPerPage = 20, int $pageID = 1) { $this->app->loadLang('my'); - $this->app->loadLang('product'); $this->app->loadLang('stage'); $this->app->loadLang('programplan'); + $this->loadModel('product'); $this->loadModel('datatable'); $from = $this->app->tab; @@ -2688,6 +2715,8 @@ class execution extends control $this->app->loadClass('pager', true); $pager = new pager($recTotal, $recPerPage, $pageID); + $this->loadModel('program')->refreshStats(); // Refresh stats fields of projects. + $queryID = ($status == 'bySearch') ? (int)$param : 0; $actionURL = $this->createLink('execution', 'all', "status=bySearch&orderBy=$orderBy&productID=$productID¶m=myQueryID"); $this->execution->buildSearchForm($queryID, $actionURL); @@ -2930,7 +2959,7 @@ class execution extends control public function treeStory(int $storyID, int $version = 0) { $story = $this->loadModel('story')->getById($storyID, $version, true); - $product = $this->dao->findById($story->product)->from(TABLE_PRODUCT)->fields('name,id,`type`,shadow')->fetch(); + $product = $this->dao->findById($story->product)->from(TABLE_PRODUCT)->fields('name, id, `type`, shadow')->fetch(); $this->view->story = $story; $this->view->product = $product; diff --git a/module/execution/model.php b/module/execution/model.php index 3cdbc6fc92..40cab10468 100755 --- a/module/execution/model.php +++ b/module/execution/model.php @@ -24,11 +24,7 @@ class executionModel extends model */ public function checkPriv(int $executionID): bool { - if(empty($executionID)) return false; - - /* If is admin, return true. */ - if($this->app->user->admin) return true; - return (strpos(",{$this->app->user->view->sprints},", ",{$executionID},") !== false); + return !empty($executionID) && ($this->app->user->admin || (strpos(",{$this->app->user->view->sprints},", ",{$executionID},") !== false)); } /** @@ -1463,6 +1459,35 @@ class executionModel extends model ->fetchPairs('id', 'id'); } + /** + * Get execution count. + * + * @param int $projectID + * @param string $browseType all|undone|wait|doing|suspended|closed|involved|review + * @access public + * @return int + */ + public function getExecutionCounts(int $projectID = 0, string $browseType = 'all'): int + { + $executions = $this->dao->select('t1.*,t2.name projectName, t2.model as projectModel')->from(TABLE_EXECUTION)->alias('t1') + ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id') + ->where('t1.type')->in('sprint,stage,kanban') + ->andWhere('t1.deleted')->eq('0') + ->andWhere('t1.vision')->eq($this->config->vision) + ->andWhere('t1.multiple')->eq('1') + ->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->sprints)->fi() + ->beginIF($projectID)->andWhere('t1.project')->eq($projectID)->fi() + ->beginIF(!in_array($browseType, array('all', 'undone', 'involved', 'review', 'bySearch')))->andWhere('t1.status')->eq($browseType)->fi() + ->beginIF($browseType == 'undone')->andWhere('t1.status')->notIN('done,closed')->fi() + ->beginIF($browseType == 'review') + ->andWhere("FIND_IN_SET('{$this->app->user->account}', t1.reviewers)") + ->andWhere('t1.reviewStatus')->eq('doing') + ->fi() + ->fetchAll('id'); + + return count($executions); + } + /** * 获取执行数据。 * Get execution stat data. @@ -1573,7 +1598,7 @@ class executionModel extends model ->andWhere('t1.multiple')->eq('1') ->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->sprints)->fi() ->beginIF(!empty($executionQuery))->andWhere($executionQuery)->fi() - ->beginIF($productID)->andWhere('t3.product')->eq((int)$productID)->fi() + ->beginIF($productID)->andWhere('t3.product')->eq($productID)->fi() ->beginIF($projectID)->andWhere('t1.project')->eq($projectID)->fi() ->beginIF(!in_array($browseType, array('all', 'undone', 'involved', 'review', 'bySearch')))->andWhere('t1.status')->eq($browseType)->fi() ->beginIF($browseType == 'undone')->andWhere('t1.status')->notIN('done,closed')->fi() @@ -2259,6 +2284,7 @@ class executionModel extends model $this->config->product->search['params']['plan']['values'] = $planPairs; $this->config->product->search['params']['module']['values'] = $modules; $this->config->product->search['params']['status'] = array('operator' => '=', 'control' => 'select', 'values' => $this->lang->story->statusList); + $this->config->product->search['params']['stage']['values'] = array('' => '') + $this->lang->story->stageList; if($productType == 'normal') { unset($this->config->product->search['fields']['branch']); diff --git a/module/execution/view/all.html.php b/module/execution/view/all.html.php index f5906f02d3..7553ce5af9 100644 --- a/module/execution/view/all.html.php +++ b/module/execution/view/all.html.php @@ -37,7 +37,7 @@ js::set('isCNLang', !$this->loadModel('common')->checkNotCN());
- product->allProduct;?> + product->allProduct;?>