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
 *
19
 *
20
 * @package    block_site_main_menu
20
 * @package    block_site_main_menu
21
 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
21
 * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
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
 */
24
 
-
 
25
class block_site_main_menu extends block_list {
24
class block_site_main_menu extends block_base {
26
    function init() {
25
    function init() {
27
        $this->title = get_string('pluginname', 'block_site_main_menu');
26
        $this->title = get_string('pluginname', 'block_site_main_menu');
28
    }
27
    }
Línea 29... Línea 28...
29
 
28
 
30
    function applicable_formats() {
29
    function applicable_formats() {
31
        return array('site' => true);
30
        return array('site' => true);
Línea 32... Línea 31...
32
    }
31
    }
33
 
-
 
34
    function get_content() {
-
 
35
        global $USER, $CFG, $DB, $OUTPUT;
32
 
36
 
33
    function get_content() {
37
        if ($this->content !== NULL) {
34
        if ($this->content !== NULL) {
Línea 38... Línea 35...
38
            return $this->content;
35
            return $this->content;
39
        }
36
        }
40
 
-
 
41
        $this->content = new stdClass();
37
 
Línea 42... Línea 38...
42
        $this->content->items = array();
38
        $this->content = new stdClass();
43
        $this->content->icons = array();
39
        $this->content->text = '';
44
        $this->content->footer = '';
40
        $this->content->footer = '';
Línea 45... Línea -...
45
 
-
 
46
        if (empty($this->instance)) {
-
 
47
            return $this->content;
41
 
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
 
-
 
Línea 122... Línea -...
122
                    $this->content->items[] = html_writer::div($content, 'main-menu-content section');
-
 
123
                }
-
 
124
            }
42
        if (empty($this->instance)) {
-
 
43
            return $this->content;
125
            return $this->content;
44
        }
126
        }
45
 
Línea 127... Línea -...
127
 
-
 
128
        // Slow & hacky editing mode.
-
 
129
        $ismoving = ismoving($course->id);
46
        $course = get_site();
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 {
-
 
Línea 138... Línea -...
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,
47
 
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,
-
 
Línea 234... Línea -...
234
                            'activity-item activity',
-
 
235
                            ['data-activityname' => $mod->name]
-
 
236
                        );
-
 
237
                    }
48
        course_create_sections_if_missing($course, 0);
238
                    $this->content->items[] = html_writer::div($content, 'main-menu-content');
-
 
Línea 239... Línea 49...
239
                }
49
        $format = course_get_format($course);
240
            }
50
        $modinfo = $format->get_modinfo();
-
 
51
        $section = $modinfo->get_section_info(0);
-
 
52
 
-
 
53
        $courserenderer = $format->get_renderer($this->page);
241
        }
54
 
-
 
55
        $output = new block_site_main_menu\output\mainsection($format, $section);
242
 
56
 
243
        if ($ismoving) {
57
        $this->content->text = $courserenderer->render($output);
244
            $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
58
 
245
            $this->content->items[] = html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere'));
59
        if ($this->page->course->id === SITEID) {