Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 22... Línea 22...
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
23
 */
Línea 24... Línea 24...
24
 
24
 
Línea -... Línea 25...
-
 
25
namespace format_topics\output\courseformat\content\section;
-
 
26
 
-
 
27
use core\output\action_menu\link as action_menu_link;
25
namespace format_topics\output\courseformat\content\section;
28
use core\output\action_menu\link_secondary as action_menu_link_secondary;
26
 
29
use core\output\pix_icon;
Línea 27... Línea 30...
27
use core_courseformat\output\local\content\section\controlmenu as controlmenu_base;
30
use core_courseformat\output\local\content\section\controlmenu as controlmenu_base;
28
use moodle_url;
31
use core\url;
29
 
32
 
30
/**
33
/**
Línea 48... Línea 51...
48
     * This method must remain public until the final deprecation of section_edit_control_items.
51
     * This method must remain public until the final deprecation of section_edit_control_items.
49
     *
52
     *
50
     * @return array of edit control items
53
     * @return array of edit control items
51
     */
54
     */
52
    public function section_control_items() {
55
    public function section_control_items() {
53
 
-
 
54
        $format = $this->format;
-
 
55
        $section = $this->section;
56
        $section = $this->section;
56
        $coursecontext = $format->get_context();
-
 
57
 
-
 
58
        $controls = [];
-
 
59
        if ($section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) {
-
 
60
            $controls['highlight'] = $this->get_highlight_control();
-
 
61
        }
-
 
62
 
-
 
63
        $parentcontrols = parent::section_control_items();
57
        $parentcontrols = parent::section_control_items();
Línea 64... Línea -...
64
 
-
 
65
        // If the edit key exists, we are going to insert our controls after it.
58
 
66
        if (array_key_exists("edit", $parentcontrols)) {
-
 
67
            $merged = [];
-
 
68
            // We can't use splice because we are using associative arrays.
-
 
69
            // Step through the array and merge the arrays.
59
        if ($section->is_orphan() || !$section->sectionnum) {
70
            foreach ($parentcontrols as $key => $action) {
-
 
71
                $merged[$key] = $action;
-
 
72
                if ($key == "edit") {
-
 
73
                    // If we have come to the edit key, merge these controls here.
-
 
74
                    $merged = array_merge($merged, $controls);
-
 
75
                }
60
            return $parentcontrols;
Línea 76... Línea 61...
76
            }
61
        }
77
 
-
 
78
            return $merged;
62
 
79
        } else {
63
        if (!has_capability('moodle/course:setcurrentsection', $this->coursecontext)) {
-
 
64
            return $parentcontrols;
-
 
65
        }
80
            return array_merge($controls, $parentcontrols);
66
 
Línea 81... Línea 67...
81
        }
67
        return $this->add_control_after($parentcontrols, 'edit', 'highlight', $this->get_section_highlight_item());
82
    }
68
    }
83
 
69
 
84
    /**
70
    /**
85
     * Return the course url.
71
     * Return the course url.
-
 
72
     *
-
 
73
     * @return url
-
 
74
     */
-
 
75
    #[\core\attribute\deprecated(
-
 
76
        since: '5.0',
86
     *
77
        mdl: 'MDL-82767',
-
 
78
        reason: 'Not used anymore, use $this->format->get_update_url instead',
87
     * @return moodle_url
79
    )]
88
     */
