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
 * Site main menu block.
19
 *
20
 * @package    block_site_main_menu
21
 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
class block_site_main_menu extends block_list {
26
    function init() {
27
        $this->title = get_string('pluginname', 'block_site_main_menu');
28
    }
29
 
30
    function applicable_formats() {
31
        return array('site' => true);
32
    }
33
 
34
    function get_content() {
35
        global $USER, $CFG, $DB, $OUTPUT;
36
 
37
        if ($this->content !== NULL) {
38
            return $this->content;
39
        }
40
 
41
        $this->content = new stdClass();
42
        $this->content->items = array();
43
        $this->content->icons = array();
44
        $this->content->footer = '';
45
 
46
        if (empty($this->instance)) {
47
            return $this->content;
48
        }
49
 
50
        require_once($CFG->dirroot . '/course/lib.php');
51
 
52
        $course = get_site();
53
        $format = course_get_format($course);
54
        $courserenderer = $format->get_renderer($this->page);
55
 
56
        $context = context_course::instance($course->id);
57
        $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
58
 
59
        // Output classes.
60
        $cmnameclass = $format->get_output_classname('content\\cm\\cmname');
61
        $controlmenuclass = $format->get_output_classname('content\\cm\\controlmenu');
62
 
63
        $badgeattributes = [
64
            'class' => 'badge rounded-pill bg-warning text-dark mt-2',
65
            'data-region' => 'visibility'
66
        ];
67
 
68
        // Extra fast view mode.
69
        if (!$isediting) {
70
            $modinfo = get_fast_modinfo($course);
71
            if (!empty($modinfo->sections[0])) {
72
                foreach($modinfo->sections[0] as $cmid) {
73
                    $cm = $modinfo->cms[$cmid];
74
                    if (!$cm->uservisible || !$cm->is_visible_on_course_page()) {
75
                        continue;
76
                    }
77
 
78
                    if ($cm->indent > 0) {
79
                        $indent = '<div class="mod-indent mod-indent-'.$cm->indent.'"></div>';
80
                    } else {
81
                        $indent = '';
82
                    }
83
 
84
                    $badges = '';
85
                    if (!$cm->visible) {
86
                        $badges = html_writer::tag(
87
                            'span',
88
                            get_string('hiddenfromstudents'),
89
                            $badgeattributes
90
                        );
91
                    }
92
 
93
                    if ($cm->is_stealth()) {
94
                        $badges = html_writer::tag(
95
                            'span',
96
                            get_string('hiddenoncoursepage'),
97
                            $badgeattributes
98
                        );
99
                    }
100
 
101
                    if (!$cm->url) {
102
                        $activitybasis = html_writer::div(
103
                            $indent . $cm->get_formatted_content(['overflowdiv' => true, 'noclean' => true]),
104
                            'activity-basis d-flex align-items-center');
105
                        $content = html_writer::div(
106
                            $activitybasis . $badges,
107
                            'contentwithoutlink activity-item activity',
108
                            ['data-activityname' => $cm->name]
109
                        );
110
                    } else {
111
                        $cmname = new $cmnameclass($format, $cm->get_section_info(), $cm);
112
                        $activitybasis = html_writer::div(
113
                            $indent . $courserenderer->render($cmname),
114
                            'activity-basis d-flex align-items-center');
115
                        $content = html_writer::div(
116
                            $activitybasis . $badges,
117
                            'activity-item activity',
118
                            ['data-activityname' => $cm->name]
119
                        );
120
                    }
121
 
122
                    $this->content->items[] = html_writer::div($content, 'main-menu-content section');
123
                }
124
            }
125
            return $this->content;
126
        }
127
 
128
        // Slow & hacky editing mode.
129
        $ismoving = ismoving($course->id);
130
        course_create_sections_if_missing($course, 0);
131
        $modinfo = get_fast_modinfo($course);
132
        $section = $modinfo->get_section_info(0);
133
 
134
        if ($ismoving) {
135
            $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
136
            $strcancel= get_string('cancel');
137
        } else {
138
            $strmove = get_string('move');
139
        }
140
 
141
        if ($ismoving) {
142
            $this->content->icons[] = $OUTPUT->pix_icon('t/move', get_string('move'));
143
            $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
144
        }
145
 
146
        if (!empty($modinfo->sections[0])) {
147
            foreach ($modinfo->sections[0] as $modnumber) {
148
                $mod = $modinfo->cms[$modnumber];
149
                if (!$mod->uservisible || !$mod->is_visible_on_course_page()) {
150
                    continue;
151
                }
152
                if (!$ismoving) {
153
 
154
                    $controlmenu = new $controlmenuclass(
155
                        $format,
156
                        $mod->get_section_info(),
157
                        $mod
158
                    );
159
 
160
                    $menu = $controlmenu->get_action_menu($OUTPUT);
161
 
162
                    $moveaction = html_writer::link(
163
                        new moodle_url('/course/mod.php', ['sesskey' => sesskey(), 'copy' => $mod->id]),
164
                        $OUTPUT->pix_icon('i/dragdrop', $strmove),
165
                        ['class' => 'editing_move_activity']
166
                    );
167
 
168
                    $editbuttons = html_writer::tag(
169
                        'div',
170
                        $courserenderer->render($controlmenu),
171
                        ['class' => 'buttons activity-actions ml-auto']
172
                    );
173
                } else {
174
                    $editbuttons = '';
175
                    $moveaction = '';
176
                }
177
 
178
                if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) {
179
                    if ($ismoving) {
180
                        if ($mod->id == $USER->activitycopy) {
181
                            continue;
182
                        }
183
                        $movingurl = new moodle_url('/course/mod.php', array('moveto' => $mod->id, 'sesskey' => sesskey()));
184
                        $this->content->items[] = html_writer::link($movingurl, '', array('title' => $strmovefull,
185
                            'class' => 'movehere'));
186
                        $this->content->icons[] = '';
187
                    }
188
 
189
                    if ($mod->indent > 0) {
190
                        $indent = '<div class="mod-indent mod-indent-'.$mod->indent.'"></div>';
191
                    } else {
192
                        $indent = '';
193
                    }
194
 
195
                    $badges = '';
196
                    if (!$mod->visible) {
197
                        $badges = html_writer::tag(
198
                            'span',
199
                            get_string('hiddenfromstudents'),
200
                            $badgeattributes
201
                        );
202
                    }
203
 
204
                    if ($mod->is_stealth()) {
205
                        $badges = html_writer::tag(
206
                            'span',
207
                            get_string('hiddenoncoursepage'),
208
                            $badgeattributes
209
                        );
210
                    }
211
 
212
                    if (!$mod->url) {
213
                        $activitybasis = html_writer::div(
214
                            $moveaction .
215
                            $indent .
216
                            $mod->get_formatted_content(['overflowdiv' => true, 'noclean' => true]) .
217
                            $editbuttons,
218
                            'activity-basis d-flex align-items-center');
219
                        $content = html_writer::div(
220
                            $activitybasis . $badges,
221
                            'contentwithoutlink activity-item activity',
222
                            ['data-activityname' => $mod->name]
223
                        );
224
                    } else {
225
                        $cmname = new $cmnameclass($format, $mod->get_section_info(), $mod);
226
                        $activitybasis = html_writer::div(
227
                            $moveaction .
228
                            $indent .
229
                            $courserenderer->render($cmname) .
230
                            $editbuttons,
231
                            'activity-basis d-flex align-items-center');
232
                        $content = html_writer::div(
233
                            $activitybasis . $badges,
234
                            'activity-item activity',
235
                            ['data-activityname' => $mod->name]
236
                        );
237
                    }
238
                    $this->content->items[] = html_writer::div($content, 'main-menu-content');
239
                }
240
            }
241
        }
242
 
243
        if ($ismoving) {
244
            $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
245
            $this->content->items[] = html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere'));
246
            $this->content->icons[] = '';
247
        }
248
 
249
        if ($this->page->course->id === SITEID) {
250
            $this->content->footer = $courserenderer->course_section_add_cm_control($course,
251
                0, null, array('inblock' => true));
252
        }
253
        return $this->content;
254
    }
255
}