forked from brum1975/moodle-course_format_weeksrev
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrenderer.php
325 lines (287 loc) · 13.8 KB
/
renderer.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
<?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/>.
/**
* Renderer for outputting the weeksrev course format.
*
* @package format_weeksrev
* @copyright 2018 Arnaud Trouvé <moodle@arnaudtrouve.fr>
* based on code by Mat Cannings
* based on code from 2012 Dan Poltawski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/course/format/renderer.php');
require_once($CFG->dirroot.'/course/format/weeksrev/lib.php');
/**
* Basic renderer for weeksrev format.
*
* @copyright 2018 Arnaud Trouvé <moodle@arnaudtrouve.fr>
* based on code by Mat Cannings
* based on code from 2012 Dan Poltawski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class format_weeksrev_renderer extends format_section_renderer_base {
/**
* Generate the starting container html for a list of sections
* @return string HTML to output.
*/
protected function start_section_list() {
return html_writer::start_tag('ul', ['class' => 'weeksrev']);
}
/**
* Generate the closing container html for a list of sections
* @return string HTML to output.
*/
protected function end_section_list() {
return html_writer::end_tag('ul');
}
/**
* Generate the title for this section page
* @return string the page title
*/
protected function page_title() {
return get_string('weeklyoutline');
}
/**
* Generate the section title, wraps it in a link to the section page if page is to be displayed on a separate page
*
* @param stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @return string HTML to output.
*/
public function section_title($section, $course) {
return $this->render(course_get_format($course)->inplace_editable_render_section_name($section));
}
/**
* Generate the section title to be displayed on the section page, without a link
*
* @param stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @return string HTML to output.
*/
public function section_title_without_link($section, $course) {
return $this->render(course_get_format($course)->inplace_editable_render_section_name($section, false));
}
/**
* Generate the display of the header part of a section before
* course modules are included
*
* @param stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @param bool $onsectionpage true if being printed on a single-section page
* @param int $sectionreturn The section to return to after an action
* @return string HTML to output.
*/
protected function section_header($section, $course, $onsectionpage, $sectionreturn=null) {
$o = '';
$sectionstyle = '';
$courseformat = course_get_format($course);
if ($section->section != 0) {
// Only in the non-general sections.
if (!$section->visible) {
$sectionstyle .= ' hidden';
}
if ($courseformat->is_section_current($section)) {
$sectionstyle .= ' current';
} else if ($course->hidefuture && $courseformat->is_section_future($section)) {
$sectionstyle .= ' future';
}
}
$o .= html_writer::start_tag('li', ['id' => 'section-' . $section->section,
'class' => 'section main clearfix' . $sectionstyle, 'role' => 'region',
'aria-label' => get_section_name($course, $section)]);
// Create a span that contains the section title to be used to create the keyboard section move menu.
$o .= html_writer::tag('span', get_section_name($course, $section), ['class' => 'hidden sectionname']);
$leftcontent = $this->section_left_content($section, $course, $onsectionpage);
$o .= html_writer::tag('div', $leftcontent, ['class' => 'left side']);
$rightcontent = $this->section_right_content($section, $course, $onsectionpage);
$o .= html_writer::tag('div', $rightcontent, ['class' => 'right side']);
$o .= html_writer::start_tag('div', ['class' => 'content']);
// When not on a section page, we display the section titles except the general section if null.
$hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
// When on a section page, we only display the general section title, if title is not the default one.
$hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
$classes = ' accesshide';
if ($hasnamenotsecpg || $hasnamesecpg) {
$classes = '';
}
$sectionname = html_writer::tag('span', $this->section_title($section, $course));
$o .= $this->output->heading($sectionname, 3, 'sectionname' . $classes);
$o .= $this->section_availability($section);
$o .= html_writer::start_tag('div', ['class' => 'summary']);
$o .= $this->format_summary_text($section);
$o .= html_writer::end_tag('div');
return $o;
}
/**
* Generate a summary of a section for display on the 'coruse index page'
*
* @param stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @param array $mods (argument not used)
* @return string HTML to output.
*/
protected function section_summary($section, $course, $mods) {
$courseformat = course_get_format($course);
$classattr = 'section main section-summary clearfix';
$linkclasses = '';
// If section is hidden then display grey section link
if (!$section->visible) {
$classattr .= ' hidden';
$linkclasses .= ' dimmed_text';
}
if ($courseformat->is_section_current($section)) {
$classattr .= ' current';
} else if ($course->hidefuture && $courseformat->is_section_future($section)) {
$classattr .= ' future';
}
$title = get_section_name($course, $section);
$o = '';
$o .= html_writer::start_tag('li', ['id' => 'section-'.$section->section,
'class' => $classattr, 'role' => 'region', 'aria-label' => $title]);
$o .= html_writer::tag('div', '', ['class' => 'left side']);
$o .= html_writer::tag('div', '', ['class' => 'right side']);
$o .= html_writer::start_tag('div', ['class' => 'content']);
if ($section->uservisible) {
$title = html_writer::tag('a', $title,
['href' => course_get_url($course, $section->section), 'class' => $linkclasses]);
}
$o .= $this->output->heading($title, 3, 'section-title');
$o .= html_writer::start_tag('div', ['class' => 'summarytext']);
$o .= $this->format_summary_text($section);
$o .= html_writer::end_tag('div');
$o .= $this->section_activity_summary($section, $course, null);
$o .= $this->section_availability($section);
$o .= html_writer::end_tag('div');
$o .= html_writer::end_tag('li');
return $o;
}
/**
* Output the html for a single section page .
*
* @param stdClass $course The course entry from DB
* @param array $sections (argument not used)
* @param array $mods (argument not used)
* @param array $modnames (argument not used)
* @param array $modnamesused (argument not used)
* @param int $displaysection The section number in the course which is being displayed
*/
public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
$context = context_course::instance($course->id);
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
if ($course->hidefuture && $canviewhidden) {
echo html_writer::tag('ul',
html_writer::tag('li', get_string('futureweeks', 'format_weeksrev'), ['class' => 'future-legend']),
['class' => 'weeksrev']
);
}
parent::print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection);
}
/**
* Output the html for a multiple section page
*
* @param stdClass $course The course entry from DB
* @param array $sections (argument not used)
* @param array $mods (argument not used)
* @param array $modnames (argument not used)
* @param array $modnamesused (argument not used)
*/
public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
global $PAGE;
$modinfo = get_fast_modinfo($course);
$courseformat = course_get_format($course);
$course = $courseformat->get_course();
$context = context_course::instance($course->id);
// Title with completion help icon.
$completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon();
echo $this->output->heading($this->page_title(), 2, 'accesshide');
// Copy activity clipboard..
echo $this->course_activity_clipboard($course, 0);
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
if ($course->hidefuture && $canviewhidden) {
echo html_writer::tag('ul',
html_writer::tag('li', get_string('futureweeks', 'format_weeksrev'), ['class' => 'future-legend']),
['class' => 'weeksrev']
);
}
// Now the list of sections..
echo $this->start_section_list();
$numsections = $courseformat->get_last_section_number();
$sectionsinfo = $modinfo->get_section_info_all();
if (!$PAGE->user_is_editing()) {
$sectionsinfo = array_reverse($modinfo->get_section_info_all(), true);
$sectionsinfo = [array_pop($sectionsinfo)] + $sectionsinfo; // Move section 0 back to top.
}
foreach ($sectionsinfo as $section => $thissection) {
if ($section == 0) {
// 0-section is displayed a little different then the others.
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
echo $this->section_header($thissection, $course, false, 0);
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->courserenderer->course_section_add_cm_control($course, 0, 0);
echo $this->section_footer();
}
continue;
}
if ($section > $numsections) {
// Activities inside this section are 'orphaned', this section will be printed as 'stealth' below.
continue;
}
// Show the section if the user is permitted to access it, OR if it's not available
// but there is some available info text which explains the reason & should display.
$showsection = $thissection->uservisible ||
($thissection->visible && !$thissection->available &&
!empty($thissection->availableinfo));
if (!$showsection) {
// If the hiddensections option is set to 'show hidden sections in collapsed
// form', then display the hidden section message - UNLESS the section is
// hidden by the availability system, which is set to hide the reason.
if (!$course->hiddensections && $thissection->available) {
echo $this->section_hidden($section, $course->id);
}
continue;
}
if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
// Display section summary only.
echo $this->section_summary($thissection, $course, null);
} else {
echo $this->section_header($thissection, $course, false, 0);
if ($thissection->uservisible) {
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->courserenderer->course_section_add_cm_control($course, $section, 0);
}
echo $this->section_footer();
}
}
if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
// Print stealth sections if present.
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if ($section <= $numsections or empty($modinfo->sections[$section])) {
// this is not stealth section or it is empty
continue;
}
echo $this->stealth_section_header($section);
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->stealth_section_footer();
}
echo $this->end_section_list();
echo $this->change_number_sections($course, 0);
} else {
echo $this->end_section_list();
}
}
}