weekly release
[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');
dd97c328 30 $context = get_context_instance(CONTEXT_COURSE, $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 }
43 if ($cm->modname == 'label') {
367a75fa 44 $this->content->items[] = format_text($cm->extra, FORMAT_HTML, $options);
dd97c328 45 $this->content->icons[] = '';
46 } else {
47 $linkcss = $cm->visible ? '' : ' class="dimmed" ';
48 $instancename = format_string($cm->name, true, $course->id);
dd97c328 49 //Accessibility: incidental image - should be empty Alt text
50 if (!empty($cm->icon)) {
b5d0cafc 51 $icon = $OUTPUT->pix_url($cm->icon);
dd97c328 52 } else {
b5d0cafc 53 $icon = $OUTPUT->pix_url('icon', $cm->modname);
dd97c328 54 }
710363c9
RW
55 $icon = '<img src="'.$icon.'" class="icon" alt="" />&nbsp;';
56 $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
57 ' href="'.$CFG->wwwroot.'/mod/'.$cm->modname.'/view.php?id='.$cm->id.'">'.$icon.$instancename.'</a>';
dd97c328 58 }
59 }
60 }
61 return $this->content;
62 }
63
dd97c328 64/// slow & hacky editing mode
3179b000 65 $ismoving = ismoving($course->id);
66 $section = get_course_section(0, $course->id);
a2f96413 67
3179b000 68 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
89adb174 69
9b4b78fd 70 $groupbuttons = $course->groupmode;
71 $groupbuttonslink = (!$course->groupmodeforce);
89adb174 72
73 if ($ismoving) {
74 $strmovehere = get_string('movehere');
75 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
76 $strcancel= get_string('cancel');
77 $stractivityclipboard = $USER->activitycopyname;
78 }
fea43a7f 79 /// Casting $course->modinfo to string prevents one notice when the field is null
89adb174 80 $editbuttons = '';
81
82 if ($ismoving) {
b5d0cafc 83 $this->content->icons[] = '<img src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
d4a1fcaf 84 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
89adb174 85 }
86
1a4872b6 87 if (!empty($section->sequence)) {
89adb174 88 $sectionmods = explode(',', $section->sequence);
367a75fa 89 $options = array('overflowdiv'=>true);
89adb174 90 foreach ($sectionmods as $modnumber) {
91 if (empty($mods[$modnumber])) {
92 continue;
93 }
94 $mod = $mods[$modnumber];
dd97c328 95 if (!$ismoving) {
89adb174 96 if ($groupbuttons) {
97 if (! $mod->groupmodelink = $groupbuttonslink) {
9b4b78fd 98 $mod->groupmode = $course->groupmode;
89adb174 99 }
100
101 } else {
102 $mod->groupmode = false;
103 }
f82c88ab 104 $editbuttons = '<div class="buttons">'.make_editing_buttons($mod, true, true).'</div>';
89adb174 105 } else {
106 $editbuttons = '';
107 }
6006c31d 108 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
89adb174 109 if ($ismoving) {
110 if ($mod->id == $USER->activitycopy) {
111 continue;
112 }
d4a1fcaf 113 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 114 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 115 $this->content->icons[] = '';
dd97c328 116 }
117 $instancename = $modinfo->cms[$modnumber]->name;
3179b000 118 $instancename = format_string($instancename, true, $course->id);
89adb174 119 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
dd97c328 120 if (!empty($modinfo->cms[$modnumber]->extra)) {
121 $extra = $modinfo->cms[$modnumber]->extra;
89adb174 122 } else {
123 $extra = '';
124 }
dd97c328 125 if (!empty($modinfo->cms[$modnumber]->icon)) {
b5d0cafc 126 $icon = $OUTPUT->pix_url($modinfo->cms[$modnumber]->icon);
facf75c1 127 } else {
b5d0cafc 128 $icon = $OUTPUT->pix_url('icon', $mod->modname);
facf75c1 129 }
89adb174 130
131 if ($mod->modname == 'label') {
367a75fa 132 $this->content->items[] = format_text($extra, FORMAT_HTML,$options).$editbuttons;
89adb174 133 $this->content->icons[] = '';
134 } else {
dd97c328 135 //Accessibility: incidental image - should be empty Alt text
710363c9
RW
136 $icon = '<img src="'.$icon.'" class="icon" alt="" />&nbsp;';
137 $this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
dd4bee83 138 ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$icon.$instancename.'</a>'.$editbuttons;
89adb174 139 }
140 }
141 }
142 }
143
144 if ($ismoving) {
d4a1fcaf 145 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 146 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 147 $this->content->icons[] = '';
148 }
149
51f2e837 150 if (!empty($modnames)) {
4fad3618 151 $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
89adb174 152 } else {
153 $this->content->footer = '';
154 }
155
156 return $this->content;
157 }
158}
159
4ca6cfbf 160