weekly release 2.9dev
[moodle.git] / blocks / site_main_menu / block_site_main_menu.php
CommitLineData
4ca6cfbf 1<?php
f25a6839
SH
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 */
89adb174 24
3ef642d9 25class block_site_main_menu extends block_list {
9b4b78fd 26 function init() {
0f14f7e6 27 $this->title = get_string('pluginname', 'block_site_main_menu');
89adb174 28 }
8571833f 29
89adb174 30 function applicable_formats() {
2b0d60ec 31 return array('site' => true);
89adb174 32 }
33
34 function get_content() {
6b608f8f 35 global $USER, $CFG, $DB, $OUTPUT;
89adb174 36
2eb68e6f 37 if ($this->content !== NULL) {
89adb174 38 return $this->content;
39 }
40
dd4bee83 41 $this->content = new stdClass();
89adb174 42 $this->content->items = array();
43 $this->content->icons = array();
44 $this->content->footer = '';
45
9b4b78fd 46 if (empty($this->instance)) {
47 return $this->content;
48 }
49
3179b000 50 $course = $this->page->course;
dd97c328 51 require_once($CFG->dirroot.'/course/lib.php');
fe2fdd11 52 $context = context_course::instance($course->id);
cb640229 53 $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
dd97c328 54
55/// extra fast view mode
56 if (!$isediting) {
71a56e08 57 $modinfo = get_fast_modinfo($course);
dd97c328 58 if (!empty($modinfo->sections[0])) {
367a75fa 59 $options = array('overflowdiv'=>true);
dd97c328 60 foreach($modinfo->sections[0] as $cmid) {
61 $cm = $modinfo->cms[$cmid];
62 if (!$cm->uservisible) {
63 continue;
64 }
0d8b6a69 65
f89c53f6
MG
66 $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
67 $instancename = $cm->get_formatted_name();
0d8b6a69 68
73ee2fda 69 if (!($url = $cm->url)) {
0d8b6a69 70 $this->content->items[] = $content;
dd97c328 71 $this->content->icons[] = '';
72 } else {
73 $linkcss = $cm->visible ? '' : ' class="dimmed" ';
dd97c328 74 //Accessibility: incidental image - should be empty Alt text
11f87187 75 $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
710363c9 76 $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
0d8b6a69 77 ' href="' . $url . '">' . $icon . $instancename . '</a>';
dd97c328 78 }
79 }
80 }
81 return $this->content;
82 }
83
ea5a01fb
SH
84 // Slow & hacky editing mode.
85 /** @var core_course_renderer $courserenderer */
9a36be73 86 $courserenderer = $this->page->get_renderer('core', 'course');
3179b000 87 $ismoving = ismoving($course->id);
4ede27b2 88 course_create_sections_if_missing($course, 0);
71a56e08 89 $modinfo = get_fast_modinfo($course);
4ede27b2 90 $section = $modinfo->get_section_info(0);
89adb174 91
89adb174 92 if ($ismoving) {
93 $strmovehere = get_string('movehere');
94 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
95 $strcancel= get_string('cancel');
96 $stractivityclipboard = $USER->activitycopyname;
0c74b33f
MG
97 } else {
98 $strmove = get_string('move');
89adb174 99 }
89adb174 100 $editbuttons = '';
101
102 if ($ismoving) {
b5d0cafc 103 $this->content->icons[] = '<img src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
d4a1fcaf 104 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
89adb174 105 }
106
71a56e08 107 if (!empty($modinfo->sections[0])) {
367a75fa 108 $options = array('overflowdiv'=>true);
71a56e08
MG
109 foreach ($modinfo->sections[0] as $modnumber) {
110 $mod = $modinfo->cms[$modnumber];
111 if (!$mod->uservisible) {
89adb174 112 continue;
113 }
dd97c328 114 if (!$ismoving) {
9a36be73 115 $actions = course_get_cm_edit_actions($mod, -1);
2a974bb7 116
0c74b33f
MG
117 // Prepend list of actions with the 'move' action.
118 $actions = array('move' => new action_menu_link_primary(
119 new moodle_url('/course/mod.php', array('sesskey' => sesskey(), 'copy' => $mod->id)),
120 new pix_icon('t/move', $strmove, 'moodle', array('class' => 'iconsmall', 'title' => '')),
121 $strmove
122 )) + $actions;
2a974bb7 123
9a36be73 124 $editbuttons = html_writer::tag('div',
f803ce26
SH
125 $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)),
126 array('class' => 'buttons')
127 );
89adb174 128 } else {
129 $editbuttons = '';
130 }
45ad1693 131 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) {
89adb174 132 if ($ismoving) {
133 if ($mod->id == $USER->activitycopy) {
134 continue;
135 }
d4a1fcaf 136 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 137 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 138 $this->content->icons[] = '';
dd97c328 139 }
f89c53f6
MG
140 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
141 $instancename = $mod->get_formatted_name();
89adb174 142 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
89adb174 143
73ee2fda 144 if (!($url = $mod->url)) {
0d8b6a69 145 $this->content->items[] = $content . $editbuttons;
89adb174 146 $this->content->icons[] = '';
147 } else {
dd97c328 148 //Accessibility: incidental image - should be empty Alt text
11f87187 149 $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />';
0d8b6a69 150 $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
151 ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
89adb174 152 }
153 }
154 }
155 }
156
157 if ($ismoving) {
d4a1fcaf 158 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 159 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 160 $this->content->icons[] = '';
161 }
162
9a6aa5c1
MG
163 $this->content->footer = $courserenderer->course_section_add_cm_control($course,
164 0, null, array('inblock' => true));
89adb174 165
166 return $this->content;
167 }
168}
169
4ca6cfbf 170