Skip to content

Commit 10897f1

Browse files
committed
Add template for course home page - refs BT#12756
1 parent 8f1955a commit 10897f1

File tree

5 files changed

+183
-157
lines changed

5 files changed

+183
-157
lines changed

main/course_home/activity.php

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
// COURSE ADMIN ONLY VIEW
4949

50+
$blocks = [];
51+
5052
// Start of tools for CourseAdmins (teachers/tutors)
5153
if ($session_id === 0 && api_is_course_admin() && api_is_allowed_to_edit(null, true)) {
5254
$content .= '<div class="alert alert-success" style="border:0px; margin-top: 0px;padding:0px;">
@@ -72,19 +74,30 @@
7274
}
7375

7476
$my_list = CourseHome::get_tools_category(TOOL_AUTHORING);
75-
$items = CourseHome::show_tools_category($my_list);
76-
$content .= return_block(get_lang('Authoring'), $items, 'course-tools-author');
7777

78-
$my_list = CourseHome::get_tools_category(TOOL_INTERACTION);
78+
$blocks[] = [
79+
'title' => get_lang('Authoring'),
80+
'class' => 'course-tools-author',
81+
'content' => CourseHome::show_tools_category($my_list)
82+
];
83+
84+
$list1 = CourseHome::get_tools_category(TOOL_INTERACTION);
7985
$list2 = CourseHome::get_tools_category(TOOL_COURSE_PLUGIN);
86+
$my_list = array_merge($list1, $list2);
8087

81-
$my_list = array_merge($my_list, $list2);
82-
$items = CourseHome::show_tools_category($my_list);
83-
$content .= return_block(get_lang('Interaction'), $items, 'course-tools-interaction');
88+
$blocks[] = [
89+
'title' => get_lang('Interaction'),
90+
'class' => 'course-tools-interaction',
91+
'content' => CourseHome::show_tools_category($my_list)
92+
];
8493

8594
$my_list = CourseHome::get_tools_category(TOOL_ADMIN_PLATFORM);
86-
$items = CourseHome::show_tools_category($my_list);
87-
$content .= return_block(get_lang('Administration'), $items, 'course-tools-administration');
95+
96+
$blocks[] = [
97+
'title' => get_lang('Administration'),
98+
'class' => 'course-tools-administration',
99+
'content' => CourseHome::show_tools_category($my_list)
100+
];
88101

89102
} elseif (api_is_coach()) {
90103
$content .= $pluginExtra;
@@ -97,10 +110,11 @@
97110
$content .= '</table></div></div>';
98111
}
99112

100-
$content .= '<div class="row">';
101113
$my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW);
102-
$content .= CourseHome::show_tools_category($my_list);
103-
$content .= '</div>';
114+
115+
$blocks[] = [
116+
'content' => CourseHome::show_tools_category($my_list)
117+
];
104118

105119
$sessionsCopy = api_get_setting('allow_session_course_copy_for_teachers');
106120
if ($sessionsCopy === 'true') {
@@ -116,8 +130,10 @@
116130
}
117131
}
118132

119-
$items = CourseHome::show_tools_category($onlyMaintenanceList);
120-
$content .= return_block(get_lang('Administration'), $items);
133+
$blocks[] = [
134+
'title' => get_lang('Administration'),
135+
'content' => CourseHome::show_tools_category($onlyMaintenanceList)
136+
];
121137
}
122138
} else {
123139
$tools = CourseHome::get_tools_category(TOOL_STUDENT_VIEW);
@@ -155,34 +171,19 @@
155171
}
156172

157173
if (count($tools) > 0) {
158-
$content .= '<div class="row">';
159-
$content .= CourseHome::show_tools_category($tools);
160-
$content .= '</div>';
174+
$blocks[] = ['content' => CourseHome::show_tools_category($tools)];
161175
}
162176

163177
if ($isDrhOfCourse) {
164178
$drhTool = CourseHome::get_tools_category(TOOL_DRH);
165-
$content .= '<div class="row">';
166-
$content .= CourseHome::show_tools_category($drhTool);
167-
$content .= '</div>';
179+
180+
$blocks[] = ['content' => CourseHome::show_tools_category($drhTool)];
168181
}
169182
}
170183

171-
/**
172-
* @param string $title
173-
* @param string $content
174-
* @param string $class
175-
*
176-
* @return string
177-
*/
178-
function return_block($title, $content, $class = null)
179-
{
180-
$html = '<div class="row">
181-
<div class="col-xs-12 col-md-12">
182-
<div class="title-tools">' . $title.'</div>
183-
</div>
184-
</div>
185-
<div class="row '.$class.'">'.$content.'</div>';
184+
$activityView = new Template('', false, false, false, false, false, false);
185+
$activityView->assign('blocks', $blocks);
186186

187-
return $html;
188-
}
187+
$content .= $activityView->fetch(
188+
$activityView->get_template('course_home/activity.tpl')
189+
);

