* Rewrite program browse page.
This commit is contained in:
@@ -34,57 +34,18 @@ class program extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function browse($status = 'unclosed', $orderBy = 'order_asc', $recTotal = 0, $recPerPage = 10, $pageID = 1, $param = 0)
|
||||
public function browse(string $status = 'unclosed', string $orderBy = 'order_asc', int $recTotal = 0, int $recPerPage = 10, int $pageID = 1, int $param = 0)
|
||||
{
|
||||
if(common::hasPriv('program', 'create')) $this->lang->pageActions = html::a($this->createLink('program', 'create'), "<i class='icon icon-plus'></i> " . $this->lang->program->create, '', "class='btn btn-primary create-program-btn'");
|
||||
|
||||
$this->session->set('programList', $this->app->getURI(true), 'program');
|
||||
$this->session->set('projectList', $this->app->getURI(true), 'program');
|
||||
$this->session->set('createProjectLocate', $this->app->getURI(true), 'program');
|
||||
$uri = $this->app->getURI(true);
|
||||
$this->session->set('programList', $uri, 'program');
|
||||
$this->session->set('projectList', $uri, 'program');
|
||||
$this->session->set('createProjectLocate', $uri, 'program');
|
||||
|
||||
$this->app->loadClass('pager', $static = true);
|
||||
$pager = new pager($recTotal, $recPerPage, $pageID);
|
||||
|
||||
$programType = $this->cookie->programType ? $this->cookie->programType : 'bylist';
|
||||
|
||||
if($programType === 'bygrid')
|
||||
{
|
||||
$programs = $this->program->getProgramStats($status, 20, $orderBy);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(strtolower($status) == 'bysearch')
|
||||
{
|
||||
$queryID = (int)$param;
|
||||
$programs = $this->program->getListBySearch($orderBy, $queryID);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get top programs and projects. */
|
||||
$topObjects = $this->program->getList($status == 'unclosed' ? 'doing,suspended,wait' : $status, $orderBy, 'top', array());
|
||||
if(!$topObjects) $topObjects = array(0);
|
||||
$programs = $this->program->getList($status, $orderBy, 'child', array_keys($topObjects));
|
||||
|
||||
/* Get summary. */
|
||||
$topCount = $indCount = 0;
|
||||
foreach($programs as $program)
|
||||
{
|
||||
if($program->type == 'program' and $program->parent == 0) $topCount ++;
|
||||
if($program->type == 'project' and $program->parent == 0) $indCount ++;
|
||||
}
|
||||
$summary = sprintf($this->lang->program->summary, $topCount, $indCount);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get PM id list. */
|
||||
$accounts = array();
|
||||
$hasProject = false;
|
||||
foreach($programs as $program)
|
||||
{
|
||||
if(!empty($program->PM) and !in_array($program->PM, $accounts)) $accounts[] = $program->PM;
|
||||
if($hasProject === false and $program->type != 'program') $hasProject = true;
|
||||
}
|
||||
$PMList = $this->loadModel('user')->getListByAccounts($accounts, 'account');
|
||||
$programs = $this->programZen->getProgramsByType($status, $orderBy, $param, $pager);
|
||||
$PMList = $this->programZen->getPMListByPrograms($programs);
|
||||
|
||||
/* Build the search form. */
|
||||
$actionURL = $this->createLink('program', 'browse', "status=bySearch&orderBy={$orderBy}&recTotal={$recTotal}&recPerPage={$recPerPage}&pageID={$pageID}¶m=myQueryID");
|
||||
@@ -95,16 +56,11 @@ class program extends control
|
||||
$this->view->programs = $programs;
|
||||
$this->view->status = $status;
|
||||
$this->view->orderBy = $orderBy;
|
||||
$this->view->summary = isset($summary) ? $summary : '';
|
||||
$this->view->pager = $pager;
|
||||
$this->view->users = $this->user->getPairs('noletter');
|
||||
$this->view->userIdPairs = $this->user->getPairs('noletter|showid');
|
||||
$this->view->users = $this->loadModel('user')->getPairs('noletter');
|
||||
$this->view->usersAvatar = $this->user->getAvatarPairs('');
|
||||
$this->view->programType = $programType;
|
||||
$this->view->PMList = $PMList;
|
||||
$this->view->progressList = $this->program->getProgressList();
|
||||
$this->view->hasProject = $hasProject;
|
||||
$this->view->param = $param;
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -213,29 +213,23 @@ class programModel extends model
|
||||
/**
|
||||
* Get program list by search.
|
||||
*
|
||||
* @param string $orderBy
|
||||
* @param int $queryID
|
||||
* @param string $orderBy
|
||||
* @param int $queryID
|
||||
* @access public
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function getListBySearch($orderBy = 'id_asc', $queryID = 0)
|
||||
public function getListBySearch(string $orderBy = 'id_asc', int $queryID = 0): array
|
||||
{
|
||||
if($this->session->programQuery == false) $this->session->set('programQuery', ' 1 = 1');
|
||||
if($queryID)
|
||||
{
|
||||
$this->session->set('programQuery', ' 1 = 1');
|
||||
$query = $this->loadModel('search')->getQuery($queryID);
|
||||
if($query)
|
||||
{
|
||||
$this->session->set('programQuery', $query->sql);
|
||||
$this->session->set('programForm', $query->form);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->session->set('programQuery', ' 1 = 1');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->session->programQuery == false) $this->session->set('programQuery', ' 1 = 1');
|
||||
}
|
||||
$query = $this->session->programQuery;
|
||||
|
||||
@@ -248,16 +242,16 @@ class programModel extends model
|
||||
|
||||
if($this->app->rawMethod == 'browse')
|
||||
{
|
||||
$pathList = $this->dao->select('id,path')->from(TABLE_PROJECT)->where('id')->in($objectIdList)->andWhere('deleted')->eq(0)->fetchPairs('id');
|
||||
$pathList = $this->dao->select('id,path')->from(TABLE_PROJECT)->where('id')->in($objectIdList)->andWhere('deleted')->eq(0)->fetchPairs('id', 'path');
|
||||
foreach($pathList as $path)
|
||||
{
|
||||
foreach(explode(',', trim($path, ',')) as $pathID) $objectIdList[$pathID] = $pathID;
|
||||
}
|
||||
}
|
||||
$objectIdList = array_unique($objectIdList);
|
||||
}
|
||||
|
||||
return $this->dao->select('*')->from(TABLE_PROGRAM)
|
||||
->where('deleted')->eq(0)
|
||||
return $this->dao->select('*')->from(TABLE_PROGRAM)->where('deleted')->eq(0)
|
||||
->andWhere('vision')->eq($this->config->vision)
|
||||
->andWhere('type')->eq('program')
|
||||
->beginIF($query)->andWhere($query)->fi()
|
||||
|
||||
@@ -15,7 +15,7 @@ $program->status->range('wait,doing,suspended,closed');
|
||||
$program->openedBy->range('admin,user1');
|
||||
$program->begin->range('20220112 000000:0')->type('timestamp')->format('YY/MM/DD');
|
||||
$program->end->range('20220212 000000:0')->type('timestamp')->format('YY/MM/DD');
|
||||
$program->gen(20);
|
||||
$program->gen(20)->fixPath();
|
||||
|
||||
$query = zdTable('userquery');
|
||||
$query->id->range('1');
|
||||
@@ -44,6 +44,17 @@ $programTester = new programTest();
|
||||
$sql1 = "(( 1 AND `name` LIKE '%项目集%' ) AND ( 1 AND `status` = 'wait' ))";
|
||||
$sql2 = "(( 1 AND `name` LIKE '%项目集%' ) AND ( 1 AND `status` = 'doing' ))";
|
||||
|
||||
r($programTester->getListBySearchTest('id_desc', 0, $sql)) && p('17:name') && e('项目集17'); // 按照id倒序查看,所有名称包含项目集并且未开始的第一个项目集
|
||||
r($programTester->getListBySearchTest('id_asc', 0, $sql)) && p('1:name') && e('项目集1'); // 按照id正序查看,所有名称包含项目集并且进行中的第一个项目集
|
||||
r($programTester->getListBySearchTest('id_asc', 1)) && p('1:name') && e('项目集1'); // 按照id正序查看,符合搜索条件id=1,的第一个项目集
|
||||
$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,的第一个项目集
|
||||
|
||||
$programTester->program->app->rawMethod = 'browse';
|
||||
$programTester->program->app->user->admin = false;
|
||||
$programTester->program->app->user->view->programs = ',1,2,3,4,5';
|
||||
$programTester->program->app->user->view->projects = ',19,20';
|
||||
|
||||
r($programTester->getListBySearchTest('id_desc', 0, $sql1)) && p('1:name') && e('项目集1'); // 按照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,的第一个项目集
|
||||
|
||||
+60
-1
@@ -26,4 +26,63 @@ class programZen extends program
|
||||
->add('lastEditedDate', helper::now())
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据条件获取项目集。
|
||||
* Get programs by type.
|
||||
*
|
||||
* @param string $status
|
||||
* @param string $orderBy
|
||||
* @param int $param
|
||||
* @param object|null $pager
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function getProgramsByType(string $status, string $orderBy, int $param = 0, object|null $pager = null): array
|
||||
{
|
||||
$status = strtolower($status);
|
||||
$params = array();
|
||||
$this->view->summary = '';
|
||||
|
||||
if(strtolower($status) == 'bysearch') return $this->program->getListBySearch($orderBy, $param);
|
||||
|
||||
/* 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));
|
||||
|
||||
/* Get summary. */
|
||||
$topCount = $indCount = 0;
|
||||
foreach($programs as $program)
|
||||
{
|
||||
if($program->type == 'program' and $program->parent == 0) $topCount ++;
|
||||
if($program->type == 'project' and $program->parent == 0) $indCount ++;
|
||||
}
|
||||
$this->view->summary = sprintf($this->lang->program->summary, $topCount, $indCount);
|
||||
|
||||
return $programs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据项目集,获取产品经理列表。
|
||||
* Get PM list by programs.
|
||||
*
|
||||
* @param array $programs
|
||||
* @access protected
|
||||
* @return array
|
||||
*/
|
||||
protected function getPMListByPrograms(array $programs): array
|
||||
{
|
||||
$accounts = array();
|
||||
$hasProject = false;
|
||||
foreach($programs as $program)
|
||||
{
|
||||
if(!empty($program->PM) and !in_array($program->PM, $accounts)) $accounts[] = $program->PM;
|
||||
if($hasProject === false and $program->type != 'program') $hasProject = true;
|
||||
}
|
||||
$this->view->hasProject = $hasProject;
|
||||
|
||||
return $this->loadModel('user')->getListByAccounts($accounts, 'account');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class userModel extends model
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getListByAccounts($accounts = array(), $keyField = 'id')
|
||||
public function getListByAccounts(array $accounts = array(), string $keyField = 'id'): array
|
||||
{
|
||||
if(empty($accounts)) return array();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user