on-demand release 2.4dev
[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);
830dd6e9 32 $modinfo = get_fast_modinfo($course);
dd97c328 33
34/// extra fast view mode
35 if (!$isediting) {
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
44 list($content, $instancename) =
45 get_print_section_cm_text($cm, $course);
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
0d8b6a69 53 $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />&nbsp;';
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);
64 $section = get_course_section(0, $course->id);
a2f96413 65
3179b000 66 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
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
1a4872b6 85 if (!empty($section->sequence)) {
89adb174 86 $sectionmods = explode(',', $section->sequence);
367a75fa 87 $options = array('overflowdiv'=>true);
89adb174 88 foreach ($sectionmods as $modnumber) {
89 if (empty($mods[$modnumber])) {
90 continue;
91 }
92 $mod = $mods[$modnumber];
dd97c328 93 if (!$ismoving) {
89adb174 94 if ($groupbuttons) {
95 if (! $mod->groupmodelink = $groupbuttonslink) {
9b4b78fd 96 $mod->groupmode = $course->groupmode;
89adb174 97 }
98
99 } else {
100 $mod->groupmode = false;
101 }
f82c88ab 102 $editbuttons = '<div class="buttons">'.make_editing_buttons($mod, true, true).'</div>';
89adb174 103 } else {
104 $editbuttons = '';
105 }
6006c31d 106 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
89adb174 107 if ($ismoving) {
108 if ($mod->id == $USER->activitycopy) {
109 continue;
110 }
d4a1fcaf 111 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 112 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 113 $this->content->icons[] = '';
dd97c328 114 }
0d8b6a69 115 list($content, $instancename) =
116 get_print_section_cm_text($modinfo->cms[$modnumber], $course);
89adb174 117 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
89adb174 118
0d8b6a69 119 if (!($url = $mod->get_url())) {
120 $this->content->items[] = $content . $editbuttons;
89adb174 121 $this->content->icons[] = '';
122 } else {
dd97c328 123 //Accessibility: incidental image - should be empty Alt text
0d8b6a69 124 $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
125 $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
126 ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
89adb174 127 }
128 }
129 }
130 }
131
132 if ($ismoving) {
d4a1fcaf 133 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 134 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 135 $this->content->icons[] = '';
136 }
137
51f2e837 138 if (!empty($modnames)) {
4fad3618 139 $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
89adb174 140 } else {
141 $this->content->footer = '';
142 }
143
144 return $this->content;
145 }
146}
147
4ca6cfbf 148