MDL-37085 Substitute function print_section_add_menus() with core_course_renderer...
[moodle.git] / blocks / site_main_menu / block_site_main_menu.php
CommitLineData
4ca6cfbf 1<?php
89adb174 2
3ef642d9 3class block_site_main_menu extends block_list {
9b4b78fd 4 function init() {
0f14f7e6 5 $this->title = get_string('pluginname', 'block_site_main_menu');
89adb174 6 }
8571833f 7
89adb174 8 function applicable_formats() {
2b0d60ec 9 return array('site' => true);
89adb174 10 }
11
12 function get_content() {
6b608f8f 13 global $USER, $CFG, $DB, $OUTPUT;
89adb174 14
2eb68e6f 15 if ($this->content !== NULL) {
89adb174 16 return $this->content;
17 }
18
dd4bee83 19 $this->content = new stdClass();
89adb174 20 $this->content->items = array();
21 $this->content->icons = array();
22 $this->content->footer = '';
23
9b4b78fd 24 if (empty($this->instance)) {
25 return $this->content;
26 }
27
3179b000 28 $course = $this->page->course;
dd97c328 29 require_once($CFG->dirroot.'/course/lib.php');
fe2fdd11 30 $context = context_course::instance($course->id);
cb640229 31 $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
dd97c328 32
33/// extra fast view mode
34 if (!$isediting) {
71a56e08 35 $modinfo = get_fast_modinfo($course);
dd97c328 36 if (!empty($modinfo->sections[0])) {
367a75fa 37 $options = array('overflowdiv'=>true);
dd97c328 38 foreach($modinfo->sections[0] as $cmid) {
39 $cm = $modinfo->cms[$cmid];
40 if (!$cm->uservisible) {
41 continue;
42 }
0d8b6a69 43
f89c53f6
MG
44 $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
45 $instancename = $cm->get_formatted_name();
0d8b6a69 46
47 if (!($url = $cm->get_url())) {
48 $this->content->items[] = $content;
dd97c328 49 $this->content->icons[] = '';
50 } else {
51 $linkcss = $cm->visible ? '' : ' class="dimmed" ';
dd97c328 52 //Accessibility: incidental image - should be empty Alt text
11f87187 53 $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
710363c9 54 $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
0d8b6a69 55 ' href="' . $url . '">' . $icon . $instancename . '</a>';
dd97c328 56 }
57 }
58 }
59 return $this->content;
60 }
61
dd97c328 62/// slow & hacky editing mode
3179b000 63 $ismoving = ismoving($course->id);
4ede27b2 64 course_create_sections_if_missing($course, 0);
71a56e08 65 $modinfo = get_fast_modinfo($course);
4ede27b2 66 $section = $modinfo->get_section_info(0);
89adb174 67
9b4b78fd 68 $groupbuttons = $course->groupmode;
69 $groupbuttonslink = (!$course->groupmodeforce);
89adb174 70
71 if ($ismoving) {
72 $strmovehere = get_string('movehere');
73 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
74 $strcancel= get_string('cancel');
75 $stractivityclipboard = $USER->activitycopyname;
76 }
fea43a7f 77 /// Casting $course->modinfo to string prevents one notice when the field is null
89adb174 78 $editbuttons = '';
79
80 if ($ismoving) {
b5d0cafc 81 $this->content->icons[] = '<img src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
d4a1fcaf 82 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
89adb174 83 }
84
71a56e08 85 if (!empty($modinfo->sections[0])) {
367a75fa 86 $options = array('overflowdiv'=>true);
71a56e08
MG
87 foreach ($modinfo->sections[0] as $modnumber) {
88 $mod = $modinfo->cms[$modnumber];
89 if (!$mod->uservisible) {
89adb174 90 continue;
91 }
dd97c328 92 if (!$ismoving) {
89adb174 93 if ($groupbuttons) {
94 if (! $mod->groupmodelink = $groupbuttonslink) {
9b4b78fd 95 $mod->groupmode = $course->groupmode;
89adb174 96 }
97
98 } else {
99 $mod->groupmode = false;
100 }
f82c88ab 101 $editbuttons = '<div class="buttons">'.make_editing_buttons($mod, true, true).'</div>';
89adb174 102 } else {
103 $editbuttons = '';
104 }
6006c31d 105 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
89adb174 106 if ($ismoving) {
107 if ($mod->id == $USER->activitycopy) {
108 continue;
109 }
d4a1fcaf 110 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 111 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 112 $this->content->icons[] = '';
dd97c328 113 }
f89c53f6
MG
114 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
115 $instancename = $mod->get_formatted_name();
89adb174 116 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
89adb174 117
0d8b6a69 118 if (!($url = $mod->get_url())) {
119 $this->content->items[] = $content . $editbuttons;
89adb174 120 $this->content->icons[] = '';
121 } else {
dd97c328 122 //Accessibility: incidental image - should be empty Alt text
11f87187 123 $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />';
0d8b6a69 124 $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
125 ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
89adb174 126 }
127 }
128 }
129 }
130
131 if ($ismoving) {
d4a1fcaf 132 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 133 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 134 $this->content->icons[] = '';
135 }
136
9a6aa5c1
MG
137 $courserenderer = $this->page->get_renderer('core', 'course');
138 $this->content->footer = $courserenderer->course_section_add_cm_control($course,
139 0, null, array('inblock' => true));
89adb174 140
141 return $this->content;
142 }
143}
144
4ca6cfbf 145