From 8685f2ac36eb6503a5199c915b92c516ee185aea Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Thu, 24 Apr 2014 16:25:24 +0100 Subject: [PATCH] Adding per-page titles throughout PHPCI, fixes #371 --- PHPCI/Application.php | 6 ++++++ PHPCI/Controller/BuildController.php | 3 +++ PHPCI/Controller/HomeController.php | 2 ++ PHPCI/Controller/PluginController.php | 2 ++ PHPCI/Controller/ProjectController.php | 7 +++++++ PHPCI/Controller/UserController.php | 8 ++++++++ PHPCI/View/layout.phtml | 2 +- 7 files changed, 29 insertions(+), 1 deletion(-) diff --git a/PHPCI/Application.php b/PHPCI/Application.php index 5c9647d2..ecc71ad5 100644 --- a/PHPCI/Application.php +++ b/PHPCI/Application.php @@ -73,6 +73,12 @@ class Application extends b8\Application if (View::exists('layout') && $this->response->hasLayout()) { $view = new View('layout'); + $pageTitle = $this->config->get('page_title', null); + + if (!is_null($pageTitle)) { + $view->title = $pageTitle; + } + $view->content = $this->response->getContent(); $this->response->setContent($view->render()); } diff --git a/PHPCI/Controller/BuildController.php b/PHPCI/Controller/BuildController.php index 032ce118..3ebb8432 100644 --- a/PHPCI/Controller/BuildController.php +++ b/PHPCI/Controller/BuildController.php @@ -40,6 +40,9 @@ class BuildController extends \PHPCI\Controller $this->view->plugins = $this->getUiPlugins(); $this->view->build = $build; $this->view->data = $this->getBuildData($build); + + $title = 'Build #' . $build->getId() . ' - ' . $build->getProjectTitle(); + $this->config->set('page_title', $title); } protected function getUiPlugins() diff --git a/PHPCI/Controller/HomeController.php b/PHPCI/Controller/HomeController.php index 95676efc..b2d4bd6b 100644 --- a/PHPCI/Controller/HomeController.php +++ b/PHPCI/Controller/HomeController.php @@ -56,6 +56,8 @@ class HomeController extends \PHPCI\Controller $this->view->projects = $projects['items']; $this->view->summary = $summaryView->render(); + $this->config->set('page_title', 'Dashboard'); + return $this->view->render(); } diff --git a/PHPCI/Controller/PluginController.php b/PHPCI/Controller/PluginController.php index b7e32ddb..4f51e6c9 100644 --- a/PHPCI/Controller/PluginController.php +++ b/PHPCI/Controller/PluginController.php @@ -75,6 +75,8 @@ class PluginController extends \PHPCI\Controller $this->view->plugins = $pluginInfo->getInstalledPlugins(); + $this->config->set('page_title', 'Plugins'); + return $this->view->render(); } diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 95f8c2cd..42c74a10 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -61,6 +61,8 @@ class ProjectController extends \PHPCI\Controller $this->view->project = $project; $this->view->page = $page; + $this->config->set('page_title', $project->getTitle()); + return $this->view->render(); } @@ -134,6 +136,8 @@ class ProjectController extends \PHPCI\Controller */ public function add() { + $this->config->set('page_title', 'Add Project'); + if (!$_SESSION['user']->getIsAdmin()) { throw new \Exception('You do not have permission to do that.'); } @@ -229,6 +233,9 @@ class ProjectController extends \PHPCI\Controller $method = $this->request->getMethod(); $project = $this->projectStore->getById($projectId); + $this->config->set('page_title', 'Edit: ' . $project->getTitle()); + + if ($method == 'POST') { $values = $this->getParams(); } else { diff --git a/PHPCI/Controller/UserController.php b/PHPCI/Controller/UserController.php index ad41aff6..c8fade0c 100644 --- a/PHPCI/Controller/UserController.php +++ b/PHPCI/Controller/UserController.php @@ -40,6 +40,8 @@ class UserController extends Controller $users = $this->userStore->getWhere(array(), 1000, 0, array(), array('email' => 'ASC')); $this->view->users = $users; + $this->config->set('page_title', 'Users'); + return $this->view->render(); } @@ -52,6 +54,9 @@ class UserController extends Controller throw new \Exception('You do not have permission to do that.'); } + $this->config->set('page_title', 'Add User'); + + $method = $this->request->getMethod(); if ($method == 'POST') { @@ -96,6 +101,9 @@ class UserController extends Controller $method = $this->request->getMethod(); $user = $this->userStore->getById($userId); + $this->config->set('page_title', 'Edit: ' . $user->getName()); + + if ($method == 'POST') { $values = $this->getParams(); } else { diff --git a/PHPCI/View/layout.phtml b/PHPCI/View/layout.phtml index c455334c..73c97d75 100644 --- a/PHPCI/View/layout.phtml +++ b/PHPCI/View/layout.phtml @@ -1,7 +1,7 @@ - PHPCI + <?php if (!empty($title)) { print $title . ' - '; } ?>PHPCI