Proyectos de Subversion Moodle

Rev

Ir a la última revisión | | 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
 * Contains the default section selector.
19
 *
20
 * @package   core_courseformat
21
 * @copyright 2020 Ferran Recio <ferran@moodle.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace core_courseformat\output\local\content;
26
 
27
use core\output\named_templatable;
28
use core_courseformat\base as course_format;
29
use core_courseformat\output\local\courseformat_named_templatable;
30
use renderable;
31
use stdClass;
32
use url_select;
33
 
34
/**
35
 * Represents the section selector.
36
 *
37
 * @package   core_courseformat
38
 * @copyright 2020 Ferran Recio <ferran@moodle.com>
39
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40
 */
41
class sectionselector implements named_templatable, renderable {
42
 
43
    use courseformat_named_templatable;
44
 
45
    /** @var course_format the course format class */
46
    protected $format;
47
 
48
    /** @var sectionnavigation the main section navigation class */
49
    protected $navigation;
50
 
51
    /**
52
     * Constructor.
53
     *
54
     * In the current imeplementaiton the seciton selector is almost a variation of the section navigator
55
     * but in the 4.0 this selector will be a kind of dropdown menu. When this happens the construct params
56
     * will change.
57
     *
58
     * @param course_format $format the course format
59
     * @param sectionnavigation $navigation the current section navigation
60
     */
61
    public function __construct(course_format $format, sectionnavigation $navigation) {
62
        $this->format = $format;
63
        $this->navigation = $navigation;
64
    }
65
 
66
    /**
67
     * Export this data so it can be used as the context for a mustache template.
68
     *
69
     * @param renderer_base $output typically, the renderer that's calling this function
70
     * @return stdClass data context for a mustache template
71
     */
72
    public function export_for_template(\renderer_base $output): stdClass {
73
 
74
        $format = $this->format;
75
        $course = $format->get_course();
76
 
77
        $modinfo = $this->format->get_modinfo();
78
 
79
        $data = $this->navigation->export_for_template($output);
80
 
81
        // Add the section selector.
82
        $sectionmenu = [];
83
        $sectionmenu[course_get_url($course)->out(false)] = get_string('maincoursepage');
84
        $section = 1;
85
        $numsections = $format->get_last_section_number();
86
        while ($section <= $numsections) {
87
            $thissection = $modinfo->get_section_info($section);
88
            $url = course_get_url($course, $section);
89
            if ($thissection->uservisible && $url && $section != $data->currentsection) {
90
                $sectionmenu[$url->out(false)] = get_section_name($course, $section);
91
            }
92
            $section++;
93
        }
94
 
95
        $select = new url_select($sectionmenu, '', ['' => get_string('jumpto')]);
96
        $select->class = 'jumpmenu';
97
        $select->formid = 'sectionmenu';
98
 
99
        $data->selector = $output->render($select);
100
        return $data;
101
    }
102
}