Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Renderer for the section links block.
19
 *
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
24
 */
25
 
26
/**
27
 * Renderer for the section links block.
28
 *
29
 * @package   block_section_links
30
 * @copyright 2013 Sam Hemelryk
31
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class block_section_links_renderer extends plugin_renderer_base {
34
 
35
    /**
36
     * Render a series of section links.
37
     *
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
     * @param bool $showsectionname Whether or not section name should be displayed.
42
     * @return string The HTML to display.
43
     */
44
    public function render_section_links(stdClass $course, array $sections, $jumptosection = false, $showsectionname = false) {
45
        $olparams = $showsectionname ? ['class' => 'unlist'] : ['class' => 'inline-list'];
1441 ariadna 46
        $liparams = $showsectionname ? ['class' => 'mb-2'] : [];
1 efrain 47
        $html = html_writer::start_tag('ol', $olparams);
48
        foreach ($sections as $section) {
49
            $attributes = array();
50
            if (!$section->visible) {
51
                $attributes['class'] = 'dimmed';
52
            }
1441 ariadna 53
            $html .= html_writer::start_tag('li', $liparams);
1 efrain 54
            $sectiontext = $section->section;
55
            if ($showsectionname) {
1441 ariadna 56
                $sectiontext = $section->name;
1 efrain 57
            }
58
            if ($section->highlight) {
59
                $sectiontext = html_writer::tag('strong', $sectiontext);
60
            }
61
            $html .= html_writer::link(
62
                course_get_url($course, $section->section, ['navigation' => true]),
63
                $sectiontext,
64
                $attributes
65
            );
66
            $html .= html_writer::end_tag('li').' ';
67
        }
68
        $html .= html_writer::end_tag('ol');
69
        if ($jumptosection && isset($sections[$jumptosection])) {
70
 
71
            if ($course->format == 'weeks') {
72
                $linktext = new lang_string('jumptocurrentweek', 'block_section_links');
73
            } else if ($course->format == 'topics') {
74
                $linktext = new lang_string('jumptocurrenttopic', 'block_section_links');
75
            }
76
 
77
            $attributes = array();
78
            if (!$sections[$jumptosection]->visible) {
79
                $attributes['class'] = 'dimmed';
80
            }
81
            $html .= html_writer::link(course_get_url($course, $jumptosection, ['navigation' => true]), $linktext, $attributes);
82
        }
83
 
84
        return $html;
85
    }
86
}