Moodle release 3.2.3
[moodle.git] / blocks / section_links / renderer.php
blob338855b92385051d8c3a23d3ba5b4b3e6b676d36
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.
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/>.
17 /**
18 * Renderer for the section links block.
20 * @since Moodle 2.5
21 * @package block_section_links
22 * @copyright 2013 Sam Hemelryk
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 /**
27 * Renderer for the section links block.
29 * @package block_section_links
30 * @copyright 2013 Sam Hemelryk
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 class block_section_links_renderer extends plugin_renderer_base {
35 /**
36 * Render a series of section links.
38 * @param stdClass $course The course we are rendering for.
39 * @param array $sections An array of section objects to render.
40 * @param bool|int The section to provide a jump to link for.
41 * @return string The HTML to display.
43 public function render_section_links(stdClass $course, array $sections, $jumptosection = false) {
44 $html = html_writer::start_tag('ol', array('class' => 'inline-list'));
45 foreach ($sections as $section) {
46 $attributes = array();
47 if (!$section->visible) {
48 $attributes['class'] = 'dimmed';
50 $html .= html_writer::start_tag('li');
51 $sectiontext = $section->section;
52 if ($section->highlight) {
53 $sectiontext = html_writer::tag('strong', $sectiontext);
55 $html .= html_writer::link(course_get_url($course, $section->section), $sectiontext, $attributes);
56 $html .= html_writer::end_tag('li').' ';
58 $html .= html_writer::end_tag('ol');
59 if ($jumptosection && isset($sections[$jumptosection])) {
61 if ($course->format == 'weeks') {
62 $linktext = new lang_string('jumptocurrentweek', 'block_section_links');
63 } else if ($course->format == 'topics') {
64 $linktext = new lang_string('jumptocurrenttopic', 'block_section_links');
67 $attributes = array();
68 if (!$sections[$jumptosection]->visible) {
69 $attributes['class'] = 'dimmed';
71 $html .= html_writer::link(course_get_url($course, $jumptosection), $linktext, $attributes);
74 return $html;