Proyectos de Subversion Moodle

Rev

| 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'];
46
        $html = html_writer::start_tag('ol', $olparams);
47
        foreach ($sections as $section) {
48
            $attributes = array();
49
            if (!$section->visible) {
50
                $attributes['class'] = 'dimmed';
51
            }
52
            $html .= html_writer::start_tag('li');
53
            $sectiontext = $section->section;
54
            if ($showsectionname) {
55
                $sectiontext .= ': ' . $section->name;
56
            }
57
            if ($section->highlight) {
58
                $sectiontext = html_writer::tag('strong', $sectiontext);
59
            }
60
            $html .= html_writer::link(
61
                course_get_url($course, $section->section, ['navigation' => true]),
62
                $sectiontext,
63
                $attributes
64
            );
65
            $html .= html_writer::end_tag('li').' ';
66
        }
67
        $html .= html_writer::end_tag('ol');
68
        if ($jumptosection && isset($sections[$jumptosection])) {
69
 
70
            if ($course->format == 'weeks') {
71
                $linktext = new lang_string('jumptocurrentweek', 'block_section_links');
72
            } else if ($course->format == 'topics') {
73
                $linktext = new lang_string('jumptocurrenttopic', 'block_section_links');
74
            }
75
 
76
            $attributes = array();
77
            if (!$sections[$jumptosection]->visible) {
78
                $attributes['class'] = 'dimmed';
79
            }
80
            $html .= html_writer::link(course_get_url($course, $jumptosection, ['navigation' => true]), $linktext, $attributes);
81
        }
82
 
83
        return $html;
84
    }
85
}