-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrenderers.php
More file actions
297 lines (258 loc) · 11.7 KB
/
renderers.php
File metadata and controls
297 lines (258 loc) · 11.7 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
<?php
class theme_rocket_core_renderer extends core_renderer {
/**
* Renders a custom menu object (located in outputcomponents.php)
*
* The custom menu this method override the render_custom_menu function
* in outputrenderers.php
* @staticvar int $menucount
* @param custom_menu $menu
* @return string
*/
protected function render_custom_menu(custom_menu $menu) {
// Generate custom My Courses dropdown
$mycourses = $this->page->navigation->get('mycourses');
$mycoursetitle = $this->page->theme->settings-> mycoursetitle;
if (isloggedin() && $mycourses && $mycourses->has_children()) {
$branchurl = new moodle_url('/my/index.php');
$branchsort = 10000;
if ($mycoursetitle == 'module') {
$branchlabel = get_string('mymodules', 'theme_rocket');
} else if ($mycoursetitle == 'unit') {
$branchlabel = get_string('myunits', 'theme_rocket');
} else if ($mycoursetitle == 'class') {
$branchlabel = get_string('myclasses', 'theme_rocket');
} else {
$branchlabel = get_string('mycourses', 'theme_rocket');
}
$branchtitle = $branchlabel;
$branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
foreach ($mycourses->children as $coursenode) {
$branch->add($coursenode->get_content(), $coursenode->action, $coursenode->get_title());
}
} else {
if ($mycoursetitle == 'module') {
$branchlabel = get_string('allmodules', 'theme_rocket');
} else if ($mycoursetitle == 'unit') {
$branchlabel = get_string('allunits', 'theme_rocket');
} else if ($mycoursetitle == 'class') {
$branchlabel = get_string('allclasses', 'theme_rocket');
} else {
$branchlabel = get_string('allcourses', 'theme_rocket');
}
$branchtitle = $branchlabel;
$branchurl = new moodle_url('/course/index.php');
$branchsort = 10000;
$branch = $menu->add($branchlabel, $branchurl, $branchtitle, $branchsort);
}
// If the menu has no children return an empty string
if (!$menu->has_children()) {
return '';
}
// Initialise this custom menu
$content = html_writer::start_tag('ul', array('class'=>'dropdown dropdown-horizontal'));
// Render each child
foreach ($menu->get_children() as $item) {
$content .= $this->render_custom_menu_item($item);
}
// Close the open tags
$content .= html_writer::end_tag('ul');
// Return the custom menu
return $content;
}
/**
* Renders a custom menu node as part of a submenu
*
* The custom menu this method override the render_custom_menu_item function
* in outputrenderers.php
*
* @see render_custom_menu()
*
* @staticvar int $submenucount
* @param custom_menu_item $menunode
* @return string
*/
protected function render_custom_menu_item(custom_menu_item $menunode) {
// Required to ensure we get unique trackable id's
static $submenucount = 0;
$content = html_writer::start_tag('li');
if ($menunode->has_children()) {
// 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::start_tag('span', array('class'=>'customitem'));
$content .= html_writer::link($url, $menunode->get_text(), array('title'=>$menunode->get_title()));
$content .= html_writer::end_tag('span');
$content .= html_writer::start_tag('ul');
foreach ($menunode->get_children() as $menunode) {
$content .= $this->render_custom_menu_item($menunode);
}
$content .= html_writer::end_tag('ul');
} else {
// 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;
}
/**
* Copied from core_renderer with one minor change - changed $this->output->render() call to $this->render()
*
* @param navigation_node $item
* @return string
*/
protected function render_navigation_node(navigation_node $item) {
$content = $item->get_content();
$title = $item->get_title();
if ($item->icon instanceof renderable && !$item->hideicon) {
$icon = $this->render($item->icon);
$content = $icon.$content; // use CSS for spacing of icons
}
if ($item->helpbutton !== null) {
$content = trim($item->helpbutton).html_writer::tag('span', $content, array('class'=>'clearhelpbutton'));
}
if ($content === '') {
return '';
}
if ($item->action instanceof action_link) {
//adds class dimmed to hidden courses and categories
$link = $item->action;
if ($item->hidden) {
$link->add_class('dimmed');
}
$content = $this->render($link);
} else if ($item->action instanceof moodle_url) {
$attributes = array();
if ($title !== '') {
$attributes['title'] = $title;
}
if ($item->hidden) {
$attributes['class'] = 'dimmed_text';
}
$content = html_writer::link($item->action, $content, $attributes);
} else if (is_string($item->action) || empty($item->action)) {
$attributes = array();
if ($title !== '') {
$attributes['title'] = $title;
}
if ($item->hidden) {
$attributes['class'] = 'dimmed_text';
}
$content = html_writer::tag('span', $content, $attributes);
}
return $content;
}
/**
* Reformat edit button to new status indicator
*/
public function edit_button(moodle_url $url) {
$edittoggle = 'enable';
if (!empty($this->page->theme->settings->edittoggle)) {
$edittoggle = $this->page->theme->settings->edittoggle;
}
if ($edittoggle == 'enable') {
$url->param('sesskey', sesskey());
$formclose ='</span><div id="editmode">'.get_string('editmode', 'theme_rocket').'<div id="edittoggle">'.get_string('edittoggle', 'theme_rocket').' </div></div>';
if ($this->page->user_is_editing()) {
$formopen = '<span id="editbuttonon">';
$url->param('edit', 'off');
$editstring = get_string('turneditingoff','theme_rocket');
} else {
$formopen ='<span id="editbuttonoff">';
$url->param('edit', 'on');
$editstring = get_string('turneditingon','theme_rocket');
}
return $formopen . $this->single_button($url, $editstring) . $formclose;
} else {
$url->param('sesskey', sesskey());
if ($this->page->user_is_editing()) {
$url->param('edit', 'off');
$editstring = get_string('turneditingoff');
} else {
$url->param('edit', 'on');
$editstring = get_string('turneditingon');
}
return $this->single_button($url, $editstring);
}
}
/**
* Outputs the page's footer
* @return string HTML fragment
*/
public function footer() {
global $CFG, $DB;
$output = $this->container_end_all(true);
$footer = $this->opencontainers->pop('header/footer');
if (debugging() and $DB and $DB->is_transaction_started()) {
// TODO: MDL-20625 print warning - transaction will be rolled back
}
// Provide some performance info if required
$performanceinfo = '';
if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) {
$perf = get_performance_info();
if (defined('MDL_PERFTOLOG') && !function_exists('register_shutdown_function')) {
error_log("PERF: " . $perf['txt']);
}
if (defined('MDL_PERFTOFOOT') || debugging() || $CFG->perfdebug > 7) {
$performanceinfo = rocket_performance_output($perf);
}
}
$perftoken = (property_exists($this, "unique_performance_info_token"))?$this->unique_performance_info_token:self::PERFORMANCE_INFO_TOKEN;
$endhtmltoken = (property_exists($this, "unique_end_html_token"))?$this->unique_end_html_token:self::END_HTML_TOKEN;
$footer = str_replace($perftoken, $performanceinfo, $footer);
$footer = str_replace($endhtmltoken, $this->page->requires->get_end_code(), $footer);
$this->page->set_state(moodle_page::STATE_DONE);
return $output . $footer;
}
/**
* The standard tags (typically performance information and validation links,
* if we are in developer debug mode) that should be output in the footer area
* of the page. Designed to be called in theme layout.php files.
* @return string HTML fragment.
*/
public function standard_footer_html() {
global $CFG;
// This function is normally called from a layout.php file in {@link header()}
// but some of the content won't be known until later, so we return a placeholder
// for now. This will be replaced with the real content in {@link footer()}.
$output = (property_exists($this, "unique_performance_info_token"))?$this->unique_performance_info_token:self::PERFORMANCE_INFO_TOKEN;
// Moodle 2.1 uses a magic accessor for $this->page->devicetypeinuse so we need to
// check for the existence of the function that uses as
// isset($this->page->devicetypeinuse) returns false
if (function_exists('get_user_device_type')?($this->page->devicetypeinuse=='legacy'):$this->page->legacythemeinuse) {
// The legacy theme is in use print the notification
$output .= html_writer::tag('div', get_string('legacythemeinuse'), array('class'=>'legacythemeinuse'));
}
// Get links to switch device types (only shown for users not on a default device)
if(method_exists($this, 'theme_switch_links')) {
$output .= $this->theme_switch_links();
}
// if (!empty($CFG->debugpageinfo)) {
// $output .= '<div class="performanceinfo">This page is: ' . $this->page->debug_summary() . '</div>';
// }
if (debugging(null, DEBUG_DEVELOPER)) { // Only in developer mode
$output .= '<div class="purgecaches"><a href="'.$CFG->wwwroot.'/admin/purgecaches.php?confirm=1&sesskey='.sesskey().'">'.get_string('purgecaches', 'admin').'</a></div>';
}
if (!empty($CFG->debugvalidators)) {
$output .= '<div class="validators"><ul>
<li><a href="http://validator.w3.org/check?verbose=1&ss=1&uri=' . urlencode(qualified_me()) . '">Validate HTML</a></li>
<li><a href="http://www.contentquality.com/mynewtester/cynthia.exe?rptmode=-1&url1=' . urlencode(qualified_me()) . '">Section 508 Check</a></li>
<li><a href="http://www.contentquality.com/mynewtester/cynthia.exe?rptmode=0&warnp2n3e=1&url1=' . urlencode(qualified_me()) . '">WCAG 1 (2,3) Check</a></li>
</ul></div>';
}
if (!empty($CFG->additionalhtmlfooter)) {
$output .= "\n".$CFG->additionalhtmlfooter;
}
return $output;
}
}