forked from bmbrands/theme_bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderers.php
More file actions
305 lines (260 loc) · 10.6 KB
/
renderers.php
File metadata and controls
305 lines (260 loc) · 10.6 KB
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
/* some documentation here */
class theme_bootstrap_core_renderer extends core_renderer {
/*
* Course layouts show the type of layout on top of the course page
* Using this renderer I hide these headings
*/
public function heading($text, $level = 2, $classes = 'main', $id = null) {
global $COURSE;
$topicoutline = get_string('topicoutline');
if ($text == $topicoutline) {
$text = '';
}
if ($text == get_string('weeklyoutline')) {
$text = '';
}
$content = parent::heading($text, $level, $classes, $id);
return $content;
}
/*
* The standard navigation bar (breadcrumb)
* shows the course category
* For this theme the course category has been removed
*/
public function navbar() {
$items = $this->page->navbar->get_items();
$htmlblocks = array();
// Iterate the navarray and display each node
$itemcount = count($items);
$separator = ' / ';
for ($i=0;$i < $itemcount;$i++) {
$item = $items[$i];
if ($item->type == "0" || $item->type == "30") {
continue;
}
$item->hideicon = true;
if ($i===0) {
$content = html_writer::tag('li', $this->render($item));
} else {
$content = html_writer::tag('li', $separator.$this->render($item));
}
$htmlblocks[] = $content;
}
//accessibility: heading for navbar list (MDL-20446)
$navbarcontent = html_writer::tag('span', get_string('pagepath'), array('class'=>'accesshide'));
$navbarcontent .= html_writer::tag('ul', join('', $htmlblocks));
// XHTML
return $navbarcontent;
}
/*
* Overriding the custom_menu function ensures the custom menu is
* always shown, even if no menu items are configured in the global
* theme settings page.
* We use the sitename as the first menu item
*/
public function custom_menu($custommenuitems = '') {
global $CFG;
$site = get_site();
$custommenuitems = $site->fullname . "|" . $CFG->wwwroot . "\n";
if (!empty($CFG->custommenuitems)) {
$custommenuitems .= $CFG->custommenuitems;
}
$custommenu = new custom_menu($custommenuitems, current_language());
return $this->render_custom_menu($custommenu);
}
/*
* this renders the bootstrap top menu
*/
protected function render_custom_menu(custom_menu $menu) {
global $OUTPUT, $USER;
// If the menu has no children return an empty string
if (!$menu->has_children()) {
return '';
}
$menupos = 3;
if (is_siteadmin($USER)) {
$menu->add(get_string('purgecaches', 'theme_bootstrap'), new moodle_url('/admin/purgecaches.php', array('sesskey' => sesskey(), 'confirm' => '1')), null, $menupos++);
}
// Initialise this custom menu
$content = html_writer::start_tag('div',array('class'=>"navbar navbar-fixed-top"));
$content .= html_writer::start_tag('div',array('class'=>"navbar-inner"));
$content .= html_writer::start_tag('div',array('class'=>"container"));
$content .= html_writer::start_tag('a',array('class'=>"btn btn-navbar",'data-toggle'=>"collapse",'data-target'=>".nav-collapse"));
$content .= html_writer::tag('span', '',array('class'=>'icon-bar'));
$content .= html_writer::tag('span', '',array('class'=>'icon-bar'));
$content .= html_writer::tag('span', '',array('class'=>'icon-bar'));
$content .= html_writer::end_tag('a');
$content .= html_writer::start_tag('div', array('class'=>'nav-collapse'));
$content .= html_writer::start_tag('ul', array('class'=>'nav'));
// Render each child
foreach ($menu->get_children() as $item) {
$content .= $this->render_custom_menu_item($item);
}
// Close the open tags
$content .= $this->lang_menu();
$content .= html_writer::end_tag('ul');
//$content .= $this->login_info();
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('div');
// Return the custom menu
return $content;
}
/*
* This code renders the custom menu items for the
* bootstrap dropdown menu
*/
protected function render_custom_menu_item(custom_menu_item $menunode) {
// Required to ensure we get unique trackable id's
static $submenucount = 0;
if ($menunode->has_children()) {
$content = html_writer::start_tag('li', array('class'=>'dropdown'));
// If the child has menus render it as a sub menu
$submenucount++;
if ($menunode->get_url() !== null) {
$url = $menunode->get_url();
} else {
$url = '#cm_submenu_'.$submenucount;
}
//$content .= html_writer::link($url, $menunode->get_text(), array('title'=>,));
$content .= html_writer::start_tag('a', array('href'=>$url,'class'=>'dropdown-toggle','data-toggle'=>'dropdown'));
$content .= $menunode->get_title();
$content .= html_writer::start_tag('b', array('class'=>'caret'));
$content .= html_writer::end_tag('b');
$content .= html_writer::end_tag('a');
$content .= html_writer::start_tag('ul', array('class'=>'dropdown-menu'));
foreach ($menunode->get_children() as $menunode) {
$content .= $this->render_custom_menu_item($menunode);
}
$content .= html_writer::end_tag('ul');
} else {
$content = html_writer::start_tag('li');
// The node doesn't have children so produce a final menuitem
if ($menunode->get_url() !== null) {
$url = $menunode->get_url();
} else {
$url = '#';
}
$content .= html_writer::link($url, $menunode->get_text(), array('title'=>$menunode->get_title()));
}
$content .= html_writer::end_tag('li');
// Return the sub menu
return $content;
}
/*
* This code replaces the standard moodle icons
* with a icon sprite that is included in bootstrap
* If the icon is not listed in the $icons array
* the original Moodle icon will be shown
*/
static $icons = array(
'docs' => 'question-sign',
'book' => 'book',
'chapter' => 'file',
'spacer' => 'spacer',
'generate' => 'gift',
'add' => 'plus',
't/hide' => 'eye-open',
'i/hide' => 'eye-open',
't/show' => 'eye-close',
'i/show' => 'eye-close',
't/assignroles' => 'icon-glass',
't/add' => 'plus',
't/right' => 'arrow-right',
't/left' => 'arrow-left',
't/up' => 'arrow-up',
't/down' => 'arrow-down',
't/edit' => 'edit',
't/editstring' => 'tag',
't/copy' => 'repeat',
't/delete' => 'remove',
'i/edit' => 'pencil',
'i/settings' => 'list-alt',
'i/grades' => 'grades',
'i/group' => 'user',
't/groupn' => 'share-alt',
//'t/groupv' => '?',
't/switch_plus' => 'plus-sign',
't/switch_minus' => 'minus-sign',
'i/filter' => 'filter',
't/move' => 'resize-vertical',
'i/move_2d' => 'move',
'i/backup' => 'cog',
'i/restore' => 'cog',
'i/return' => 'repeat',
'i/reload' => 'refresh',
'i/roles' => 'user',
'i/user' => 'user',
'i/users' => 'user',
'i/publish' => 'publish',
'i/navigationitem' => 'chevron-right' );
public function block_controls($controls) {
if($this->page->theme->settings->enableglyphicons) {
if (empty($controls)) {
return '';
}
$controlshtml = array();
foreach ($controls as $control) {
$controlshtml[] = self::a(array('href'=>$control['url'], 'title'=>$control['caption']), self::moodle_icon($control['icon']));
}
return self::div(array('class'=>'commands'), implode($controlshtml));
} else {
return parent::block_controls($controls);
}
}
protected static function a($attributes, $content) {
return html_writer::tag('a', $content, $attributes);
}
protected static function div($attributes, $content) {
return html_writer::tag('div', $content, $attributes);
}
protected static function span($attributes, $content) {
return html_writer::tag('span', $content, $attributes);
}
protected static function icon($name, $text=null) {
if (!$text) {$text = $name;}
return "<i class=icon-$name></i>";
}
protected static function moodle_icon($name) {
return self::icon(self::$icons[$name]);
}
public function icon_help() {
return self::icon('question-sign');
}
public function action_icon($url, pix_icon $pixicon, component_action $action = null, array $attributes = null, $linktext=false) {
if($this->page->theme->settings->enableglyphicons) {
if (!($url instanceof moodle_url)) {
$url = new moodle_url($url);
}
$attributes = (array)$attributes;
if (empty($attributes['class'])) {
// let ppl override the class via $options
$attributes['class'] = 'action-icon';
}
$icon = $this->render($pixicon);
if ($linktext) {
$text = $pixicon->attributes['alt'];
} else {
$text = '';
}
return $this->action_link($url, $text.$icon, $action, $attributes);
} else {
return parent::action_icon($url, $pixicon, $action, $attributes , $linktext);
}
}
protected function render_pix_icon(pix_icon $icon) {
if($this->page->theme->settings->enableglyphicons) {
if (isset(self::$icons[$icon->pix])) {
return self::icon(self::$icons[$icon->pix]);
} else {
return parent::render_pix_icon($icon);
//return '<i class=icon-not-assigned data-debug-icon="'.$icon->pix.'"></i>';
}
} else {
return parent::render_pix_icon($icon);
}
}
}
?>