main/course_home/vertical_activity.php

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
}
5353

5454
// COURSE ADMIN ONLY VIEW
55+
$blocks = [];
5556

5657
// Start of tools for CourseAdmins (teachers/tutors)
5758
if (api_is_allowed_to_edit(null, true) && !api_is_coach()) {
@@ -70,20 +71,26 @@
7071
</div>';
7172
}
7273

73-
$content .= '<div class="courseadminview-activity-3col"><span class="viewcaption">'.get_lang('Authoring').'</span>';
7474
$my_list = CourseHome::get_tools_category(TOOL_AUTHORING);
75-
$content .= CourseHome::show_tools_category($my_list);
76-
$content .= '</div>';
7775

78-
$content .= '<div class="courseadminview-activity-3col"><span class="viewcaption">'.get_lang('Interaction').'</span>';
76+
$blocks[] = [
77+
'title' => get_lang('Authoring'),
78+
'content' => CourseHome::show_tools_category($my_list)
79+
];
80+
7981
$my_list = CourseHome::get_tools_category(TOOL_INTERACTION);
80-
$content .= CourseHome::show_tools_category($my_list);
81-
$content .= '</div>';
8282

83-
$content .= '<div class="courseadminview-activity-3col"><span class="viewcaption">'.get_lang('Administration').'</span>';
83+
$blocks[] = [
84+
'title' => get_lang('Interaction'),
85+
'content' => CourseHome::show_tools_category($my_list)
86+
];
87+
8488
$my_list = CourseHome::get_tools_category(TOOL_ADMIN_PLATFORM);
85-
$content .= CourseHome::show_tools_category($my_list);
86-
$content .= '</div>';
89+
90+
$blocks[] = [
91+
'title' => get_lang('Administration'),
92+
'content' => CourseHome::show_tools_category($my_list)
93+
];
8794

8895
} elseif (api_is_coach()) {
8996
if (api_get_setting('show_session_data') == 'true' && $session_id > 0) {
@@ -93,15 +100,16 @@
93100
$content .= '</table></div>';
94101
}
95102

96-
$content .= '<div class="Authoringview">';
97-
$my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW);
98-
$content .= CourseHome::show_tools_category($my_list);
99-
$content .= '</div>';
103+
$my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW);
104+
105+
$blocks[] = [
106+
'class' => 'Authoringview',
107+
'content' => CourseHome::show_tools_category($my_list)
108+
];
100109
// TOOLS AUTHORING
101110
} else {
102111
$my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW);
103112
if (count($my_list) > 0) {
104-
$content .= '<div class="course-student-view-activity-3col">';
105113
//ordering by get_lang name
106114
$order_tool_list = array();
107115
foreach ($my_list as $key => $new_tool) {
@@ -113,20 +121,17 @@
113121
foreach ($order_tool_list as $key => $new_tool) {
114122
$my_temp_tool_array[] = $my_list[$key];
115123
}
116-
$my_list = $my_temp_tool_array;
117-
118-
$i = 0;
119-
foreach ($my_list as $new_tool) {
120-
if ($i >= 10) {
121-
$my_list2[] = $new_tool;
122-
} else {
123-
$my_list1[] = $new_tool;
124-
}
125-
$i++;
126-
}
127-
$content .= CourseHome::show_tools_category($my_list1);
128-
$content .= CourseHome::show_tools_category($my_list2);
129-
$content .= '</div>';
124+
125+
$blocks[] = [
126+
'class' => 'course-student-view-activity-3col',
127+
'content' => CourseHome::show_tools_category($my_temp_tool_array)
128+
];
130129
}
131130
}
132-
$content .= '</div>';
131+
132+
$activityView = new Template('', false, false, false, false, false, false);
133+
$activityView->assign('blocks', $blocks);
134+
135+
$content .= $activityView->fetch(
136+
$activityView->get_template('course_home/vertical_activity.tpl')
137+
);

main/inc/lib/course_home.lib.php

Lines changed: 43 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -996,110 +996,61 @@ public static function show_tools_category($all_tools_list, $rows = false)
996996
} // end of foreach
997997
}
998998

999-
return self::formatToolItems($items);
999+
if (api_get_setting('homepage_view') != 'activity_big') {
1000+
return $items;
1001+
}
1002+
1003+
foreach ($items as &$item) {
1004+
$originalImage = self::getToolIcon($item);
1005+
$item['tool']['image'] = Display::url(
1006+
$originalImage,
1007+
$item['url_params']['href'],
1008+
$item['url_params']
1009+
);
1010+
}
1011+
1012+
return $items;
10001013
}
10011014