80
    protected function get_course_url(): url {
89
    protected function get_course_url(): moodle_url {
81
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
90
        $format = $this->format;
82
        $format = $this->format;
Línea 91... Línea 83...
91
        $section = $this->section;
83
        $section = $this->section;
92
        $course = $format->get_course();
84
        $course = $format->get_course();
93
        $sectionreturn = $format->get_sectionnum();
85
        $sectionreturn = $format->get_sectionnum();
94
 
86
 
95
        if ($sectionreturn) {
87
        if ($sectionreturn) {
96
            $url = course_get_url($course, $section->section);
88
            $url = course_get_url($course, $section->sectionnum);
97
        } else {
89
        } else {
98
            $url = course_get_url($course);
90
            $url = course_get_url($course);
Línea 99... Línea 91...
99
        }
91
        }
-
 
92
        $url->param('sesskey', sesskey());
-
 
93
        return $url;
-
 
94
    }
-
 
95
 
-
 
96
    /**
-
 
97
     * Retrieves the view item for the section control menu.
-
 
98
     *
-
 
99
     * @return action_menu_link|null The menu item if applicable, otherwise null.
-
 
100
     */
-
 
101
    protected function get_section_highlight_item(): action_menu_link_secondary {
-
 
102
        $format = $this->format;
-
 
103
        $section = $this->section;
-
 
104
        $course = $format->get_course();
-
 
105
        $sectionreturn = $format->get_sectionnum();
-
 
106
 
-
 
107
        $highlightoff = get_string('highlightoff');
-
 
108
        $highlightofficon = 'i/marked';
-
 
109
 
-
 
110
        $highlighton = get_string('highlight');
-
 
111
        $highlightonicon = 'i/marker';
-
 
112
 
-
 
113
        if ($course->marker == $section->sectionnum) {  // Show the "light globe" on/off.
-
 
114
            $action = 'section_unhighlight';
-
 
115
            $icon = $highlightofficon;
-
 
116
            $name = $highlightoff;
-
 
117
            $attributes = [
-
 
118
                'class' => 'editing_highlight',
-
 
119
                'data-action' => 'sectionUnhighlight',
-
 
120
                'data-sectionreturn' => $sectionreturn,
-
 
121
                'data-id' => $section->id,
-
 
122
                'data-icon' => $highlightofficon,
-
 
123
                'data-swapname' => $highlighton,
-
 
124
                'data-swapicon' => $highlightonicon,
-
 
125
            ];
-
 
126
        } else {
-
 
127
            $action = 'section_highlight';
-
 
128
            $icon = $highlightonicon;
-
 
129
            $name = $highlighton;
-
 
130
            $attributes = [
-
 
131
                'class' => 'editing_highlight',
-
 
132
                'data-action' => 'sectionHighlight',
-
 
133
                'data-sectionreturn' => $sectionreturn,
-
 
134
                'data-id' => $section->id,
-
 
135
                'data-icon' => $highlightonicon,
-
 
136
                'data-swapname' => $highlightoff,
-
 
137
                'data-swapicon' => $highlightofficon,
-
 
138
            ];
-
 
139
        }
-
 
140
 
-
 
141
        $url = $this->format->get_update_url(
-
 
142
            action: $action,
-
 
143
            ids: [$section->id],
-
 
144
            returnurl: $this->baseurl,
-
 
145
        );
-
 
146
 
-
 
147
        return new action_menu_link_secondary(
-
 
148
                url: $url,
-
 
149
                icon: new pix_icon($icon, ''),
-
 
150
                text: $name,
100
        $url->param('sesskey', sesskey());
151
                attributes: $attributes,
101
        return $url;
152
        );
-
 
153
    }
-
 
154
 
102
    }
155
    /**
103
 
156
     * Return the specific section highlight action.
-
 
157
     *
-
 
158
     * @deprecated since Moodle 5.0
-
 
159
     * @todo Remove this method in Moodle 6.0 (MDL-83530).
-
 
160
     * @return array the action element.
-
 
161
     */
-
 
162
    #[\core\attribute\deprecated(
104
    /**
163
        replacement: 'get_section_highlight_item',
-
 
164
        since: '5.0',
105
     * Return the specific section highlight action.
165
        mdl: 'MDL-83527',
106
     *
166
        reason: 'Wrong return type',
107
     * @return array the action element.
167
    )]
108
     */
168
    protected function get_highlight_control(): array {
109
    protected function get_highlight_control(): array {
169
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);