From c8288bf7e18fa75648a078e5263625c7ff5dd158 Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Mon, 9 Jun 2014 00:08:46 +0700 Subject: [PATCH] Project builds pagination improvements --- PHPCI/Controller/ProjectController.php | 17 ++++++++++++----- PHPCI/View/Project/view.phtml | 2 -- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 76f794c7..6de6af1a 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -56,13 +56,20 @@ class ProjectController extends \PHPCI\Controller throw new NotFoundException('Project with id: ' . $projectId . ' not found'); } - $page = $this->getParam('p', 1); - $builds = $this->getLatestBuildsHtml($projectId, (($page - 1) * 10)); + $per_page = 10; + $page = $this->getParam('p', 1); + $builds = $this->getLatestBuildsHtml($projectId, (($page - 1) * $per_page)); + $pages = ceil($builds[1] / $per_page); - $this->view->builds = $builds[0]; - $this->view->total = $builds[1]; + if ($page > $pages) { + throw new NotFoundException('Page with number: ' . $page . ' not found'); + } + + $this->view->builds = $builds[0]; + $this->view->total = $builds[1]; $this->view->project = $project; - $this->view->page = $page; + $this->view->page = $page; + $this->view->pages = $pages; $this->config->set('page_title', $project->getTitle()); diff --git a/PHPCI/View/Project/view.phtml b/PHPCI/View/Project/view.phtml index 08781dd3..30fd24aa 100644 --- a/PHPCI/View/Project/view.phtml +++ b/PHPCI/View/Project/view.phtml @@ -82,8 +82,6 @@