10021015
/**
1003-
* Get buttons to course tools
1004-
* @param array $items
1016+
* Find the tool icon when homepage_view is activity_big
1017+
* @param array $item
10051018
* @return string
10061019
*/
1007-
public static function formatToolItems(array $items)
1020+
private static function getToolIcon(array $item)
10081021
{
1009-
$theme = api_get_setting('homepage_view');
1010-
$html = '';
1011-
1012-
if (empty($items)) {
1013-
return $html;
1022+
$image = str_replace('.gif', '.png', $item['tool']['image']);
1023+
$toolIid = isset($item['tool']['iid']) ? $item['tool']['iid'] : null;
1024+
1025+
if (isset($item['tool']['custom_image'])) {
1026+
return Display::img(
1027+
$item['tool']['custom_image'],
1028+
$item['name'],
1029+
array('id' => 'toolimage_'.$toolIid)
1030+
);
10141031
}
10151032

1016-
switch ($theme) {
1017-
case 'activity_big':
1018-
foreach ($items as $item) {
1019-
$data = '';
1020-
$image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
1021-
$toolIid = isset($item['tool']['iid']) ? $item['tool']['iid'] : null;
1022-
1023-
if (isset($item['tool']['custom_image'])) {
1024-
$original_image = Display::img(
1025-
$item['tool']['custom_image'],
1026-
$item['name'],
1027-
array('id' => 'toolimage_'.$toolIid)
1028-
);
1029-
} elseif (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) {
1030-
$customIcon = $item['tool']['custom_icon'];
1031-
if ($item['tool']['visibility'] == '0') {
1032-
$customIcon = self::getDisableIcon($item['tool']['custom_icon']);
1033-
}
1034-
$original_image = Display::img(
1035-
self::getCustomWebIconPath().$customIcon,
1036-
$item['name'],
1037-
array('id' => 'toolimage_'.$toolIid)
1038-
);
1039-
} else {
1040-
$original_image = Display::return_icon(
1041-
$image,
1042-
$item['name'],
1043-
array('id' => 'toolimage_'.$toolIid),
1044-
ICON_SIZE_BIG,
1045-
false
1046-
);
1047-
}
1048-
1049-
$data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']);
1033+
if (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) {
1034+
$customIcon = $item['tool']['custom_icon'];
10501035

1051-
$html .= '<div class="col-xs-6 col-md-3 course-tool">'
1052-
.Display::div($data, array('class' => 'big_icon'))
1053-
.Display::div(
1054-
'<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>',
1055-
array('class' => 'content')
1056-
)
1057-
.'</div>';
1058-
}
1059-
break;
1060-
case 'activity':
1061-
foreach ($items as $item) {
1062-
$html .= '<div class="offset2 col-md-4 course-tool">'
1063-
.$item['extra']
1064-
.$item['visibility']
1065-
.$item['icon']
1066-
.$item['link']
1067-
.'</div>';
1068-
}
1069-
break;
1070-
case 'vertical_activity':
1071-
$i = 0;
1072-
foreach ($items as $item) {
1073-
$image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
1074-
$original_image = Display::return_icon(
1075-
$image,
1076-
$item['name'],
1077-
array('id' => 'toolimage_'.$item['tool']['iid']),
1078-
ICON_SIZE_SMALL,
1079-
false
1080-
);
1081-
1082-
if ($i == 0) {
1083-
$html .= '<ul>';
1084-
}
1085-
1086-
$html .= '<li class="course-tool">'
1087-
.$item['extra']
1088-
.$item['visibility']
1089-
.Display::url($original_image, $item['url_params']['href'], $item['url_params'])
1090-
.$item['link']
1091-
.'</li>';
1092-
1093-
if ($i == count($items) - 1) {
1094-
$html .= '</ul>';
1095-
}
1036+
if ($item['tool']['visibility'] == '0') {
1037+
$customIcon = self::getDisableIcon($item['tool']['custom_icon']);
1038+
}
10961039

1097-
$i++;
1098-
}
1099-
break;
1040+
return Display::img(
1041+
self::getCustomWebIconPath().$customIcon,
1042+
$item['name'],
1043+
array('id' => 'toolimage_'.$toolIid)
1044+
);
11001045
}
11011046

1102-
return $html;
1047+
return Display::return_icon(
1048+
$image,
1049+
$item['name'],
1050+
array('id' => 'toolimage_'.$toolIid),
1051+
ICON_SIZE_BIG,
1052+
false
1053+
);
11031054
}
11041055

11051056
/**

0 commit comments

Comments
 (0)