weekly release 2.4dev
[moodle.git] / course / format / renderer.php
CommitLineData
1804b7c1
DP
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Base renderer for outputting course formats.
19 *
20 * @package core
21 * @copyright 2012 Dan Poltawski
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 * @since Moodle 2.3
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28
29/**
a8f02a34 30 * This is a convenience renderer which can be used by section based formats
3df72f8c 31 * to reduce code duplication. It is not necessary for all course formats to
a8f02a34 32 * use this and its likely to change in future releases.
1804b7c1
DP
33 *
34 * @package core
35 * @copyright 2012 Dan Poltawski
36 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37 * @since Moodle 2.3
38 */
a8f02a34 39abstract class format_section_renderer_base extends plugin_renderer_base {
1804b7c1
DP
40
41 /**
42 * Generate the starting container html for a list of sections
43 * @return string HTML to output.
44 */
cbf44997 45 abstract protected function start_section_list();
1804b7c1
DP
46
47 /**
48 * Generate the closing container html for a list of sections
49 * @return string HTML to output.
50 */
cbf44997 51 abstract protected function end_section_list();
1804b7c1
DP
52
53 /**
54 * Generate the title for this section page
55 * @return string the page title
56 */
cbf44997 57 abstract protected function page_title();
1804b7c1 58
9f3015ec
RK
59 /**
60 * Generate the section title
61 *
62 * @param stdClass $section The course_section entry from DB
63 * @param stdClass $course The course entry from DB
64 * @return string HTML to output.
65 */
66 public function section_title($section, $course) {
67 $title = get_section_name($course, $section);
68 if ($section->section != 0 && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
69 $title = html_writer::link(course_get_url($course, $section->section), $title);
70 }
71 return $title;
72 }
73
a830d866
DP
74 /**
75 * Generate the content to displayed on the right part of a section
a830d866 76 * before course modules are included
96e12851 77 *
a830d866
DP
78 * @param stdClass $section The course_section entry from DB
79 * @param stdClass $course The course entry from DB
80 * @param bool $onsectionpage true if being printed on a section page
81 * @return string HTML to output.
82 */
cbf44997 83 protected function section_right_content($section, $course, $onsectionpage) {
a830d866
DP
84 $o = $this->output->spacer();
85
86 if ($section->section != 0) {
87 $controls = $this->section_edit_controls($course, $section, $onsectionpage);
88 if (!empty($controls)) {
89 $o = implode('<br />', $controls);
90 }
91 }
92
93 return $o;
94 }
95
96 /**
97 * Generate the content to displayed on the left part of a section
a830d866 98 * before course modules are included
96e12851 99 *
a830d866
DP
100 * @param stdClass $section The course_section entry from DB
101 * @param stdClass $course The course entry from DB
102 * @param bool $onsectionpage true if being printed on a section page
103 * @return string HTML to output.
104 */
cbf44997 105 protected function section_left_content($section, $course, $onsectionpage) {
a830d866
DP
106 $o = $this->output->spacer();
107
108 if ($section->section != 0) {
109 // Only in the non-general sections.
2ea6533a 110 if ($this->is_section_current($section, $course)) {
a830d866
DP
111 $o = get_accesshide(get_string('currentsection', 'format_'.$course->format));
112 }
113 }
114
115 return $o;
116 }
117
1804b7c1
DP
118 /**
119 * Generate the display of the header part of a section before
120 * course modules are included
121 *
122 * @param stdClass $section The course_section entry from DB
123 * @param stdClass $course The course entry from DB
9f3015ec 124 * @param bool $onsectionpage true if being printed on a single-section page
b8514b6a 125 * @param int $sectionreturn The section to return to after an action
1804b7c1
DP
126 * @return string HTML to output.
127 */
b8514b6a 128 protected function section_header($section, $course, $onsectionpage, $sectionreturn=0) {
1804b7c1
DP
129 global $PAGE;
130
131 $o = '';
132 $currenttext = '';
133 $sectionstyle = '';
1804b7c1 134
96e12851 135 if ($section->section != 0) {
1804b7c1
DP
136 // Only in the non-general sections.
137 if (!$section->visible) {
138 $sectionstyle = ' hidden';
2ea6533a 139 } else if ($this->is_section_current($section, $course)) {
1804b7c1 140 $sectionstyle = ' current';
1804b7c1 141 }
1804b7c1
DP
142 }
143
144 $o.= html_writer::start_tag('li', array('id' => 'section-'.$section->section,
145 'class' => 'section main clearfix'.$sectionstyle));
a830d866
DP
146
147 $leftcontent = $this->section_left_content($section, $course, $onsectionpage);
1804b7c1 148 $o.= html_writer::tag('div', $leftcontent, array('class' => 'left side'));
a830d866
DP
149
150 $rightcontent = $this->section_right_content($section, $course, $onsectionpage);
1804b7c1
DP
151 $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
152 $o.= html_writer::start_tag('div', array('class' => 'content'));
153
5946d376
FM
154 // When not on a section page, we display the section titles except the general section if null
155 $hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));
156
157 // When on a section page, we only display the general section title, if title is not the default one
158 $hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));
159
160 if ($hasnamenotsecpg || $hasnamesecpg) {
9f3015ec 161 $o.= $this->output->heading($this->section_title($section, $course), 3, 'sectionname');
1804b7c1
DP
162 }
163
164 $o.= html_writer::start_tag('div', array('class' => 'summary'));
7cb8bfdb 165 $o.= $this->format_summary_text($section);
1804b7c1 166
7cb8bfdb 167 $context = context_course::instance($course->id);
1804b7c1 168 if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
b8514b6a 169 $url = new moodle_url('/course/editsection.php', array('id'=>$section->id, 'sr'=>$sectionreturn));
1804b7c1
DP
170 $o.= html_writer::link($url,
171 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'), 'class' => 'iconsmall edit')),
172 array('title' => get_string('editsummary')));
173 }
174 $o.= html_writer::end_tag('div');
175
ce4dfd27 176 $o .= $this->section_availability_message($section);
177
1804b7c1
DP
178 return $o;
179 }
180
181 /**
182 * Generate the display of the footer part of a section
183 *
184 * @return string HTML to output.
185 */
cbf44997 186 protected function section_footer() {
1804b7c1
DP
187 $o = html_writer::end_tag('div');
188 $o.= html_writer::end_tag('li');
189
190 return $o;
191 }
192
193 /**
194 * Generate the edit controls of a section
195 *
196 * @param stdClass $course The course entry from DB
197 * @param stdClass $section The course_section entry from DB
198 * @param bool $onsectionpage true if being printed on a section page
199 * @return array of links with edit controls
200 */
cbf44997 201 protected function section_edit_controls($course, $section, $onsectionpage = false) {
1804b7c1
DP
202 global $PAGE;
203
204 if (!$PAGE->user_is_editing()) {
205 return array();
206 }
207
208 if (!has_capability('moodle/course:update', context_course::instance($course->id))) {
209 return array();
210 }
211
212 if ($onsectionpage) {
213 $baseurl = course_get_url($course, $section->section);
214 } else {
215 $baseurl = course_get_url($course);
216 }
217 $baseurl->param('sesskey', sesskey());
218
219 $controls = array();
220
221 $url = clone($baseurl);
222 if ($section->visible) { // Show the hide/show eye.
223 $strhidefromothers = get_string('hidefromothers', 'format_'.$course->format);
224 $url->param('hide', $section->section);
225 $controls[] = html_writer::link($url,
226 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/hide'),
227 'class' => 'icon hide', 'alt' => $strhidefromothers)),
228 array('title' => $strhidefromothers, 'class' => 'editing_showhide'));
229 } else {
230 $strshowfromothers = get_string('showfromothers', 'format_'.$course->format);
231 $url->param('show', $section->section);
232 $controls[] = html_writer::link($url,
233 html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/show'),
234 'class' => 'icon hide', 'alt' => $strshowfromothers)),
235 array('title' => $strshowfromothers, 'class' => 'editing_showhide'));
236 }
237
238 if (!$onsectionpage) {
239 $url = clone($baseurl);
240 if ($section->section > 1) { // Add a arrow to move section up.
241 $url->param('section', $section->section);
242 $url->param('move', -1);
243 $strmoveup = get_string('moveup');
244
245 $controls[] = html_writer::link($url,
246 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/up'),
247 'class' => 'icon up', 'alt' => $strmoveup)),
248 array('title' => $strmoveup, 'class' => 'moveup'));
249 }
250
251 $url = clone($baseurl);
252 if ($section->section < $course->numsections) { // Add a arrow to move section down.
253 $url->param('section', $section->section);
254 $url->param('move', 1);
255 $strmovedown = get_string('movedown');
256
257 $controls[] = html_writer::link($url,
258 html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/down'),
259 'class' => 'icon down', 'alt' => $strmovedown)),
260 array('title' => $strmovedown, 'class' => 'movedown'));
261 }
262 }
263
264 return $controls;
265 }
266
267 /**
268 * Generate a summary of a section for display on the 'coruse index page'
269 *
270 * @param stdClass $section The course_section entry from DB
271 * @param stdClass $course The course entry from DB
d87debaa 272 * @param array $mods course modules indexed by id (from get_all_mods)
1804b7c1
DP
273 * @return string HTML to output.
274 */
d87debaa 275 protected function section_summary($section, $course, $mods) {
76055f5d
FM
276 $classattr = 'section main section-summary clearfix';
277 $linkclasses = '';
278
bcf7175f 279 // If section is hidden then display grey section link
76055f5d
FM
280 if (!$section->visible) {
281 $classattr .= ' hidden';
282 $linkclasses .= ' dimmed_text';
283 } else if ($this->is_section_current($section, $course)) {
284 $classattr .= ' current';
bcf7175f 285 }
1804b7c1
DP
286
287 $o = '';
76055f5d 288 $o .= html_writer::start_tag('li', array('id' => 'section-'.$section->section, 'class' => $classattr));
1804b7c1 289
76055f5d
FM
290 $o .= html_writer::tag('div', '', array('class' => 'left side'));
291 $o .= html_writer::tag('div', '', array('class' => 'right side'));
292 $o .= html_writer::start_tag('div', array('class' => 'content'));
293
294 $title = html_writer::tag('a', get_section_name($course, $section),
295 array('href' => course_get_url($course, $section->section), 'class' => $linkclasses));
296 $o .= $this->output->heading($title, 3, 'section-title');
1804b7c1
DP
297
298 $o.= html_writer::start_tag('div', array('class' => 'summarytext'));
7cb8bfdb 299 $o.= $this->format_summary_text($section);
1804b7c1 300 $o.= html_writer::end_tag('div');
7c05cd0e 301 $o.= $this->section_activity_summary($section, $course, $mods);
ce4dfd27 302
d87debaa 303 $o.= $this->section_availability_message($section);
ce4dfd27 304
76055f5d
FM
305 $o .= html_writer::end_tag('div');
306 $o .= html_writer::end_tag('li');
1804b7c1
DP
307
308 return $o;
309 }
310
d87debaa
DP
311 /**
312 * Generate a summary of the activites in a section
313 *
314 * @param stdClass $section The course_section entry from DB
7c05cd0e 315 * @param stdClass $course the course record from DB
d87debaa
DP
316 * @param array $mods course modules indexed by id (from get_all_mods)
317 * @return string HTML to output.
318 */
7c05cd0e 319 private function section_activity_summary($section, $course, $mods) {
d87debaa
DP
320 if (empty($section->sequence)) {
321 return '';
322 }
323
324 // Generate array with count of activities in this section:
325 $sectionmods = array();
7c05cd0e
AA
326 $total = 0;
327 $complete = 0;
0e5533b6
SH
328 $cancomplete = isloggedin() && !isguestuser();
329 $completioninfo = new completion_info($course);
d87debaa
DP
330 $modsequence = explode(',', $section->sequence);
331 foreach ($modsequence as $cmid) {
332 $thismod = $mods[$cmid];
333
00c41b40
DP
334 if ($thismod->modname == 'label') {
335 // Labels are special (not interesting for students)!
336 continue;
337 }
338
d87debaa
DP
339 if ($thismod->uservisible) {
340 if (isset($sectionmods[$thismod->modname])) {
341 $sectionmods[$thismod->modname]['count']++;
342 } else {
343 $sectionmods[$thismod->modname]['name'] = $thismod->modplural;
344 $sectionmods[$thismod->modname]['count'] = 1;
345 }
0e5533b6 346 if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) {
7c05cd0e 347 $total++;
0e5533b6 348 $completiondata = $completioninfo->get_data($thismod, true);
7c05cd0e
AA
349 if ($completiondata->completionstate == COMPLETION_COMPLETE) {
350 $complete++;
351 }
352 }
d87debaa
DP
353 }
354 }
355
356 if (empty($sectionmods)) {
357 // No sections
358 return '';
359 }
360
361 // Output section activities summary:
362 $o = '';
363 $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
364 foreach ($sectionmods as $mod) {
365 $o.= html_writer::start_tag('span', array('class' => 'activity-count'));
366 $o.= $mod['name'].': '.$mod['count'];
367 $o.= html_writer::end_tag('span');
368 }
dce49c1c 369 $o.= html_writer::end_tag('div');
7c05cd0e
AA
370
371 // Output section completion data
0e5533b6
SH
372 if ($total > 0) {
373 $a = new stdClass;
374 $a->complete = $complete;
375 $a->total = $total;
376
dce49c1c 377 $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right'));
0e5533b6 378 $o.= html_writer::tag('span', get_string('progresstotal', 'completion', $a), array('class' => 'activity-count'));
dce49c1c 379 $o.= html_writer::end_tag('div');
7c05cd0e 380 }
dce49c1c 381
d87debaa
DP
382 return $o;
383 }
384
ce4dfd27 385 /**
386 * If section is not visible to current user, display the message about that
387 * ('Not available until...', that sort of thing). Otherwise, returns blank.
388 *
389 * @param stdClass $section The course_section entry from DB
390 * @return string HTML to output
391 */
392 protected function section_availability_message($section) {
393 $o = '';
5316007e 394 if (!$section->uservisible || $section->availableinfo) {
ce4dfd27 395 $o .= html_writer::start_tag('div', array('class' => 'availabilityinfo'));
396 if (!empty($section->availableinfo)) {
397 $o .= $section->availableinfo;
398 } else {
399 $o .= get_string('notavailable');
400 }
401 $o .= html_writer::end_tag('div');
402 }
403 return $o;
404 }
405
1804b7c1
DP
406 /**
407 * Show if something is on on the course clipboard (moving around)
408 *
409 * @param stdClass $course The course entry from DB
410 * @param int $sectionno The section number in the coruse which is being dsiplayed
411 * @return string HTML to output.
412 */
cbf44997 413 protected function course_activity_clipboard($course, $sectionno = 0) {
1804b7c1
DP
414 global $USER;
415
416 $o = '';
417 // If currently moving a file then show the current clipboard.
418 if (ismoving($course->id)) {
419 $url = new moodle_url('/course/mod.php',
420 array('sesskey' => sesskey(),
421 'cancelcopy' => true,
422 'sr' => $sectionno,
423 )
424 );
425
76055f5d 426 $o.= html_writer::start_tag('div', array('class' => 'clipboard'));
1804b7c1
DP
427 $o.= strip_tags(get_string('activityclipboard', '', $USER->activitycopyname));
428 $o.= ' ('.html_writer::link($url, get_string('cancel')).')';
76055f5d 429 $o.= html_writer::end_tag('div');
1804b7c1
DP
430 }
431
432 return $o;
433 }
434
435 /**
436 * Generate next/previous section links for naviation
437 *
438 * @param stdClass $course The course entry from DB
439 * @param array $sections The course_sections entries from the DB
440 * @param int $sectionno The section number in the coruse which is being dsiplayed
36be7e14 441 * @return array associative array with previous and next section link
1804b7c1 442 */
cbf44997 443 protected function get_nav_links($course, $sections, $sectionno) {
1804b7c1
DP
444 // FIXME: This is really evil and should by using the navigation API.
445 $canviewhidden = has_capability('moodle/course:viewhiddensections', context_course::instance($course->id))
446 or !$course->hiddensections;
447
448 $links = array('previous' => '', 'next' => '');
449 $back = $sectionno - 1;
450 while ($back > 0 and empty($links['previous'])) {
451 if ($canviewhidden || $sections[$back]->visible) {
bcf7175f
RT
452 $params = array();
453 if (!$sections[$back]->visible) {
454 $params = array('class' => 'dimmed_text');
455 }
36be7e14
RT
456 $previouslink = html_writer::tag('span', $this->output->larrow(), array('class' => 'larrow'));
457 $previouslink .= get_section_name($course, $sections[$back]);
bcf7175f 458 $links['previous'] = html_writer::link(course_get_url($course, $back), $previouslink, $params);
1804b7c1
DP
459 }
460 $back--;
461 }
462
463 $forward = $sectionno + 1;
464 while ($forward <= $course->numsections and empty($links['next'])) {
465 if ($canviewhidden || $sections[$forward]->visible) {
bcf7175f
RT
466 $params = array();
467 if (!$sections[$forward]->visible) {
468 $params = array('class' => 'dimmed_text');
469 }
36be7e14
RT
470 $nextlink = get_section_name($course, $sections[$forward]);
471 $nextlink .= html_writer::tag('span', $this->output->rarrow(), array('class' => 'rarrow'));
bcf7175f 472 $links['next'] = html_writer::link(course_get_url($course, $forward), $nextlink, $params);
1804b7c1
DP
473 }
474 $forward++;
475 }
476
36be7e14 477 return $links;
1804b7c1
DP
478 }
479
480 /**
481 * Generate the header html of a stealth section
482 *
483 * @param int $sectionno The section number in the coruse which is being dsiplayed
484 * @return string HTML to output.
485 */
cbf44997 486 protected function stealth_section_header($sectionno) {
1804b7c1
DP
487 $o = '';
488 $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix orphaned hidden'));
489 $o.= html_writer::tag('div', '', array('class' => 'left side'));
490 $o.= html_writer::tag('div', '', array('class' => 'right side'));
491 $o.= html_writer::start_tag('div', array('class' => 'content'));
492 $o.= $this->output->heading(get_string('orphanedactivities'), 3, 'sectionname');
493 return $o;
494 }
495
496 /**
497 * Generate footer html of a stealth section
498 *
499 * @return string HTML to output.
500 */
cbf44997 501 protected function stealth_section_footer() {
1804b7c1
DP
502 $o = html_writer::end_tag('div');
503 $o.= html_writer::end_tag('li');
504 return $o;
505 }
506
507 /**
508 * Generate the html for a hidden section
509 *
510 * @param int $sectionno The section number in the coruse which is being dsiplayed
511 * @return string HTML to output.
512 */
cbf44997 513 protected function section_hidden($sectionno) {
1804b7c1
DP
514 $o = '';
515 $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix hidden'));
516 $o.= html_writer::tag('div', '', array('class' => 'left side'));
517 $o.= html_writer::tag('div', '', array('class' => 'right side'));
518 $o.= html_writer::start_tag('div', array('class' => 'content'));
519 $o.= get_string('notavailable');
520 $o.= html_writer::end_tag('div');
521 $o.= html_writer::end_tag('li');
522 return $o;
523 }
524
525 /**
526 * Output the html for a single section page .
527 *
528 * @param stdClass $course The course entry from DB
529 * @param array $sections The course_sections entries from the DB
530 * @param array $mods used for print_section()
531 * @param array $modnames used for print_section()
532 * @param array $modnamesused used for print_section()
533 * @param int $displaysection The section number in the course which is being displayed
534 */
535 public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
536 global $PAGE;
537
1804b7c1
DP
538 // Can we view the section in question?
539 $context = context_course::instance($course->id);
540 $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
541
0c053c53
ARN
542 if (!isset($sections[$displaysection])) {
543 // This section doesn't exist
544 print_error('unknowncoursesection', 'error', null, $course->fullname);
545 return;
546 }
547
1804b7c1
DP
548 if (!$sections[$displaysection]->visible && !$canviewhidden) {
549 if (!$course->hiddensections) {
550 echo $this->start_section_list();
551 echo $this->section_hidden($displaysection);
552 echo $this->end_section_list();
1804b7c1
DP
553 }
554 // Can't view this section.
555 return;
556 }
557
76055f5d
FM
558 // Copy activity clipboard..
559 echo $this->course_activity_clipboard($course, $displaysection);
560
243b7003
DP
561 // General section if non-empty.
562 $thissection = $sections[0];
563 if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
564 echo $this->start_section_list();
b8514b6a
FM
565 echo $this->section_header($thissection, $course, true, $displaysection);
566 print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection);
243b7003 567 if ($PAGE->user_is_editing()) {
b8514b6a 568 print_section_add_menus($course, 0, $modnames, false, false, $displaysection);
243b7003
DP
569 }
570 echo $this->section_footer();
571 echo $this->end_section_list();
572 }
573
c129f430
RT
574 // Start single-section div
575 echo html_writer::start_tag('div', array('class' => 'single-section'));
576
36be7e14 577 // Title with section navigation links.
243b7003 578 $sectionnavlinks = $this->get_nav_links($course, $sections, $displaysection);
36be7e14 579 $sectiontitle = '';
c129f430 580 $sectiontitle .= html_writer::start_tag('div', array('class' => 'section-navigation header headingblock'));
36be7e14
RT
581 $sectiontitle .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
582 $sectiontitle .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
bcf7175f
RT
583 // Title attributes
584 $titleattr = 'mdl-align title';
585 if (!$sections[$displaysection]->visible) {
586 $titleattr .= ' dimmed_text';
587 }
588 $sectiontitle .= html_writer::tag('div', get_section_name($course, $sections[$displaysection]), array('class' => $titleattr));
36be7e14
RT
589 $sectiontitle .= html_writer::end_tag('div');
590 echo $sectiontitle;
591
1804b7c1
DP
592 // Now the list of sections..
593 echo $this->start_section_list();
594
1804b7c1
DP
595 // The requested section page.
596 $thissection = $sections[$displaysection];
b8514b6a 597 echo $this->section_header($thissection, $course, true, $displaysection);
c129f430
RT
598 // Show completion help icon.
599 $completioninfo = new completion_info($course);
600 echo $completioninfo->display_help_icon();
601
b8514b6a 602 print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, $displaysection);
1804b7c1 603 if ($PAGE->user_is_editing()) {
b8514b6a 604 print_section_add_menus($course, $displaysection, $modnames, false, false, $displaysection);
1804b7c1
DP
605 }
606 echo $this->section_footer();
1804b7c1 607 echo $this->end_section_list();
36be7e14
RT
608
609 // Display section bottom navigation.
610 $courselink = html_writer::link(course_get_url($course), get_string('returntomaincoursepage'));
611 $sectionbottomnav = '';
612 $sectionbottomnav .= html_writer::start_tag('div', array('class' => 'section-navigation mdl-bottom'));
613 $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['previous'], array('class' => 'mdl-left'));
614 $sectionbottomnav .= html_writer::tag('span', $sectionnavlinks['next'], array('class' => 'mdl-right'));
615 $sectionbottomnav .= html_writer::tag('div', $courselink, array('class' => 'mdl-align'));
616 $sectionbottomnav .= html_writer::end_tag('div');
617 echo $sectionbottomnav;
c129f430
RT
618
619 // close single-section div.
620 echo html_writer::end_tag('div');
1804b7c1
DP
621 }
622
623 /**
624 * Output the html for a multiple section page
625 *
626 * @param stdClass $course The course entry from DB
627 * @param array $sections The course_sections entries from the DB
628 * @param array $mods used for print_section()
629 * @param array $modnames used for print_section()
630 * @param array $modnamesused used for print_section()
631 */
632 public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
633 global $PAGE;
634
635 $context = context_course::instance($course->id);
636 // Title with completion help icon.
637 $completioninfo = new completion_info($course);
638 echo $completioninfo->display_help_icon();
803e36e1 639 echo $this->output->heading($this->page_title(), 2, 'accesshide');
1804b7c1
DP
640
641 // Copy activity clipboard..
642 echo $this->course_activity_clipboard($course);
643
644 // Now the list of sections..
645 echo $this->start_section_list();
646
647 // General section if non-empty.
648 $thissection = $sections[0];
649 unset($sections[0]);
650 if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
5946d376 651 echo $this->section_header($thissection, $course, false);
1804b7c1
DP
652 print_section($course, $thissection, $mods, $modnamesused, true);
653 if ($PAGE->user_is_editing()) {
654 print_section_add_menus($course, 0, $modnames);
655 }
656 echo $this->section_footer();
657 }
658
659 $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
660 for ($section = 1; $section <= $course->numsections; $section++) {
661 if (!empty($sections[$section])) {
662 $thissection = $sections[$section];
663 } else {
664 // This will create a course section if it doesn't exist..
665 $thissection = get_course_section($section, $course->id);
52f14061 666
667 // The returned section is only a bare database object rather than
668 // a section_info object - we will need at least the uservisible
669 // field in it.
670 $thissection->uservisible = true;
57a42a24 671 $thissection->availableinfo = null;
672 $thissection->showavailability = 0;
1804b7c1 673 }
ce4dfd27 674 // Show the section if the user is permitted to access it, OR if it's not available
675 // but showavailability is turned on
676 $showsection = $thissection->uservisible ||
677 ($thissection->visible && !$thissection->available && $thissection->showavailability);
678 if (!$showsection) {
679 // Hidden section message is overridden by 'unavailable' control
680 // (showavailability option).
681 if (!$course->hiddensections && $thissection->available) {
1804b7c1
DP
682 echo $this->section_hidden($section);
683 }
684
685 unset($sections[$section]);
686 continue;
687 }
688
689 if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
690 // Display section summary only.
d87debaa 691 echo $this->section_summary($thissection, $course, $mods);
1804b7c1
DP
692 } else {
693 echo $this->section_header($thissection, $course, false);
ce4dfd27 694 if ($thissection->uservisible) {
695 print_section($course, $thissection, $mods, $modnamesused);
696 if ($PAGE->user_is_editing()) {
697 print_section_add_menus($course, $section, $modnames);
698 }
1804b7c1
DP
699 }
700 echo $this->section_footer();
701 }
702
703 unset($sections[$section]);
704 }
705
706 if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
707 // Print stealth sections if present.
708 $modinfo = get_fast_modinfo($course);
709 foreach ($sections as $section => $thissection) {
710 if (empty($modinfo->sections[$section])) {
711 continue;
712 }
713 echo $this->stealth_section_header($section);
714 print_section($course, $thissection, $mods, $modnamesused);
715 echo $this->stealth_section_footer();
716 }
1abf1253 717
575826c7
ARN
718 echo $this->end_section_list();
719
54495fe4 720 echo html_writer::start_tag('div', array('id' => 'changenumsections', 'class' => 'mdl-right'));
3a35a9ff
DP
721
722 // Increase number of sections.
723 $straddsection = get_string('increasesections', 'moodle');
724 $url = new moodle_url('/course/changenumsections.php',
725 array('courseid' => $course->id,
726 'increase' => true,
727 'sesskey' => sesskey()));
728 $icon = $this->output->pix_icon('t/switch_plus', $straddsection);
729 echo html_writer::link($url, $icon.get_accesshide($straddsection), array('class' => 'increase-sections'));
730
731 if ($course->numsections > 0) {
732 // Reduce number of sections sections.
733 $strremovesection = get_string('reducesections', 'moodle');
734 $url = new moodle_url('/course/changenumsections.php',
735 array('courseid' => $course->id,
736 'increase' => false,
737 'sesskey' => sesskey()));
738 $icon = $this->output->pix_icon('t/switch_minus', $strremovesection);
739 echo html_writer::link($url, $icon.get_accesshide($strremovesection), array('class' => 'reduce-sections'));
740 }
741
1abf1253 742 echo html_writer::end_tag('div');
575826c7
ARN
743 } else {
744 echo $this->end_section_list();
1804b7c1
DP
745 }
746
1804b7c1 747 }
7cb8bfdb
DP
748
749 /**
750 * Generate html for a section summary text
751 *
752 * @param stdClass $section The course_section entry from DB
753 * @return string HTML to output.
754 */
755 protected function format_summary_text($section) {
756 $context = context_course::instance($section->course);
757 $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php',
758 $context->id, 'course', 'section', $section->id);
759
760 $options = new stdClass();
761 $options->noclean = true;
762 $options->overflowdiv = true;
763 return format_text($summarytext, $section->summaryformat, $options);
764 }
2ea6533a
DP
765
766 /**
767 * Is the section passed in the current section? (Note this isn't strictly
768 * a renderering method, but neater here).
769 *
770 * @param stdClass $course The course entry from DB
771 * @param stdClass $section The course_section entry from the DB
772 * @return bool true if the section is current
773 */
774 protected function is_section_current($section, $course) {
775 return ($course->marker == $section->section);
776 }
1804b7c1 777}