forked from microsoft/moodle-theme_boost_o365teams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderers.php
308 lines (261 loc) · 12.8 KB
/
renderers.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
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
306
307
308
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Boost o365teams.
*
* @package theme_boost_o365teams
* @copyright 2018 Enovation Solutions
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/course/renderer.php');
require_once($CFG->dirroot . '/mod/assign/renderer.php');
require_once($CFG->dirroot . '/mod/quiz/renderer.php');
class theme_boost_o365teams_mod_assign_renderer extends mod_assign_renderer {
/**
* Render the header.
*
* @param assign_header $header
* @return string
*/
public function render_assign_header(assign_header $header) {
$o = '';
if ($header->subpage) {
$this->page->navbar->add($header->subpage);
}
$heading = format_string($header->assign->name, false, array('context' => $header->context));
$this->page->set_title($heading);
$this->page->set_heading($this->page->course->fullname);
$o .= $this->output->header();
if ($header->preface) {
$o .= $header->preface;
}
if ($header->showintro) {
$o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
$o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
$o .= $header->postfix;
$o .= $this->output->box_end();
}
return $o;
}
}
class theme_boost_o365teams_core_course_renderer extends core_course_renderer {
public function course_section_cm($course, &$completioninfo, cm_info $mod, $sectionreturn, $displayoptions = array()) {
$output = '';
// We return empty string (because course module will not be displayed at all) if
// 1) The activity is not visible to users; and
// 2) The 'availableinfo' is empty, i.e. the activity was
// hidden in a way that leaves no info, such as using the
// eye icon.
if (!$mod->is_visible_on_course_page()) {
return $output;
}
$indentclasses = 'mod-indent';
if (!empty($mod->indent)) {
$indentclasses .= ' mod-indent-' . $mod->indent;
if ($mod->indent > 15) {
$indentclasses .= ' mod-indent-huge';
}
}
$output .= html_writer::start_tag('div');
if ($this->page->user_is_editing()) {
$output .= course_get_cm_move($mod, $sectionreturn);
}
$output .= html_writer::start_tag('div', array('class' => 'mod-indent-outer'));
// This div is used to indent the content.
$output .= html_writer::div('', $indentclasses);
// Start a wrapper for the actual content to keep the indentation consistent.
$output .= html_writer::start_tag('div');
// If there is content but NO link (eg label),
// then display the content here (BEFORE any icons).
// In this case cons must be
// displayed after the content so that it makes more sense visually
// and for accessibility reasons, e.g. if you have a one-line label
// it should work similarly (at least in terms of ordering) to an
// activity.
$contentpart = $this->course_section_cm_text($mod, $displayoptions);
$url = $mod->url;
$modicons = '';
if ($this->page->user_is_editing()) {
$editactions = course_get_cm_edit_actions($mod, $mod->indent, $sectionreturn);
$modicons .= ' ' . $this->course_section_cm_edit_actions($editactions, $mod, $displayoptions);
$modicons .= $mod->afterediticons;
}
$modicons .= $this->course_section_cm_completion($course, $completioninfo, $mod, $displayoptions);
if (!empty($modicons)) {
$output .= html_writer::span($modicons, 'actions');
}
// Display the link to the module (or do nothing if module has no url).
$cmname = $this->course_section_cm_name($mod, $displayoptions);
if (!empty($cmname)) {
// Start the div for the activity title, excluding the edit icons.
$output .= html_writer::start_tag('div', array('class' => 'activityinstance'));
$output .= $cmname;
// Module can put text after the link (e.g. forum unread).
$output .= $mod->afterlink;
// Closing the tag which contains everything but edit icons. Content part of the module should not be part of this.
$output .= html_writer::end_tag('div');
}
if (empty($url)) {
$output .= $contentpart;
}
// Show availability info (if module is not available).
$output .= $this->course_section_cm_availability($mod, $displayoptions);
// If there is content AND a link, then display the content here
// (AFTER any icons). Otherwise it was displayed before.
if (!empty($url)) {
$output .= $contentpart;
}
$output .= html_writer::end_tag('div');
// End of indentation div.
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('div');
return $output;
}
public function course_section_cm_name_title(cm_info $mod, $displayoptions = array()) {
$output = '';
$url = $mod->url;
if (!$mod->is_visible_on_course_page() || !$url) {
// Nothing to be displayed to the user.
return $output;
}
// Accessibility: for files get description via icon, this is very ugly hack!
$instancename = $mod->get_formatted_name();
$altname = $mod->modfullname;
// Avoid unnecessary duplication: if e.g. a forum name already
// includes the word forum (or Forum, etc) then it is unhelpful
// to include that in the accessible description that is added.
if (false !== strpos(core_text::strtolower($instancename),
core_text::strtolower($altname))) {
$altname = '';
}
// File type after name, for alphabetic lists (screen reader).
if ($altname) {
$altname = get_accesshide(' ' . $altname);
}
list($linkclasses, $textclasses) = $this->course_section_cm_classes($mod);
// Get on-click attribute value if specified and decode the onclick - it
// has already been encoded for display (puke).
$onclick = htmlspecialchars_decode($mod->onclick, ENT_QUOTES);
// Display link itself.
$activitylink = html_writer::empty_tag('img', array('src' => $mod->get_icon_url(),
'class' => 'iconlarge activityicon', 'alt' => ' ', 'role' => 'presentation')) .
html_writer::tag('span', $instancename . $altname, array('class' => 'instancename')) .
html_writer::tag('span', '', array('class' => 'fa fa-external-link popupicon'));
if ($mod->uservisible) {
$output .= html_writer::link($url, $activitylink, array('class' => $linkclasses, 'onclick' => $onclick));
} else {
// We may be displaying this just in order to show information
// about visibility, without the actual link ($mod->is_visible_on_course_page()).
$output .= html_writer::tag('div', $activitylink, array('class' => $textclasses));
}
return $output;
}
}
class theme_boost_o365teams_mod_quiz_renderer extends mod_quiz_renderer {
/**
* Ouputs the form for making an attempt
*
* @param quiz_attempt $attemptobj
* @param int $page Current page number
* @param array $slots Array of integers relating to questions
* @param int $id ID of the attempt
* @param int $nextpage Next page number
*/
public function attempt_form($attemptobj, $page, $slots, $id, $nextpage) {
$output = '';
// Start the form.
$output .= html_writer::start_tag('form',
array('action' => new moodle_url($attemptobj->processattempt_url(),
array('cmid' => $attemptobj->get_cmid())), 'method' => 'post',
'enctype' => 'multipart/form-data', 'accept-charset' => 'utf-8',
'id' => 'responseform'));
$output .= html_writer::start_tag('div');
// Print all the questions.
foreach ($slots as $slot) {
$output .= $attemptobj->render_question($slot, false, $this,
$attemptobj->attempt_url($slot, $page), $this);
}
$navmethod = $attemptobj->get_quiz()->navmethod;
$output .= $this->attempt_navigation_buttons_with_link($page, $attemptobj->is_last_page($page), $navmethod,
$attemptobj->view_url());
// Some hidden fields to trach what is going on.
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'attempt',
'value' => $attemptobj->get_attemptid()));
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'thispage',
'value' => $page, 'id' => 'followingpage'));
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'nextpage',
'value' => $nextpage));
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'timeup',
'value' => '0', 'id' => 'timeup'));
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey',
'value' => sesskey()));
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'scrollpos',
'value' => '', 'id' => 'scrollpos'));
// Add a hidden field with questionids. Do this at the end of the form, so
// if you navigate before the form has finished loading, it does not wipe all
// the student's answers.
$output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'slots',
'value' => implode(',', $attemptobj->get_active_slots($page))));
// Finish the form.
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('form');
$output .= $this->connection_warning();
return $output;
}
/**
* Display the prev/next buttons that go at the bottom of each page of the attempt.
* A new "return to quiz menu" button is added in the custom renderer function.
*
* This function is created based on attemp_navigation_buttons() function of parent class.
*
* @param int $page the page number. Starts at 0 for the first page.
* @param bool $lastpage is this the last page in the quiz?
* @param string $navmethod Optional quiz attribute, 'free' (default) or 'sequential'
* @param string|bool $viewurl URL to the view quiz page.
* @return string HTML fragment.
*/
protected function attempt_navigation_buttons_with_link($page, $lastpage, $navmethod = 'free', $viewurl = null) {
$output = '';
$output .= html_writer::start_tag('div', array('class' => 'submitbtns submitbtns_with_return'));
if ($page > 0 && $navmethod == 'free') {
$output .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'previous',
'value' => get_string('navigateprevious', 'quiz'), 'class' => 'mod_quiz-prev-nav btn btn-secondary'));
}
if ($lastpage) {
$nextlabel = get_string('endtest', 'quiz');
} else {
$nextlabel = get_string('navigatenext', 'quiz');
}
$output .= html_writer::empty_tag('input', array('type' => 'submit', 'name' => 'next',
'value' => $nextlabel, 'class' => 'mod_quiz-next-nav btn btn-primary'));
if ($viewurl) {
// Return button.
$output .= html_writer::link($viewurl, get_string('navigatereturn', 'theme_boost_o365teams'),
array('class' => 'btn btn-secondary mod_quiz-return-nav'));
}
$output .= html_writer::end_tag('div');
return $output;
}
public function no_questions_message($canedit, $editurl) {
$output = '';
$output .= $this->notification(get_string('noquestions', 'quiz'));
if ($canedit) {
$output .= $this->single_button($editurl, get_string('editquiz', 'quiz'), 'get', array("primary" => true));
}
return $output;
}
}