Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 26... Línea 26...
26
 
26
 
27
use core\output\named_templatable;
27
use core\output\named_templatable;
28
use core_courseformat\base as course_format;
28
use core_courseformat\base as course_format;
29
use core_courseformat\output\local\courseformat_named_templatable;
29
use core_courseformat\output\local\courseformat_named_templatable;
-
 
30
use renderable;
30
use renderable;
31
use section_info;
31
use stdClass;
32
use stdClass;
Línea 32... Línea 33...
32
use url_select;
33
use url_select;
33
 
34
 
Línea 40... Línea 41...
40
 */
41
 */
41
class sectionselector implements named_templatable, renderable {
42
class sectionselector implements named_templatable, renderable {
Línea 42... Línea 43...
42
 
43
 
Línea -... Línea 44...
-
 
44
    use courseformat_named_templatable;
-
 
45
 
43
    use courseformat_named_templatable;
46
    /** @var string the indenter */
44
 
47
    private const INDENTER = '    ';
45
    /** @var course_format the course format class */
-
 
46
    protected $format;
48
    /** @var course_format the course format class */
47
 
49
    protected $format;
Línea -... Línea 50...
-
 
50
    /** @var sectionnavigation the main section navigation class */
-
 
51
    protected $navigation;
-
 
52
 
48
    /** @var sectionnavigation the main section navigation class */
53
    /** @var array $sectionmenu the sections indexed by url. */
49
    protected $navigation;
54
    protected $sectionmenu = [];
50
 
55
 
51
    /**
56
    /**
52
     * Constructor.
57
     * Constructor.
Línea 64... Línea 69...
64
    }
69
    }
Línea 65... Línea 70...
65
 
70
 
66
    /**
71
    /**
67
     * Export this data so it can be used as the context for a mustache template.
72
     * Export this data so it can be used as the context for a mustache template.
68
     *
73
     *
69
     * @param renderer_base $output typically, the renderer that's calling this function
74
     * @param \renderer_base $output typically, the renderer that's calling this function
70
     * @return stdClass data context for a mustache template
75
     * @return stdClass data context for a mustache template
71
     */
76
     */
Línea 72... Línea 77...
72
    public function export_for_template(\renderer_base $output): stdClass {
77
    public function export_for_template(\renderer_base $output): stdClass {
Línea 76... Línea 81...
76
 
81
 
Línea 77... Línea 82...
77
        $modinfo = $this->format->get_modinfo();
82
        $modinfo = $this->format->get_modinfo();
Línea -... Línea 83...
-
 
83
 
-
 
84
        $data = $this->navigation->export_for_template($output);
78
 
85
 
-
 
86
        $this->sectionmenu[course_get_url($course)->out(false)] = get_string('maincoursepage');
-
 
87
 
79
        $data = $this->navigation->export_for_template($output);
88
        // Add the section selector.
80
 
89
        $allsections = $modinfo->get_section_info_all();
-
 
90
        $disabledlink = $this->get_section_url($course, $allsections[$data->currentsection]);
-
 
91
        $sectionwithchildren = [];
-
 
92
        // First get any section with chidren (easier to process later in a regular loop).
81
        // Add the section selector.
93
        foreach ($allsections as $section) {
-
 
94
            if (!$section->uservisible) {
82
        $sectionmenu = [];
95
                unset($allsections[$section->sectionnum]);
83
        $sectionmenu[course_get_url($course)->out(false)] = get_string('maincoursepage');
96
                continue;
84
        $section = 1;
97
            }
85
        $numsections = $format->get_last_section_number();
98
            $sectiondelegated = $section->get_component_instance();
86
        while ($section <= $numsections) {
99
            if ($sectiondelegated) {
-
 
100
                unset($allsections[$section->sectionnum]);
87
            $thissection = $modinfo->get_section_info($section);
101
                $parentsection = $sectiondelegated->get_parent_section();
-
 
102
                // If the section is delegated we need to get the parent section and add the section to the parent section array.
88
            $url = course_get_url($course, $section, ['navigation' => true]);
103
                if ($parentsection) {
89
            if ($thissection->uservisible && $url && $section != $data->currentsection) {
-
 
90
                $sectionmenu[$url->out(false)] = get_section_name($course, $section);
104
                    $sectionwithchildren[$parentsection->sectionnum][] = $section;
Línea -... Línea 105...
-
 
105
                }
-
 
106
            }
-
 
107
        }
-
 
108
 
-
 
109
        foreach ($allsections as $section) {
-
 
110
            $this->add_section_menu($format, $course, $section);
-
 
111
            if (isset($sectionwithchildren[$section->sectionnum])) {
-
 
112
                foreach ($sectionwithchildren[$section->sectionnum] as $subsection) {
-
 
113
                    $this->add_section_menu($format, $course, $subsection, true);
-
 
114
                }
-
 
115
            }
91
            }
116
        }
-
 
117
        $select = new url_select(
-
 
118
            urls: $this->sectionmenu,
-
 
119
            selected: '',
92
            $section++;
120
            nothing: ['' => get_string('jumpto')],
93
        }
121
        );
Línea 94... Línea 122...
94
 
122
        // Disable the current section.
95
        $select = new url_select($sectionmenu, '', ['' => get_string('jumpto')]);
123
        $select->set_option_disabled($disabledlink);
96
        $select->class = 'jumpmenu';
124
        $select->class = 'jumpmenu';
-
 
125
        $select->formid = 'sectionmenu';
-
 
126
 
-
 
127
        $data->selector = $output->render($select);
-
 
128
        return $data;
-
 
129
    }
-
 
130
 
-
 
131
    /**
-
 
132
     * Add a section to the section menu.
-
 
133
     *
-
 
134
     * @param course_format $format
-
 
135
     * @param stdClass $course
-
 
136
     * @param section_info $section
-
 
137
     * @param bool $indent
-
 
138
     */
-
 
139
    private function add_section_menu(
-
 
140
        course_format $format,
-
 
141
        stdClass $course,
-
 
142
        section_info $section,
-
 
143
        bool $indent = false
-
 
144
    ) {
-
 
145
        $url = $this->get_section_url($course, $section);
-
 
146
        $indentation = $indent ? self::INDENTER : '';
-
 
147
        $this->sectionmenu[$url] = $indentation . $format->get_section_name($section);
-
 
148
    }
-
 
149
 
-
 
150
    /**
-
 
151
     * Get the section url.
-
 
152
     * @param stdClass $course
-
 
153
     * @param section_info $section
97
        $select->formid = 'sectionmenu';
154
     * @return string