diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-09-16 13:25:44 +0200 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-09-16 13:25:44 +0200 |
commit | 12a688347ce9374e060f4adb98af3892542285d4 (patch) | |
tree | 53e349326f114da6ac01d4ec9c79da1605b0e8ee | |
parent | a7f3cd87fba3e02d31f1c939a75e884d645c35e9 (diff) |
Improve Board::Index() and avoid useless HTTP redirects
-rw-r--r-- | app/Controller/Base.php | 5 | ||||
-rw-r--r-- | app/Controller/Board.php | 71 | ||||
-rw-r--r-- | app/Controller/User.php | 2 | ||||
-rw-r--r-- | app/Model/User.php | 33 |
4 files changed, 64 insertions, 47 deletions
diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 00bfb79b..1ef54d8e 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -280,11 +280,12 @@ abstract class Base * Common method to get a project * * @access protected + * @param integer $project_id Default project id * @return array */ - protected function getProject() + protected function getProject($project_id = 0) { - $project_id = $this->request->getIntegerParam('project_id'); + $project_id = $this->request->getIntegerParam('project_id', $project_id); $project = $this->project->getById($project_id); if (! $project) { diff --git a/app/Controller/Board.php b/app/Controller/Board.php index ec3eb4f3..05ef018a 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -188,71 +188,54 @@ class Board extends Base */ public function index() { - $projects = $this->project->getListByStatus(ProjectModel::ACTIVE); - $project_id = 0; - $project_name = ''; + $last_seen_project_id = $this->user->getLastSeenProject(); + $favorite_project_id = $this->user->getFavoriteProjectId(); + $project_id = $last_seen_project_id ?: $favorite_project_id; - if ($this->acl->isRegularUser()) { - $projects = $this->project->filterListByAccess($projects, $this->acl->getUserId()); - } + if (! $project_id) { + $projects = $this->project->getAvailableList($this->acl->getUserId()); - if (empty($projects)) { + if (empty($projects)) { - if ($this->acl->isAdminUser()) { - $this->redirectNoProject(); - } - else { - $this->response->redirect('?controller=project&action=forbidden'); + if ($this->acl->isAdminUser()) { + $this->redirectNoProject(); + } + + $this->forbidden(); } - } - else if (! empty($_SESSION['user']['last_show_project_id']) && isset($projects[$_SESSION['user']['last_show_project_id']])) { - $project_id = $_SESSION['user']['last_show_project_id']; - $project_name = $projects[$_SESSION['user']['last_show_project_id']]; - } - else if (! empty($_SESSION['user']['default_project_id']) && isset($projects[$_SESSION['user']['default_project_id']])) { - $project_id = $_SESSION['user']['default_project_id']; - $project_name = $projects[$_SESSION['user']['default_project_id']]; - } - else { - list($project_id, $project_name) = each($projects); + + $project_id = key($projects); } - $this->response->redirect('?controller=board&action=show&project_id='.$project_id); + $this->show($project_id); } /** * Show a board for a given project * * @access public + * @param integer $project_id Default project id */ - public function show() + public function show($project_id = 0) { - $project_id = $this->request->getIntegerParam('project_id'); - $user_id = $this->request->getIntegerParam('user_id', UserModel::EVERYBODY_ID); - - // Stored last seen in the project dashboard - $_SESSION['user']['last_show_project_id'] = $project_id ; - - $this->checkProjectPermissions($project_id); + $project = $this->getProject($project_id); $projects = $this->project->getAvailableList($this->acl->getUserId()); - if (! isset($projects[$project_id])) { - $this->notfound(); - } - $board_selector = $projects; - unset($board_selector[$project_id]); + unset($board_selector[$project['id']]); + + $this->user->storeLastSeenProject($project['id']); $this->response->html($this->template->layout('board_index', array( - 'users' => $this->project->getUsersList($project_id, true, true), - 'filters' => array('user_id' => $user_id), + 'users' => $this->project->getUsersList($project['id'], true, true), + 'filters' => array('user_id' => UserModel::EVERYBODY_ID), 'projects' => $projects, - 'current_project_id' => $project_id, - 'current_project_name' => $projects[$project_id], - 'board' => $this->board->get($project_id), - 'categories' => $this->category->getList($project_id, true, true), + 'current_project_id' => $project['id'], + 'current_project_name' => $projects[$project['id']], + 'board' => $this->board->get($project['id']), + 'categories' => $this->category->getList($project['id'], true, true), 'menu' => 'boards', - 'title' => $projects[$project_id], + 'title' => $projects[$project['id']], 'board_selector' => $board_selector, ))); } diff --git a/app/Controller/User.php b/app/Controller/User.php index 25402f03..ee3d47eb 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -53,7 +53,7 @@ class User extends Base list($valid, $errors) = $this->authentication->validateForm($values); if ($valid) { - $this->response->redirect('?controller=app'); + $this->response->redirect('?controller=board'); } $this->response->html($this->template->layout('user_login', array( diff --git a/app/Model/User.php b/app/Model/User.php index b99be2cb..9eccb207 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -28,6 +28,39 @@ class User extends Base const EVERYBODY_ID = -1; /** + * Get the default project from the session + * + * @access public + * @return integer + */ + public function getFavoriteProjectId() + { + return isset($_SESSION['user']['default_project_id']) ? $_SESSION['user']['default_project_id'] : 0; + } + + /** + * Get the last seen project from the session + * + * @access public + * @return integer + */ + public function getLastSeenProject() + { + return empty($_SESSION['user']['last_show_project_id']) ? 0 : $_SESSION['user']['last_show_project_id']; + } + + /** + * Set the last seen project from the session + * + * @access public + * @@param integer $project_id Project id + */ + public function storeLastSeenProject($project_id) + { + $_SESSION['user']['last_show_project_id'] = (int) $project_id; + } + + /** * Get a specific user by id * * @access public |