forked from jitamin/jitamin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayoutHelper.php
189 lines (165 loc) · 5.02 KB
/
LayoutHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
/*
* This file is part of Jitamin.
*
* Copyright (C) Jitamin Team
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Jitamin\Helper;
use Jitamin\Foundation\Base;
/**
* Layout Helper.
*/
class LayoutHelper extends Base
{
/**
* Render a template without the layout if Ajax request.
*
* @param string $template Template name
* @param array $params Template parameters
*
* @return string
*/
public function app($template, array $params = [])
{
$content = $this->template->render($template, $params);
if ($this->request->isAjax()) {
return $content;
}
return $this->template->render(
'layouts/master',
$params + ['content_for_layout' => $content]
);
}
/**
* Common layout for profile views.
*
* @param string $template Template name
* @param array $params Template parameters
* @param string $subside
*
* @return string
*/
public function profile($template, array $params, $subside = 'profile/_partials/subnav')
{
if (isset($params['user'])) {
$params['title'] = '#'.$params['user']['id'].' '.($params['user']['name'] ?: $params['user']['username']);
}
return $this->subLayout('profile/layout', $subside, $template, $params);
}
/**
* Common layout for task views.
*
* @param string $template Template name
* @param array $params Template parameters
*
* @return string
*/
public function task($template, array $params)
{
$params['page_title'] = $params['task']['project_name'].', #'.$params['task']['id'].' - '.$params['task']['title'];
$params['title'] = $params['task']['project_name'];
return $this->subLayout('task/layout', 'task/subside', $template, $params);
}
/**
* Common layout for project views.
*
* @param string $template
* @param array $params
* @param string $subside
*
* @return string
*/
public function project($template, array $params, $subside = 'manage/project_settings/subside')
{
if (empty($params['title'])) {
$params['title'] = $params['project']['name'];
} elseif ($params['project']['name'] !== $params['title']) {
$params['title'] = $params['project']['name'].' » '.$params['title'];
}
return $this->subLayout('project/layout', $subside, $template, $params);
}
/**
* Common layout for project user views.
*
* @param string $template
* @param array $params
*
* @return string
*/
public function projectUser($template, array $params)
{
$params['filter'] = ['user_id' => $params['user_id']];
return $this->subLayout('manage/project_user_overview/layout', 'manage/project_user_overview/subside', $template, $params);
}
/**
* Common layout for admin views.
*
* @param string $template
* @param array $params
* @param string $subside
*
* @return string
*/
public function admin($template, array $params, $subside = 'admin/setting/subside')
{
if (!isset($params['values'])) {
$params['values'] = $this->settingModel->getAll();
}
if (!isset($params['errors'])) {
$params['errors'] = [];
}
return $this->subLayout('admin/layout', $subside, $template, $params);
}
/**
* Common layout for dashboard views.
*
* @param string $template
* @param array $params
* @param string $subside
*
* @return string
*/
public function dashboard($template, array $params, $subside = 'dashboard/_partials/subnav')
{
return $this->subLayout('dashboard/layout', $subside, $template, $params);
}
/**
* Common layout for analytic views.
*
* @param string $template
* @param array $params
* @param string $subside
*
* @return string
*/
public function analytic($template, array $params, $subside = 'project/analytic/_partials/subside')
{
if (isset($params['project']['name'])) {
$params['title'] = $params['project']['name'].' » '.$params['title'];
}
return $this->subLayout('project/analytic/layout', $subside, $template, $params);
}
/**
* Common method to generate a sub-layout.
*
* @param string $sublayout
* @param string $subside
* @param string $template
* @param array $params
*
* @return string
*/
protected function subLayout($sublayout, $subside, $template, array $params = [])
{
$content = $this->template->render($template, $params);
if ($this->request->isAjax()) {
return $content;
}
$params['content_for_sublayout'] = $content;
$params['subside_template'] = $subside;
return $this->app($sublayout, $params);
}
}