diff --git a/PHPCI/Controller/IndexController.php b/PHPCI/Controller/IndexController.php index 6f9d9c52..c185d2f3 100644 --- a/PHPCI/Controller/IndexController.php +++ b/PHPCI/Controller/IndexController.php @@ -31,8 +31,14 @@ class IndexController extends \PHPCI\Controller public function index() { $projects = $this->_projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC')); + $summary = $this->_buildStore->getBuildSummary(); + + $summaryView = new b8\View('BuildsTable'); + $summaryView->builds = $summary['items']; + $this->view->builds = $this->getLatestBuildsHtml(); $this->view->projects = $projects['items']; + $this->view->summary = $summaryView->render(); return $this->view->render(); } @@ -50,7 +56,7 @@ class IndexController extends \PHPCI\Controller */ protected function getLatestBuildsHtml() { - $builds = $this->_buildStore->getWhere(array(), 10, 0, array(), array('id' => 'DESC')); + $builds = $this->_buildStore->getWhere(array(), 5, 0, array(), array('id' => 'DESC')); $view = new b8\View('BuildsTable'); $view->builds = $builds['items']; diff --git a/PHPCI/Store/BuildStore.php b/PHPCI/Store/BuildStore.php index 5355fac2..03b1ad28 100644 --- a/PHPCI/Store/BuildStore.php +++ b/PHPCI/Store/BuildStore.php @@ -19,5 +19,32 @@ use PHPCI\Store\Base\BuildStoreBase; */ class BuildStore extends BuildStoreBase { - // This class has been left blank so that you can modify it - changes in this file will not be overwritten. + public function getBuildSummary() + { + $query = 'SELECT COUNT(*) AS cnt FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC'; + $stmt = \b8\Database::getConnection('read')->prepare($query); + + if ($stmt->execute()) { + $res = $stmt->fetch(\PDO::FETCH_ASSOC); + $count = (int)$res['cnt']; + } else { + $count = 0; + } + + $query = 'SELECT * FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC'; + $stmt = \b8\Database::getConnection('read')->prepare($query); + + if ($stmt->execute()) { + $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); + + $map = function ($item) { + return new \PHPCI\Model\Build($item); + }; + $rtn = array_map($map, $res); + + return array('items' => $rtn, 'count' => $count); + } else { + return array('items' => array(), 'count' => 0); + } + } } diff --git a/PHPCI/View/Index/index.phtml b/PHPCI/View/Index/index.phtml index 4a53ec33..887b46d3 100644 --- a/PHPCI/View/Index/index.phtml +++ b/PHPCI/View/Index/index.phtml @@ -40,6 +40,24 @@
| ID | +Project | +Commit | +Branch | +Status | ++ |
|---|