MDL-12627 - when visiting the gradebook for the first time, we don't sort
[moodle.git] / blocks / site_main_menu / block_site_main_menu.php
CommitLineData
89adb174 1<?php //$Id$
2
3ef642d9 3class block_site_main_menu extends block_list {
9b4b78fd 4 function init() {
89adb174 5 $this->title = get_string('mainmenu');
8023ab86 6 $this->version = 2005061300;
89adb174 7 }
8
9 function applicable_formats() {
2b0d60ec 10 return array('site' => true);
89adb174 11 }
12
13 function get_content() {
14 global $USER, $CFG;
15
2eb68e6f 16 if ($this->content !== NULL) {
89adb174 17 return $this->content;
18 }
19
8023ab86 20 $this->content = new stdClass;
89adb174 21 $this->content->items = array();
22 $this->content->icons = array();
23 $this->content->footer = '';
24
9b4b78fd 25 if (empty($this->instance)) {
26 return $this->content;
27 }
28
29 $course = get_record('course', 'id', $this->instance->pageid);
6006c31d 30 $context = get_context_instance(CONTEXT_COURSE, $course->id);
9b4b78fd 31
b286b860 32 $isediting = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context);
9b4b78fd 33 $ismoving = ismoving($this->instance->pageid);
89adb174 34
9b4b78fd 35 $sections = get_all_sections($this->instance->pageid);
a2f96413 36
8023ab86 37 if(!empty($sections) && isset($sections[0])) {
38 $section = $sections[0];
39 }
89adb174 40
8023ab86 41 if (!empty($section) || $isediting) {
9b4b78fd 42 get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
89adb174 43 }
44
9b4b78fd 45 $groupbuttons = $course->groupmode;
46 $groupbuttonslink = (!$course->groupmodeforce);
89adb174 47
48 if ($ismoving) {
49 $strmovehere = get_string('movehere');
50 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
51 $strcancel= get_string('cancel');
52 $stractivityclipboard = $USER->activitycopyname;
53 }
fea43a7f 54 /// Casting $course->modinfo to string prevents one notice when the field is null
55 $modinfo = unserialize((string)$course->modinfo);
56
89adb174 57 $editbuttons = '';
58
59 if ($ismoving) {
f82c88ab 60 $this->content->icons[] = '<img src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" alt="" />';
8b92f5bb 61 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
89adb174 62 }
63
8023ab86 64 if (!empty($section) && !empty($section->sequence)) {
89adb174 65 $sectionmods = explode(',', $section->sequence);
66 foreach ($sectionmods as $modnumber) {
67 if (empty($mods[$modnumber])) {
68 continue;
69 }
70 $mod = $mods[$modnumber];
71 if ($isediting && !$ismoving) {
72 if ($groupbuttons) {
73 if (! $mod->groupmodelink = $groupbuttonslink) {
9b4b78fd 74 $mod->groupmode = $course->groupmode;
89adb174 75 }
76
77 } else {
78 $mod->groupmode = false;
79 }
f82c88ab 80 $editbuttons = '<div class="buttons">'.make_editing_buttons($mod, true, true).'</div>';
89adb174 81 } else {
82 $editbuttons = '';
83 }
6006c31d 84 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
89adb174 85 if ($ismoving) {
86 if ($mod->id == $USER->activitycopy) {
87 continue;
88 }
8b92f5bb 89 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.$USER->sesskey.'">'.
6a18844b 90 '<img style="height:16px; width:80px; border:0px" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" /></a>';
89adb174 91 $this->content->icons[] = '';
92 }
93 $instancename = urldecode($modinfo[$modnumber]->name);
0c75bc8c 94 $instancename = format_string($instancename, true, $this->instance->pageid);
89adb174 95 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
96 if (!empty($modinfo[$modnumber]->extra)) {
97 $extra = urldecode($modinfo[$modnumber]->extra);
98 } else {
99 $extra = '';
100 }
facf75c1 101 if (!empty($modinfo[$modnumber]->icon)) {
102 $icon = $CFG->pixpath.'/'.urldecode($modinfo[$modnumber]->icon);
103 } else {
104 $icon = $CFG->modpixpath.'/'.$mod->modname.'/icon.gif';
105 }
89adb174 106
107 if ($mod->modname == 'label') {
108 $this->content->items[] = format_text($extra, FORMAT_HTML).$editbuttons;
109 $this->content->icons[] = '';
110 } else {
111 $this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
112 ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$instancename.'</a>'.$editbuttons;
f82c88ab 113 //Accessibility: incidental image - should be empty Alt text
114 $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
89adb174 115 }
116 }
117 }
118 }
119
120 if ($ismoving) {
8b92f5bb 121 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.$USER->sesskey.'">'.
6a18844b 122 '<img style="height:16px; width:80px; border:0px" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" /></a>';
89adb174 123 $this->content->icons[] = '';
124 }
125
126 if ($isediting && $modnames) {
4fad3618 127 $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
89adb174 128 } else {
129 $this->content->footer = '';
130 }
131
132 return $this->content;
133 }
134}
135
136?>