Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 19... Línea 19...
19
use core\output\choicelist;
19
use core\output\choicelist;
20
use core\output\local\dropdown\status;
20
use core\output\local\dropdown\status;
21
use core\output\named_templatable;
21
use core\output\named_templatable;
22
use core_courseformat\base as course_format;
22
use core_courseformat\base as course_format;
23
use core_courseformat\output\local\courseformat_named_templatable;
23
use core_courseformat\output\local\courseformat_named_templatable;
-
 
24
use core_courseformat\sectiondelegatemodule;
24
use pix_icon;
25
use pix_icon;
25
use renderable;
26
use renderable;
26
use section_info;
27
use section_info;
27
use stdClass;
28
use stdClass;
Línea 58... Línea 59...
58
     * @param \renderer_base $output typically, the renderer that's calling this function
59
     * @param \renderer_base $output typically, the renderer that's calling this function
59
     * @return stdClass|null data context for a mustache template
60
     * @return stdClass|null data context for a mustache template
60
     */
61
     */
61
    public function export_for_template(\renderer_base $output): ?stdClass {
62
    public function export_for_template(\renderer_base $output): ?stdClass {
62
        global $USER;
63
        global $USER;
-
 
64
 
-
 
65
        if ($this->section->visible) {
-
 
66
            return null;
-
 
67
        }
-
 
68
 
63
        $context = context_course::instance($this->section->course);
69
        $context = context_course::instance($this->section->course);
64
        $data = new stdClass();
70
        $data = new stdClass();
65
        $data->editing = $this->format->show_editor();
-
 
-
 
71
 
66
        if (!$this->section->visible) {
72
        if (!has_capability('moodle/course:sectionvisibility', $context, $USER)) {
67
            $data->notavailable = true;
73
            $data->notavailable = true;
68
            if (has_capability('moodle/course:sectionvisibility', $context, $USER)) {
-
 
69
                $data->hiddenfromstudents = true;
-
 
70
                $data->notavailable = false;
-
 
71
                $badgetext = $output->sr_text(get_string('availability'));
-
 
72
                $badgetext .= get_string("hiddenfromstudents");
-
 
73
                $icon = $this->get_icon('hide');
-
 
74
                $choice = new choicelist();
-
 
75
                $choice->add_option(
74
            return $data;
76
                    'show',
75
        }
77
                    get_string("availability_show", 'core_courseformat'),
-
 
-
 
76
 
78
                    $this->get_option_data('show', 'sectionShow')
77
        $data->editing = $this->format->show_editor();
79
                );
-
 
-
 
78
 
80
                $choice->add_option(
79
        if ($this->section->is_orphan()) {
81
                    'hide',
80
            $data->editing = false;
82
                    get_string('availability_hide', 'core_courseformat'),
-
 
83
                    $this->get_option_data('hide', 'sectionHide')
-
 
84
                );
81
        }
-
 
82
 
85
                $choice->set_selected_value('hide');
83
        $data->notavailable = false;
86
                $dropdown = new status(
84
        $data->hiddenfromstudents = true;
87
                    $output->render($icon) . ' ' . $badgetext,
85
        if ($data->editing && $this->is_section_visibility_editable()) {
88
                    $choice,
-
 
89
                    ['dialogwidth' => status::WIDTH['big']],
86
            $data->dropwdown = $this->get_visibility_dropdown($output);
90
                );
87
        } else {
91
                $data->dropwdown = $dropdown->export_for_template($output);
88
            // The user is editing but cannot edit the visibility on this specific section,
92
            }
89
            $data->editing = false;
93
        }
90
        }
94
        return $data;
91
        return $data;
95
    }
92
    }
Línea 96... Línea 93...
96
 
93
 
-
 
94
    /**
-
 
95
     * Check if the section visibility is editable.
-
 
96
     *
-
 
97
     * @return bool
-
 
98
     */
-
 
