diff --git a/module/program/control.php b/module/program/control.php index ce2b19f33b..e265a22462 100644 --- a/module/program/control.php +++ b/module/program/control.php @@ -52,9 +52,9 @@ class program extends control } else { - /* Get pager for top program and projects whithout program. */ - $this->program->getList($status, $orderBy, $pager, 'top'); - $programs = $this->program->getList($status, $orderBy); + /* Get top programs and projects. */ + $topObjects = $this->program->getList($status, $orderBy, $pager, 'top'); + $programs = $this->program->getList($status, $orderBy, NULL, 'child', array_keys($topObjects)); /* Get summary. */ $topCount = $indCount = 0; diff --git a/module/program/model.php b/module/program/model.php index 083d47c721..fdec2de028 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -131,12 +131,12 @@ class programModel extends model * @param string $orderBy * @param object $pager * @param string $type top|child + * @param array $topIdList * @access public * @return array */ - public function getList($status = 'all', $orderBy = 'id_asc', $pager = NULL, $type = '') + public function getList($status = 'all', $orderBy = 'id_asc', $pager = NULL, $type = '', $topIdList = '') { - $objectIdList = array(); if(!$this->app->user->admin) { $objectIdList = trim($this->app->user->view->programs, ',') . ',' . trim($this->app->user->view->projects, ','); @@ -145,9 +145,20 @@ 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'); + + $objectIdList = array(); foreach($pathList as $path) { + if($type == 'child' and !empty($topIdList)) + { + $topID = $this->getTopByPath($path); + if(!in_array($topID, $topIdList)) continue; + } + foreach(explode(',', trim($path, ',')) as $pathID) $objectIdList[$pathID] = $pathID; } }