-
Notifications
You must be signed in to change notification settings - Fork 5
/
renderer.php
350 lines (312 loc) · 14.9 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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?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 2012 Dan Poltawski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.3
*/
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 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', array('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');
}
/**
* 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);
$course = course_get_format($course)->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);
// Now the list of sections..
echo $this->start_section_list();
$revmodinfo = array_reverse($modinfo->get_section_info_all());//reverse sections
array_unshift($revmodinfo,array_pop($revmodinfo));//move section 0 back to top
$started = $ended = false;
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
foreach ($revmodinfo 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);
print_section($course, $thissection, null, null, true, "100%", false, 0);
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, 0, null, false, false, 0);
}
echo $this->section_footer();
}
continue;
}
$thissectiondates = course_get_format($course)->get_section_dates($thissection);
$thefuture = $thissectiondates->start>time();
if($thefuture && !$started){
if($canviewhidden){
echo '<fieldset id="futureweeks"><legend>'.get_string('futureweeks', 'format_weeksrev').'</legend>';
$started = true;
}
}
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);
print_section($course, $thissection, null, null, true, "100%", false, 0);
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, 0, null, false, false, 0);
}
echo $this->section_footer();
}
continue;
}
if ($section > $course->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 showavailability is turned on (and there is some available info text).
$showsection = $thissection->uservisible ||
($thissection->visible && !$thissection->available && $thissection->showavailability
&& !empty($thissection->availableinfo));
if (!$showsection) {
// Hidden section message is overridden by 'unavailable' control
// (showavailability option).
if (!$course->hiddensections && $thissection->available) {
echo $this->section_hidden($section);
}
continue;
}
if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
if ($canviewhidden || !$thefuture){
// Display section summary only.
echo $this->section_summary($thissection, $course, null);
}
} else {
if(($canviewhidden && $started && !$ended || $ended) ){
echo $this->section_header($thissection, $course, false, 0);
if ($thissection->uservisible) {
print_section($course, $thissection, null, null, true, "100%", false, 0);
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, $section, null, false, false, 0);
}
}
echo $this->section_footer();
}
}
if($thissectiondates->start<(time() + (7 * 24 * 60 * 60)) && !$ended){
if($canviewhidden){
echo '</fieldset>';
}
$ended = true;
}
}
if(!$ended){
if($canviewhidden){
echo '</fieldset>';
}
$ended = true;
}
echo $this->end_section_list();
}
/**
* Output the html for a single section page .
*
* @param stdClass $course The course entry from DB
* @param array $sections The course_sections entries from the DB
* @param array $mods used for print_section()
* @param array $modnames used for print_section()
* @param array $modnamesused used for print_section()
* @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) {
global $PAGE;
$modinfo = get_fast_modinfo($course);
$course = course_get_format($course)->get_course();
// Can we view the section in question?
$context = context_course::instance($course->id);
$canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
$thissectiondates = course_get_format($course)->get_section_dates($displaysection);
if($thissectiondates->start>time()){
$thefuture = true;
} else {
$thefuture = false;
}
// Can we view the section in question?
if (!($sectioninfo = $modinfo->get_section_info($displaysection))) {
// This section doesn't exist
print_error('unknowncoursesection', 'error', null, $course->fullname);
return;
}
if (!$sectioninfo->uservisible) {
if (!$course->hiddensections) {
echo $this->start_section_list();
echo $this->section_hidden($displaysection);
echo $this->end_section_list();
}
// Can't view this section.
return;
}
// Copy activity clipboard..
echo $this->course_activity_clipboard($course, $displaysection);
// General section if non-empty.
$thissection = $modinfo->get_section_info(0);
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
echo $this->start_section_list();
echo $this->section_header($thissection, $course, true, $displaysection);
print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection);
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, 0, $modnames, false, false, $displaysection);
}
echo $this->section_footer();
echo $this->end_section_list();
}
if ($thefuture){
if($canviewhidden){
echo '<fieldset id="futureweeks"><legend>'.get_string('futureweek', 'format_weeksrev').'</legend>';
}
}
// Start single-section div
echo html_writer::start_tag('div', array('class' => 'single-section'));
// Title with section navigation links.
$sectionnavlinks = $this->get_nav_links($course, $sections, $displaysection);
$sectiontitle = '';
$sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock'));
$sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
$sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
// Title attributes
$titleattr = 'mdl-align title';
if (!$sections[$displaysection]->visible) {
$titleattr .= ' dimmed_text';
}
$sectiontitle .= html_writer::tag('div', get_section_name($course, $sections[$displaysection]), array('class' => $titleattr));
$sectiontitle .= html_writer::end_tag('div');
echo $sectiontitle;
// Now the list of sections..
echo $this->start_section_list();
// The requested section page.
$thissection = $sections[$displaysection];
echo $this->section_header($thissection, $course, true, $displaysection);
// Show completion help icon.
$completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon();
print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, $displaysection);
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, $displaysection, $modnames, false, false, $displaysection);
}
echo $this->section_footer();
echo $this->end_section_list();
// Display section bottom navigation.
$courselink = html_writer::link(course_get_url($course), get_string('returntomaincoursepage'));
$sectionbottomnav = '';
$sectionbottomnav .= html_writer::start_tag('div', array('class' => 'section-navigation mdl-bottom'));
$sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
$sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
$sectionbottomnav .= html_writer::tag('div', $courselink, array('class' => 'mdl-align'));
$sectionbottomnav .= html_writer::end_tag('div');
echo $sectionbottomnav;
// close single-section div.
echo html_writer::end_tag('div');
if ($thefuture){
if($canviewhidden){
echo '</fieldset>';
}
}
}
/**
* Generate next/previous section links for naviation
*
* @param stdClass $course The course entry from DB
* @param array $sections The course_sections entries from the DB
* @param int $sectionno The section number in the coruse which is being dsiplayed
* @return array associative array with previous and next section link
*/
protected function get_nav_links($course, $sections, $sectionno) {
// FIXME: This is really evil and should by using the navigation API.
$canviewhidden = has_capability('moodle/course:viewhiddensections', context_course::instance($course->id))
or !$course->hiddensections;
$links = array('previous' => '', 'next' => '');
$back = $sectionno - 1;
while ($back > 0 and empty($links['previous'])) {
if ($canviewhidden || $sections[$back]->uservisible) {
$params = array();
if (!$sections[$back]->visible) {
$params = array('class' => 'dimmed_text');
}
$previouslink = html_writer::tag('span', $this->output->larrow(), array('class' => 'larrow'));
$previouslink .= get_section_name($course, $sections[$back]);
$links['previous'] = html_writer::link(course_get_url($course, $back), $previouslink, $params);
}
$back--;
}
$forward = $sectionno + 1;
while ($forward <= $course->numsections and empty($links['next'])) {
$nextsectiondates = course_get_format($course)->get_section_dates($sections[$forward]);
$shownext = $nextsectiondates->start<time();
if($shownext || $canviewhidden){
if ($canviewhidden || $sections[$forward]->uservisible) {
$params = array();
if (!$sections[$forward]->visible) {
$params = array('class' => 'dimmed_text');
}
$nextlink = get_section_name($course, $sections[$forward]);
$nextlink .= html_writer::tag('span', $this->output->rarrow(), array('class' => 'rarrow'));
$links['next'] = html_writer::link(course_get_url($course, $forward), $nextlink, $params);
}
}
$forward++;
}
return $links;
}
}