From 26492aba7ee2bfb8c525ea0aaa580aff47a414ba Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 31 Jan 2016 21:44:49 -0500 Subject: Simplify layout and templates generation --- app/Controller/User.php | 56 ++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) (limited to 'app/Controller/User.php') diff --git a/app/Controller/User.php b/app/Controller/User.php index 97e01553..881266d4 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -14,27 +14,6 @@ use Kanboard\Core\Security\Role; */ class User extends Base { - /** - * Common layout for user views - * - * @access protected - * @param string $template Template name - * @param array $params Template parameters - * @return string - */ - protected function layout($template, array $params) - { - $content = $this->template->render($template, $params); - $params['user_content_for_layout'] = $content; - $params['board_selector'] = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); - - if (isset($params['user'])) { - $params['title'] = ($params['user']['name'] ?: $params['user']['username']).' (#'.$params['user']['id'].')'; - } - - return $this->template->layout('user/layout', $params); - } - /** * List all users * @@ -50,8 +29,7 @@ class User extends Base ->calculate(); $this->response->html( - $this->template->layout('user/index', array( - 'board_selector' => $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()), + $this->helper->layout->app('user/index', array( 'title' => t('Users').' ('.$paginator->getTotal().')', 'paginator' => $paginator, ))); @@ -71,8 +49,7 @@ class User extends Base } $this->response->html( - $this->template->layout('user/profile', array( - 'board_selector' => $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()), + $this->helper->layout->app('user/profile', array( 'title' => $user['name'] ?: $user['username'], 'user' => $user, ) @@ -88,11 +65,10 @@ class User extends Base { $is_remote = $this->request->getIntegerParam('remote') == 1 || (isset($values['is_ldap_user']) && $values['is_ldap_user'] == 1); - $this->response->html($this->template->layout($is_remote ? 'user/create_remote' : 'user/create_local', array( + $this->response->html($this->helper->layout->app($is_remote ? 'user/create_remote' : 'user/create_local', array( 'timezones' => $this->config->getTimezones(true), 'languages' => $this->config->getLanguages(true), 'roles' => $this->role->getApplicationRoles(), - 'board_selector' => $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()), 'projects' => $this->project->getList(), 'errors' => $errors, 'values' => $values + array('role' => Role::APP_USER), @@ -142,7 +118,7 @@ class User extends Base public function show() { $user = $this->getUser(); - $this->response->html($this->layout('user/show', array( + $this->response->html($this->helper->layout->user('user/show', array( 'user' => $user, 'timezones' => $this->config->getTimezones(true), 'languages' => $this->config->getLanguages(true), @@ -166,7 +142,7 @@ class User extends Base ->setQuery($this->subtaskTimeTracking->getUserQuery($user['id'])) ->calculateOnlyIf($this->request->getStringParam('pagination') === 'subtasks'); - $this->response->html($this->layout('user/timesheet', array( + $this->response->html($this->helper->layout->user('user/timesheet', array( 'subtask_paginator' => $subtask_paginator, 'user' => $user, ))); @@ -180,7 +156,7 @@ class User extends Base public function passwordReset() { $user = $this->getUser(); - $this->response->html($this->layout('user/password_reset', array( + $this->response->html($this->helper->layout->user('user/password_reset', array( 'tokens' => $this->passwordReset->getAll($user['id']), 'user' => $user, ))); @@ -194,7 +170,7 @@ class User extends Base public function last() { $user = $this->getUser(); - $this->response->html($this->layout('user/last', array( + $this->response->html($this->helper->layout->user('user/last', array( 'last_logins' => $this->lastLogin->getAll($user['id']), 'user' => $user, ))); @@ -208,7 +184,7 @@ class User extends Base public function sessions() { $user = $this->getUser(); - $this->response->html($this->layout('user/sessions', array( + $this->response->html($this->helper->layout->user('user/sessions', array( 'sessions' => $this->rememberMeSession->getAll($user['id']), 'user' => $user, ))); @@ -243,7 +219,7 @@ class User extends Base $this->response->redirect($this->helper->url->to('user', 'notifications', array('user_id' => $user['id']))); } - $this->response->html($this->layout('user/notifications', array( + $this->response->html($this->helper->layout->user('user/notifications', array( 'projects' => $this->projectUserRole->getProjectsByUser($user['id'], array(ProjectModel::ACTIVE)), 'notifications' => $this->userNotification->readSettings($user['id']), 'types' => $this->userNotificationType->getTypes(), @@ -268,7 +244,7 @@ class User extends Base $this->response->redirect($this->helper->url->to('user', 'integrations', array('user_id' => $user['id']))); } - $this->response->html($this->layout('user/integrations', array( + $this->response->html($this->helper->layout->user('user/integrations', array( 'user' => $user, 'values' => $this->userMetadata->getall($user['id']), ))); @@ -282,7 +258,7 @@ class User extends Base public function external() { $user = $this->getUser(); - $this->response->html($this->layout('user/external', array( + $this->response->html($this->helper->layout->user('user/external', array( 'last_logins' => $this->lastLogin->getAll($user['id']), 'user' => $user, ))); @@ -310,7 +286,7 @@ class User extends Base $this->response->redirect($this->helper->url->to('user', 'share', array('user_id' => $user['id']))); } - $this->response->html($this->layout('user/share', array( + $this->response->html($this->helper->layout->user('user/share', array( 'user' => $user, 'title' => t('Public access'), ))); @@ -342,7 +318,7 @@ class User extends Base } } - $this->response->html($this->layout('user/password', array( + $this->response->html($this->helper->layout->user('user/password', array( 'values' => $values, 'errors' => $errors, 'user' => $user, @@ -384,7 +360,7 @@ class User extends Base } } - $this->response->html($this->layout('user/edit', array( + $this->response->html($this->helper->layout->user('user/edit', array( 'values' => $values, 'errors' => $errors, 'user' => $user, @@ -422,7 +398,7 @@ class User extends Base } } - $this->response->html($this->layout('user/authentication', array( + $this->response->html($this->helper->layout->user('user/authentication', array( 'values' => $values, 'errors' => $errors, 'user' => $user, @@ -450,7 +426,7 @@ class User extends Base $this->response->redirect($this->helper->url->to('user', 'index')); } - $this->response->html($this->layout('user/remove', array( + $this->response->html($this->helper->layout->user('user/remove', array( 'user' => $user, ))); } -- cgit v1.2.3