diff --git a/module/program/control.php b/module/program/control.php index e848ec15c3..d3dacda35e 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -45,7 +45,7 @@ class program extends control $this->program->refreshStats(); // Refresh stats fields of projects. - $programs = $this->programZen->getProgramsByType($status, $orderBy, $param, $pager); + $programs = $this->programZen->getProgramsByType($status, $orderBy, (int)$param, $pager); $PMList = $this->programZen->getPMListByPrograms($programs); /* Build the search form. */ @@ -695,19 +695,18 @@ class program extends control $this->loadModel('user'); $this->session->set('productList', $this->app->getURI(true), 'program'); - if($this->app->viewType == 'mhtml') - { - $productID = $this->product->checkAccess(0, $this->products); - $this->product->setMenu($productID); - } - $this->app->loadClass('pager', true); $pager = new pager($recTotal, $recPerPage, $pageID); /* Process product structure. */ if($this->config->systemMode == 'light' and $orderBy == 'program_asc') $orderBy = 'order_asc'; - $queryID = strtolower($browseType) == 'bysearch' ? $param : 0; - $products = strtolower($browseType) == 'bysearch' ? $this->product->getListBySearch($queryID) : $this->product->getList(); + + $products = $this->product->getList(); + if(strtolower($browseType) == 'bysearch') + { + $programs = $this->program->getListBySearch('id', (int)$param); + array_map(function($product) use($programs, &$products){ if(!isset($programs[$product->program])) unset($products[$product->id]);}, $products); + } $products = $this->programZen->getProductsByBrowseType($browseType, $products); /* Filter the program by browse type. */ $productStats = $this->product->getStats(array_keys($products), $orderBy, $pager); /* The product stats list with program data and product data. */ diff --git a/module/program/js/productview.ui.js b/module/program/js/productview.ui.js index 0db8703ce7..44a7a15420 100644 --- a/module/program/js/productview.ui.js +++ b/module/program/js/productview.ui.js @@ -15,11 +15,7 @@ window.renderCellProductView = function(result, {col, row}) if(row.data.latestReleaseDate === '') return ['']; } - if(col.name == 'totalProjects' && row.data.type !== 'product') - { - return [row.data.totalProjects]; - } - + if(col.name == 'totalProjects' && row.data.type !== 'product') return [row.data.totalProjects]; return result; } @@ -31,12 +27,9 @@ window.iconRenderProductView = function(value, row) return ''; } -window.footerSummary = function(checkedIdList) +window.footerSummary = function(checkedIdList, pageSummary) { - if(!checkedIdList.length) - { - return {html: pageSummary, className: 'text-dark'}; - } + if(!checkedIdList.length) return {html: pageSummary, className: 'text-dark'}; let totalProducts = 0; checkedIdList.forEach(function(id) diff --git a/module/program/model.php b/module/program/model.php index f761b31132..fc7488b0da 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -230,10 +230,12 @@ class programModel extends model * * @param string $orderBy * @param int $queryID + * @param bool $hasProject + * @param object $pager * @access public * @return array */ - public function getListBySearch(string $orderBy = 'id_asc', int $queryID = 0): array + public function getListBySearch(string $orderBy = 'id_asc', int $queryID = 0, bool $hasProject = false, object|null $pager = null): array { if($this->session->programQuery == false) $this->session->set('programQuery', ' 1 = 1'); if($queryID) @@ -268,10 +270,12 @@ class programModel extends model return $this->dao->select('*')->from(TABLE_PROGRAM)->where('deleted')->eq(0) ->andWhere('vision')->eq($this->config->vision) - ->andWhere('type')->eq('program') + ->beginIF(!$hasProject)->andWhere('type')->eq('program')->fi() + ->beginIF($hasProject)->andWhere('type')->in('program,project')->fi() ->beginIF($query)->andWhere($query)->fi() ->beginIF(!$this->app->user->admin)->andWhere('id')->in($objectIdList)->fi() ->orderBy($orderBy) + ->page($pager) ->fetchAll('id'); } diff --git a/module/program/test/model/getlistbysearch.php b/module/program/test/model/getlistbysearch.php index 77850e67a6..e4d9ea8144 100644 --- a/module/program/test/model/getlistbysearch.php +++ b/module/program/test/model/getlistbysearch.php @@ -1,5 +1,22 @@ #!/usr/bin/env php gen(5); @@ -8,7 +25,7 @@ su('admin'); $program = zdTable('project'); $program->id->range('1-20'); $program->name->range('1-20')->prefix('项目集'); -$program->type->range('program'); +$program->type->range('program{17},project{3}'); $program->path->range('1-20')->prefix(',')->postfix(','); $program->grade->range('1'); $program->status->range('wait,doing,suspended,closed'); @@ -26,18 +43,6 @@ $query->form->range('`a:41:{s:9:"fieldname";s:0:"";s:11:"fieldstatus";s:0:"";s:9 $query->sql->range("`(( 1 AND `name` LIKE '%项目集%' ) AND ( 1 AND `status` = 'wait' ))`"); $query->gen(1); -/** - -title=测试 programModel::getListBySearch(); -cid=1 -pid=1 - -按照id倒序查看,所有名称包含项目集并且未开始的第一个项目集 >> 项目集17 -按照id正序查看,所有名称包含项目集并且进行中的第一个项目集 >> 项目集1 -按照id正序查看,符合搜索条件id=1,的第一个项目集 >> 项目集1 - -*/ - global $tester; $programTester = new programTest(); @@ -46,9 +51,17 @@ $sql2 = "(( 1 AND `name` LIKE '%项目集%' ) AND ( 1 AND `status` = 'doing' $programTester->program->app->user->admin = true; -r($programTester->getListBySearchTest('id_desc', 0, $sql1)) && p('17:name') && e('项目集17'); // 按照id倒序查看,所有名称包含项目集并且未开始的第一个项目集 -r($programTester->getListBySearchTest('id_asc', 0, $sql2)) && p('2:name') && e('项目集2'); // 按照id正序查看,所有名称包含项目集并且进行中的第一个项目集 -r($programTester->getListBySearchTest('id_asc', 1)) && p('1:name') && e('项目集1'); // 按照id正序查看,符合搜索条件id=1,的第一个项目集 +r($programTester->getListBySearchTest('id_desc', 0, $sql1)) && p('17:name') && e('项目集17'); // 按照id倒序查看,所有名称包含项目集并且未开始的第一个项目集 +r($programTester->getListBySearchTest('id_asc', 0, $sql2)) && p('2:name') && e('项目集2'); // 按照id正序查看,所有名称包含项目集并且进行中的第一个项目集 +r($programTester->getListBySearchTest('id_asc', 1)) && p('1:name') && e('项目集1'); // 按照id正序查看,符合搜索条件id=1,的第一个项目集 +r($programTester->getListBySearchTest('id_asc', 0, $sql2, true)) && p('18:name') && e('项目集18'); // 按照id正序查看,所有名称包含项目集的项目类型的数据。 + +$programTester->program->app->moduleName = 'program'; +$programTester->program->app->methodName = 'browse'; +$programTester->program->app->loadClass('pager', true); +$pager = new pager(0, 2, 1); +r(count($programTester->getListBySearchTest('id_asc', 0, $sql2, true, $pager))) && p() && e('2'); // 加分页参数后,检查结果条目数。 +r($pager->recTotal) && p() && e('5'); // 检查分页总条目。 $programTester->program->app->rawMethod = 'browse'; $programTester->program->app->user->admin = false; diff --git a/module/program/test/program.class.php b/module/program/test/program.class.php index df9e1e8f10..2d1482c4d1 100644 --- a/module/program/test/program.class.php +++ b/module/program/test/program.class.php @@ -24,11 +24,11 @@ class programTest * @access public * @return array */ - public function getListBySearchTest($orderBy = 'id_asc', $queryID = 0, $sql = '') + public function getListBySearchTest($orderBy = 'id_asc', $queryID = 0, $sql = '', $hasProject = false, $pager = null) { if(!empty($sql)) $_SESSION['programQuery'] = $sql; - return $this->program->getListBySearch($orderBy, $queryID); + return $this->program->getListBySearch($orderBy, $queryID, $hasProject, $pager); } /** diff --git a/module/program/ui/browse.html.php b/module/program/ui/browse.html.php index 73a4801230..eae4e9a020 100644 --- a/module/program/ui/browse.html.php +++ b/module/program/ui/browse.html.php @@ -194,7 +194,6 @@ dtable set::onRenderCell(jsRaw('window.renderCell')), set::orderBy($orderBy), set::sortLink(createLink('program', 'browse', "status={$status}&orderBy={name}_{sortType}&recTotal={$pager->recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}¶m={$param}")), - $status == 'bySearch' ? set::footer(false) : null, set::footToolbar(array ( 'type' => 'btn-group', diff --git a/module/program/ui/productview.html.php b/module/program/ui/productview.html.php index 28f98ff5bf..dd6e278c00 100644 --- a/module/program/ui/productview.html.php +++ b/module/program/ui/productview.html.php @@ -246,6 +246,9 @@ $fnGenerateCols = function() use ($canBatchEdit) return $cols; }; +$pageSummary = sprintf($lang->product->lineSummary, $linesCount, count($productStats)); +jsVar('checkedSummary', $lang->program->checkedProducts); + /* ZIN: layout. */ featureBar ( @@ -283,13 +286,10 @@ dtable ) : null ) )), - set::checkInfo(jsRaw("function(checkedIDList){ return window.footerSummary(checkedIDList);}")), + set::checkInfo(jsRaw("function(checkedIDList){ return window.footerSummary(checkedIDList, '{$pageSummary}');}")), set::emptyTip($lang->product->noProduct), set::createTip($lang->product->create), set::createLink(hasPriv('product', 'create') ? createLink('product', 'create') : null) ); -jsVar('pageSummary', sprintf($lang->product->lineSummary, $linesCount, count($productStats))); -jsVar('checkedSummary', $lang->program->checkedProducts); - render(); diff --git a/module/program/zen.php b/module/program/zen.php index 5a405a8b38..6cfadbfbaa 100644 --- a/module/program/zen.php +++ b/module/program/zen.php @@ -120,13 +120,18 @@ class programZen extends program $params = array(); $this->view->summary = ''; - if(strtolower($status) == 'bysearch') return $this->program->getListBySearch($orderBy, $param); + if(strtolower($status) == 'bysearch') + { + $programs = $this->program->getListBySearch($orderBy, $param, true, $pager); + } + else + { + /* Get top programs and projects. */ + $topObjects = $this->program->getList($status == 'unclosed' ? 'doing,suspended,wait' : $status, $orderBy, 'top', array(), $pager); + if(!$topObjects) $topObjects = array(0); - /* Get top programs and projects. */ - $topObjects = $this->program->getList($status == 'unclosed' ? 'doing,suspended,wait' : $status, $orderBy, 'top', array(), $pager); - if(!$topObjects) $topObjects = array(0); - - $programs = $this->program->getList($status, $orderBy, 'child', array_keys($topObjects)); + $programs = $this->program->getList($status, $orderBy, 'child', array_keys($topObjects)); + } /* Get summary. */ $topCount = $indCount = 0;