From f51375fe0391cec0b7e8f08f00abd5349f4ed042 Mon Sep 17 00:00:00 2001 From: liugang Date: Fri, 22 Sep 2023 10:26:05 +0800 Subject: [PATCH] * testtask: refactor the browse method. --- module/testtask/control.php | 61 +++++++++++++++---------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/module/testtask/control.php b/module/testtask/control.php index c6be5c0a91..647e02d2b0 100644 --- a/module/testtask/control.php +++ b/module/testtask/control.php @@ -78,57 +78,46 @@ class testtask extends control */ public function browse(int $productID = 0, string $branch = '', string $type = 'local,totalStatus', string $orderBy = 'id_desc', int $recTotal = 0, int $recPerPage = 20, int $pageID = 1, string $beginTime = '', string $endTime = '') { + /* 检查是否有权限访问测试单所属产品。*/ + /* Check if user have permission to access the product to which the testtask belongs. */ + $productID = $this->loadModel('product')->checkAccess($productID, $this->products); + + /* 保存部分内容到 session 中供后面使用。*/ /* Save session. */ $uri = $this->app->getURI(true); $this->session->set('testtaskList', $uri, 'qa'); $this->session->set('reportList', $uri, 'qa'); $this->session->set('buildList', $uri, 'execution'); - - /* Set menu. */ - $productID = $this->loadModel('product')->checkAccess($productID, $this->products); - $this->loadModel('qa')->setMenu($productID, $branch); $this->session->set('branch', $branch, 'qa'); - /* Load pager. */ + $this->loadModel('qa')->setMenu($productID, $branch); + + /* 预处理部分变量供查询使用。*/ + /* Prepare variables for query. */ $this->app->loadClass('pager', $static = true); - $pager = pager::init($recTotal, $recPerPage, $pageID); - - /* Append id for second sort. */ - $sort = common::appendOrder($orderBy); - - /* Get tasks. */ + $pager = pager::init($recTotal, $recPerPage, $pageID); $beginTime = $beginTime ? date('Y-m-d', strtotime($beginTime)) : ''; $endTime = $endTime ? date('Y-m-d', strtotime($endTime)) : ''; + $sort = common::appendOrder($orderBy); $product = $this->product->getById($productID); if($product->type == 'normal') $branch = 'all'; + + /* 从数据库中查询符合条件的测试单。*/ + /* Query the testtasks from the database. */ $testtasks = $this->testtask->getProductTasks($productID, $branch, $type, $beginTime, $endTime, $sort, $pager); - /* 获取不同状态测试单的数量,用于列表底部统计信息展示。 */ - $waitCount = 0; - $testingCount = 0; - $blockedCount = 0; - $doneCount = 0; - foreach($testtasks as $testtask) - { - if($testtask->status == 'wait') $waitCount ++; - if($testtask->status == 'doing') $testingCount ++; - if($testtask->status == 'blocked') $blockedCount ++; - if($testtask->status == 'done') $doneCount ++; - if($testtask->build == 'trunk' || empty($testtask->buildName)) $testtask->buildName = $this->lang->trunk; - } + $this->testtaskZen->prepareSummaryForBrowse($testtasks); - $this->view->title = $product->name . $this->lang->colon . $this->lang->testtask->common; - $this->view->users = $this->loadModel('user')->getPairs('noclosed|noletter'); - $this->view->allSummary = sprintf($this->lang->testtask->allSummary, count($testtasks), $waitCount, $testingCount, $blockedCount, $doneCount); - $this->view->pageSummary = sprintf($this->lang->testtask->pageSummary, count($testtasks)); - $this->view->tasks = $testtasks; - $this->view->product = $product; - $this->view->branch = $branch; - $this->view->type = $type; - $this->view->orderBy = $orderBy; - $this->view->pager = $pager; - $this->view->beginTime = $beginTime; - $this->view->endTime = $endTime; + $this->view->title = $product->name . $this->lang->colon . $this->lang->testtask->common; + $this->view->users = $this->loadModel('user')->getPairs('noclosed|noletter'); + $this->view->tasks = $testtasks; + $this->view->product = $product; + $this->view->branch = $branch; + $this->view->type = $type; + $this->view->orderBy = $orderBy; + $this->view->pager = $pager; + $this->view->beginTime = $beginTime; + $this->view->endTime = $endTime; $this->display(); }