Skip to content

Commit d76db9c

Browse files
committed
add tpl dashboard
1 parent c8249c4 commit d76db9c

File tree

2 files changed

+41
-49
lines changed

2 files changed

+41
-49
lines changed

main/dashboard/dashboard_controller.php

Lines changed: 20 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function __construct()
3030
*/
3131
public function display()
3232
{
33+
$tpl = new Template(get_lang('Dashboard'));
3334
$user_id = $this->user_id;
3435
$dashboard_blocks = DashboardManager::get_enabled_dashboard_blocks();
3536
$user_block_data = DashboardManager::get_user_block_data($user_id);
@@ -44,9 +45,9 @@ public function display()
4445

4546
$path = $block['path'];
4647
$controller_class = $block['controller'];
47-
$filename_controller = $path.'.class.php';
48-
$dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH).'dashboard/'.$path.'/';
49-
require_once $dashboard_plugin_path.$filename_controller;
48+
$filename_controller = $path . '.class.php';
49+
$dashboard_plugin_path = api_get_path(SYS_PLUGIN_PATH) . 'dashboard/' . $path . '/';
50+
require_once $dashboard_plugin_path . $filename_controller;
5051
if (class_exists($controller_class)) {
5152
$obj = new $controller_class($user_id);
5253

@@ -69,77 +70,47 @@ public function display()
6970
api_block_anonymous_users();
7071
$link_blocks_view = $link_list_view = null;
7172
if ($view == 'list') {
72-
$link_blocks_view = '<a href="'.api_get_self().'?view=blocks">'.
73-
Display::return_icon('blocks.png', get_lang('DashboardBlocks'), '', ICON_SIZE_MEDIUM).'</a>';
73+
$link_blocks_view = '<a href="' . api_get_self() . '?view=blocks">' .
74+
Display::return_icon('blocks.png', get_lang('DashboardBlocks'), '', ICON_SIZE_MEDIUM) . '</a>';
7475
} else {
75-
$link_list_view = '<a href="'.api_get_self().'?view=list">'.
76-
Display::return_icon('edit.png', get_lang('EditBlocks'), '', ICON_SIZE_MEDIUM).'</a>';
76+
$link_list_view = '<a href="' . api_get_self() . '?view=list">' .
77+
Display::return_icon('edit.png', get_lang('EditBlocks'), '', ICON_SIZE_MEDIUM) . '</a>';
7778
}
7879

7980
$configuration_link = null;
8081
if (api_is_platform_admin()) {
81-
$configuration_link = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/settings.php?category=Plugins">'
82-
.Display::return_icon('settings.png', get_lang('ConfigureDashboardPlugin'), '', ICON_SIZE_MEDIUM).'</a>';
82+
$configuration_link = '<a href="' . api_get_path(WEB_CODE_PATH) . 'admin/settings.php?category=Plugins">'
83+
. Display::return_icon('settings.png', get_lang('ConfigureDashboardPlugin'), '', ICON_SIZE_MEDIUM) . '</a>';
8384
}
8485

85-
$content = '<div class="actions">';
86-
$content .= $link_blocks_view.$link_list_view.$configuration_link;
87-
$content .= '</div>';
86+
$actions = Display::toolbarAction('toolbar', [0 => $link_blocks_view . $link_list_view . $configuration_link]);
87+
$tpl->assign('actions', $actions);
8888

8989
// block dashboard view
90+
$columns = [];
91+
$blockList = null;
9092
if (isset($view) && $view == 'blocks') {
9193
if (isset($blocks) && count($blocks) > 0) {
92-
$columns = [];
9394
// group content html by number of column
9495
if (is_array($blocks)) {
9596
$tmp_columns = [];
9697
foreach ($blocks as $block) {
9798
$tmp_columns[] = $block['column'];
9899
if (in_array($block['column'], $tmp_columns)) {
99-
$columns['column_'.$block['column']][] = $block['content_html'];
100-
}
101-
}
102-
}
103-
104-
$content .= '<div id="columns" class="row">';
105-
if (count($columns) > 0) {
106-
$columns_name = array_keys($columns);
107-
// blocks for column 1
108-
if (in_array('column_1', $columns_name)) {
109-
$content .= '<div id="column1" class="col-md-6">';
110-
foreach ($columns['column_1'] as $data) {
111-
$content .= $data;
112-
}
113-
$content .= '</div>';
114-
} else {
115-
$content .= '<div id="column1" class="col-md-6">';
116-
$content .= '&nbsp;';
117-
$content .= '</div>';
118-
}
119-
// blocks for column 2
120-
if (in_array('column_2', $columns_name)) {
121-
// blocks for column 1
122-
$content .= '<div id="column2" class="col-md-6">';
123-
foreach ($columns['column_2'] as $data) {
124-
$content .= $data;
100+
$columns['column_' . $block['column']][] = $block['content_html'];
125101
}
126-
$content .= '</div>';
127-
} else {
128-
$content .= '<div id="column2" class="col-md-6">';
129-
$content .= '&nbsp;';
130-
$content .= '</div>';
131102
}
132103
}
133-
$content .= '</div>';
134-
} else {
135-
$content .= '<div style="margin-top:20px;">'.get_lang('YouHaveNotEnabledBlocks').'</div>';
136104
}
137105
} else {
138106
$user_id = api_get_user_id();
139-
$content .= DashboardManager::display_user_dashboard_list($user_id);
107+
$blockList = DashboardManager::display_user_dashboard_list($user_id);
108+
$tpl->assign('blocklist', $blockList);
140109
}
141110

142-
$tpl = new Template(get_lang('Dashboard'));
111+
$tpl->assign('columns', $columns);
112+
$template = $tpl->get_template('dashboard/index.tpl');
113+
$content = $tpl->fetch($template);
143114
$tpl->assign('content', $content);
144115
$tpl->display_one_col_template();
145116
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% if blocklist == '' %}
2+
<div id="columns">
3+
<div class="row">
4+
{% if columns|length > 0 %}
5+
{% for key, column in columns %}
6+
<div id="{{ key }}" class="col-md-6">
7+
{% for item in column %}
8+
{{ item }}
9+
{% endfor %}
10+
</div>
11+
{% endfor %}
12+
{% else %}
13+
<div class="alert alert-info" role="alert">
14+
{{ 'YouHaveNotEnabledBlocks'| get_lang }}
15+
</div>
16+
{% endif %}
17+
</div>
18+
</div>
19+
{% else %}
20+
{{ blocklist }}
21+
{% endif %}

0 commit comments

Comments
 (0)