99
    protected function is_section_visibility_editable(): bool {
-
 
100
        // Delegated section inside a hidden sections are not editable.
-
 
101
        $parentsection = $this->section->get_component_instance()?->get_parent_section();
-
 
102
        if ($parentsection && !$parentsection->visible) {
-
 
103
            return false;
-
 
104
        }
-
 
105
        return true;
-
 
106
    }
-
 
107
 
-
 
108
    /**
-
 
109
     * Get the section visibility dropdown.
-
 
110
     * @param \renderer_base $output typically, the renderer that's calling this function
-
 
111
     * @return array
-
 
112
     */
-
 
113
    protected function get_visibility_dropdown(\renderer_base $output): array {
-
 
114
        $badgetext = $output->visually_hidden_text(get_string('availability'));
-
 
115
        $badgetext .= get_string('hiddenfromstudents');
-
 
116
        $icon = $this->get_icon('hide');
-
 
117
 
-
 
118
        $choice = new choicelist();
-
 
119
        $choice->add_option(
-
 
120
            'show',
-
 
121
            get_string('availability_show', 'core_courseformat'),
-
 
122
            $this->get_option_data('show', 'sectionShow', 'section_show')
-
 
123
        );
-
 
124
        $choice->add_option(
-
 
125
            'hide',
-
 
126
            get_string('availability_hide', 'core_courseformat'),
-
 
127
            $this->get_option_data('hide', 'sectionHide', 'section_hide')
-
 
128
        );
-
 
129
        $choice->set_selected_value('hide');
-
 
130
 
-
 
131
        $dropdown = new status(
-
 
132
            $output->render($icon) . ' ' . $badgetext,
-
 
133
            $choice,
-
 
134
            ['dialogwidth' => status::WIDTH['big']],
-
 
135
        );
-
 
136
        return $dropdown->export_for_template($output);
-
 
137
    }
-
 
138
 
97
    /**
139
    /**
98
     * Get the data for the option.
140
     * Get the data for the option.
99
     *
141
     *
-
 
142
     * @param string $name the name of the option
100
     * @param string $name the name of the option
143
     * @param string $mutation the mutation name
101
     * @param string $action the state action of the option
144
     * @param string $stateaction the state action name
102
     * @return array
145
     * @return array
103
     */
146
     */
104
    private function get_option_data(string $name, string $action): array {
-
 
105
        $baseurl = course_get_url($this->section->course, $this->section);
147
    private function get_option_data(string $name, string $mutation, string $stateaction): array {
106
        $baseurl->param('sesskey', sesskey());
148
        $format = $this->format;
107
        $baseurl->param($name,  $this->section->section);
-
 
108
 
-
 
109
        // The section page is not yet fully reactive and it needs to use the old non-ajax links.
149
        $nonajaxurl = $format->get_update_url(
110
        $pagesectionid = $this->format->get_sectionid();
150
            action: $stateaction,
111
        if ($this->section->id == $pagesectionid) {
151
            ids: [$this->section->id],
112
            $baseurl->param('sectionid', $pagesectionid);
-
 
113
            $action = '';
152
            returnurl: $format->get_view_url($format->get_sectionnum(), ['navigation' => true]),
Línea 114... Línea 153...
114
        }
153
        );
115
 
154
 
116
        return [
155
        return [
117
            'description' => get_string("availability_{$name}_help", 'core_courseformat'),
-
 
118
            'icon' => $this->get_icon($name),
-
 
119
            // Non-ajax behat is not smart enough to discrimante hidden links
156
            'description' => get_string("availability_{$name}_help", 'core_courseformat'),
120
            // so we need to keep providing the non-ajax links.
157
            'icon' => $this->get_icon($name),
121
            'url' => $baseurl,
158
            'url' => $nonajaxurl,
122
            'extras' => [
159
            'extras' => [
123
                'data-id' => $this->section->id,
160
                'data-id' => $this->section->id,
124
                'data-action' => $action,
161
                'data-action' => $mutation,
125
            ],
162
            ],
Línea 126... Línea 163...
126
        ];
163
        ];