summaryrefslogtreecommitdiff
path: root/app/Helper/LayoutHelper.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-03-04 20:10:34 -0500
committerFrederic Guillot <fred@kanboard.net>2016-03-04 20:10:34 -0500
commit8f3e2b2e5c62a6130f6c8867ab335fb4c1a32c5c (patch)
treece28cdc2dba9c31560ef753ac1b4dc39d567b7a6 /app/Helper/LayoutHelper.php
parentf32507d423c46e8e9612b5239728e6c617e4cbcb (diff)
Helper refactoring
Diffstat (limited to 'app/Helper/LayoutHelper.php')
-rw-r--r--app/Helper/LayoutHelper.php171
1 files changed, 171 insertions, 0 deletions
diff --git a/app/Helper/LayoutHelper.php b/app/Helper/LayoutHelper.php
new file mode 100644
index 00000000..064c11ac
--- /dev/null
+++ b/app/Helper/LayoutHelper.php
@@ -0,0 +1,171 @@
+<?php
+
+namespace Kanboard\Helper;
+
+use Kanboard\Core\Base;
+
+/**
+ * Layout helpers
+ *
+ * @package helper
+ * @author Frederic Guillot
+ */
+class LayoutHelper extends Base
+{
+ /**
+ * Render a template without the layout if Ajax request
+ *
+ * @access public
+ * @param string $template Template name
+ * @param array $params Template parameters
+ * @return string
+ */
+ public function app($template, array $params = array())
+ {
+ if ($this->request->isAjax()) {
+ return $this->template->render($template, $params);
+ }
+
+ if (! isset($params['no_layout']) && ! isset($params['board_selector'])) {
+ $params['board_selector'] = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId());
+ }
+
+ return $this->template->layout($template, $params);
+ }
+
+ /**
+ * Common layout for user views
+ *
+ * @access public
+ * @param string $template Template name
+ * @param array $params Template parameters
+ * @return string
+ */
+ public function user($template, array $params)
+ {
+ if (isset($params['user'])) {
+ $params['title'] = '#'.$params['user']['id'].' '.($params['user']['name'] ?: $params['user']['username']);
+ }
+
+ return $this->subLayout('user/layout', 'user/sidebar', $template, $params);
+ }
+
+ /**
+ * Common layout for task views
+ *
+ * @access public
+ * @param string $template Template name
+ * @param array $params Template parameters
+ * @return string
+ */
+ public function task($template, array $params)
+ {
+ $params['title'] = $params['task']['title'];
+ return $this->subLayout('task/layout', 'task/sidebar', $template, $params);
+ }
+
+ /**
+ * Common layout for project views
+ *
+ * @access public
+ * @param string $template
+ * @param array $params
+ * @param string $sidebar
+ * @return string
+ */
+ public function project($template, array $params, $sidebar = 'project/sidebar')
+ {
+ if (empty($params['title'])) {
+ $params['title'] = $params['project']['name'];
+ } elseif ($params['project']['name'] !== $params['title']) {
+ $params['title'] = $params['project']['name'].' &gt; '.$params['title'];
+ }
+
+ return $this->subLayout('project/layout', $sidebar, $template, $params);
+ }
+
+ /**
+ * Common layout for project user views
+ *
+ * @access public
+ * @param string $template
+ * @param array $params
+ * @return string
+ */
+ public function projectUser($template, array $params)
+ {
+ $params['filter'] = array('user_id' => $params['user_id']);
+ return $this->subLayout('project_user/layout', 'project_user/sidebar', $template, $params);
+ }
+
+ /**
+ * Common layout for config views
+ *
+ * @access public
+ * @param string $template
+ * @param array $params
+ * @return string
+ */
+ public function config($template, array $params)
+ {
+ if (! isset($params['values'])) {
+ $params['values'] = $this->config->getAll();
+ }
+
+ if (! isset($params['errors'])) {
+ $params['errors'] = array();
+ }
+
+ return $this->subLayout('config/layout', 'config/sidebar', $template, $params);
+ }
+
+ /**
+ * Common layout for dashboard views
+ *
+ * @access public
+ * @param string $template
+ * @param array $params
+ * @return string
+ */
+ public function dashboard($template, array $params)
+ {
+ return $this->subLayout('app/layout', 'app/sidebar', $template, $params);
+ }
+
+ /**
+ * Common layout for analytic views
+ *
+ * @access public
+ * @param string $template
+ * @param array $params
+ * @return string
+ */
+ public function analytic($template, array $params)
+ {
+ return $this->subLayout('analytic/layout', 'analytic/sidebar', $template, $params);
+ }
+
+ /**
+ * Common method to generate a sublayout
+ *
+ * @access public
+ * @param string $sublayout
+ * @param string $sidebar
+ * @param string $template
+ * @param array $params
+ * @return string
+ */
+ public function subLayout($sublayout, $sidebar, $template, array $params = array())
+ {
+ $content = $this->template->render($template, $params);
+
+ if ($this->request->isAjax()) {
+ return $content;
+ }
+
+ $params['content_for_sublayout'] = $content;
+ $params['sidebar_template'] = $sidebar;
+
+ return $this->app($sublayout, $params);
+ }
+}