2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Site main menu block.
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
25 class block_site_main_menu
extends block_list
{
27 $this->title
= get_string('pluginname', 'block_site_main_menu');
30 function applicable_formats() {
31 return array('site' => true);
34 function get_content() {
35 global $USER, $CFG, $DB, $OUTPUT;
37 if ($this->content
!== NULL) {
38 return $this->content
;
41 $this->content
= new stdClass();
42 $this->content
->items
= array();
43 $this->content
->icons
= array();
44 $this->content
->footer
= '';
46 if (empty($this->instance
)) {
47 return $this->content
;
50 require_once($CFG->dirroot
. '/course/lib.php');
53 $format = course_get_format($course);
54 $courserenderer = $format->get_renderer($this->page
);
56 $context = context_course
::instance($course->id
);
57 $isediting = $this->page
->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
60 $cmnameclass = $format->get_output_classname('content\\cm\\cmname');
61 $controlmenuclass = $format->get_output_classname('content\\cm\\controlmenu');
64 'class' => 'badge rounded-pill bg-warning text-dark mt-2',
65 'data-region' => 'visibility'
68 // Extra fast view mode.
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()) {
78 if ($cm->indent
> 0) {
79 $indent = '<div class="mod-indent mod-indent-'.$cm->indent
.'"></div>';
86 $badges = html_writer
::tag(
88 get_string('hiddenfromstudents'),
93 if ($cm->is_stealth()) {
94 $badges = html_writer
::tag(
96 get_string('hiddenoncoursepage'),
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
]
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
]
122 $this->content
->items
[] = html_writer
::div($content, 'main-menu-content section');
125 return $this->content
;
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);
135 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
136 $strcancel= get_string('cancel');
138 $strmove = get_string('move');
142 $this->content
->icons
[] = $OUTPUT->pix_icon('t/move', get_string('move'));
143 $this->content
->items
[] = $USER->activitycopyname
.' (<a href="'.$CFG->wwwroot
.'/course/mod.php?cancelcopy=true&sesskey='.sesskey().'">'.$strcancel.'</a>)';
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()) {
154 $controlmenu = new $controlmenuclass(
156 $mod->get_section_info(),
160 $menu = $controlmenu->get_action_menu($OUTPUT);
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']
168 $editbuttons = html_writer
::tag(
170 $courserenderer->render($controlmenu),
171 ['class' => 'buttons activity-actions ml-auto']
178 if ($mod->visible ||
has_capability('moodle/course:viewhiddenactivities', $mod->context
)) {
180 if ($mod->id
== $USER->activitycopy
) {
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
[] = '';
189 if ($mod->indent
> 0) {
190 $indent = '<div class="mod-indent mod-indent-'.$mod->indent
.'"></div>';
196 if (!$mod->visible
) {
197 $badges = html_writer
::tag(
199 get_string('hiddenfromstudents'),
204 if ($mod->is_stealth()) {
205 $badges = html_writer
::tag(
207 get_string('hiddenoncoursepage'),
213 $activitybasis = html_writer
::div(
216 $mod->get_formatted_content(['overflowdiv' => true, 'noclean' => true]) .
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
]
225 $cmname = new $cmnameclass($format, $mod->get_section_info(), $mod);
226 $activitybasis = html_writer
::div(
229 $courserenderer->render($cmname) .
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
]
238 $this->content
->items
[] = html_writer
::div($content, 'main-menu-content');
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
[] = '';
249 if ($this->page
->course
->id
=== SITEID
) {
250 $this->content
->footer
= $courserenderer->course_section_add_cm_control($course,
251 0, null, array('inblock' => true));
253 return $this->content
;