89adb174 |
1 | <?php //$Id$ |
2 | |
3ef642d9 |
3 | class block_site_main_menu extends block_list { |
9b4b78fd |
4 | function init() { |
89adb174 |
5 | $this->title = get_string('mainmenu'); |
433c242f |
6 | $this->version = 2007101509; |
89adb174 |
7 | } |
8 | |
9 | function applicable_formats() { |
2b0d60ec |
10 | return array('site' => true); |
89adb174 |
11 | } |
12 | |
13 | function get_content() { |
6b608f8f |
14 | global $USER, $CFG, $DB, $OUTPUT; |
89adb174 |
15 | |
2eb68e6f |
16 | if ($this->content !== NULL) { |
89adb174 |
17 | return $this->content; |
18 | } |
19 | |
dd97c328 |
20 | $this->content = new object(); |
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 | |
3179b000 |
29 | $course = $this->page->course; |
dd97c328 |
30 | require_once($CFG->dirroot.'/course/lib.php'); |
dd97c328 |
31 | $context = get_context_instance(CONTEXT_COURSE, $course->id); |
cb640229 |
32 | $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context); |
830dd6e9 |
33 | $modinfo = get_fast_modinfo($course); |
dd97c328 |
34 | |
35 | /// extra fast view mode |
36 | if (!$isediting) { |
37 | if (!empty($modinfo->sections[0])) { |
38 | foreach($modinfo->sections[0] as $cmid) { |
39 | $cm = $modinfo->cms[$cmid]; |
40 | if (!$cm->uservisible) { |
41 | continue; |
42 | } |
43 | if ($cm->modname == 'label') { |
44 | $this->content->items[] = format_text($cm->extra, FORMAT_HTML); |
45 | $this->content->icons[] = ''; |
46 | } else { |
47 | $linkcss = $cm->visible ? '' : ' class="dimmed" '; |
48 | $instancename = format_string($cm->name, true, $course->id); |
49 | $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra. |
50 | ' href="'.$CFG->wwwroot.'/mod/'.$cm->modname.'/view.php?id='.$cm->id.'">'.$instancename.'</a>'; |
51 | //Accessibility: incidental image - should be empty Alt text |
52 | if (!empty($cm->icon)) { |
e63f88c9 |
53 | $icon = $OUTPUT->old_icon_url($cm->icon); |
dd97c328 |
54 | } else { |
e63f88c9 |
55 | $icon = $OUTPUT->mod_icon_url('icon', $cm->modname); |
dd97c328 |
56 | } |
57 | $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />'; |
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) { |
6b608f8f |
83 | $this->content->icons[] = '<img src="'.$OUTPUT->old_icon_url('t/move') . '" class="iconsmall" alt="" />'; |
d4a1fcaf |
84 | $this->content->items[] = $USER->activitycopyname.' (<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&sesskey='.sesskey().'">'.$strcancel.'</a>)'; |
89adb174 |
85 | } |
86 | |
1a4872b6 |
87 | if (!empty($section->sequence)) { |
89adb174 |
88 | $sectionmods = explode(',', $section->sequence); |
89 | foreach ($sectionmods as $modnumber) { |
90 | if (empty($mods[$modnumber])) { |
91 | continue; |
92 | } |
93 | $mod = $mods[$modnumber]; |
dd97c328 |
94 | if (!$ismoving) { |
89adb174 |
95 | if ($groupbuttons) { |
96 | if (! $mod->groupmodelink = $groupbuttonslink) { |
9b4b78fd |
97 | $mod->groupmode = $course->groupmode; |
89adb174 |
98 | } |
99 | |
100 | } else { |
101 | $mod->groupmode = false; |
102 | } |
f82c88ab |
103 | $editbuttons = '<div class="buttons">'.make_editing_buttons($mod, true, true).'</div>'; |
89adb174 |
104 | } else { |
105 | $editbuttons = ''; |
106 | } |
6006c31d |
107 | if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) { |
89adb174 |
108 | if ($ismoving) { |
109 | if ($mod->id == $USER->activitycopy) { |
110 | continue; |
111 | } |
d4a1fcaf |
112 | $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&sesskey='.sesskey().'">'. |
e63f88c9 |
113 | '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->old_icon_url('movehere') . '" alt="'.$strmovehere.'" /></a>'; |
89adb174 |
114 | $this->content->icons[] = ''; |
dd97c328 |
115 | } |
116 | $instancename = $modinfo->cms[$modnumber]->name; |
3179b000 |
117 | $instancename = format_string($instancename, true, $course->id); |
89adb174 |
118 | $linkcss = $mod->visible ? '' : ' class="dimmed" '; |
dd97c328 |
119 | if (!empty($modinfo->cms[$modnumber]->extra)) { |
120 | $extra = $modinfo->cms[$modnumber]->extra; |
89adb174 |
121 | } else { |
122 | $extra = ''; |
123 | } |
dd97c328 |
124 | if (!empty($modinfo->cms[$modnumber]->icon)) { |
e63f88c9 |
125 | $icon = $OUTPUT->old_icon_url($modinfo->cms[$modnumber]->icon); |
facf75c1 |
126 | } else { |
e63f88c9 |
127 | $icon = $OUTPUT->mod_icon_url('icon', $mod->modname); |
facf75c1 |
128 | } |
89adb174 |
129 | |
130 | if ($mod->modname == 'label') { |
131 | $this->content->items[] = format_text($extra, FORMAT_HTML).$editbuttons; |
132 | $this->content->icons[] = ''; |
133 | } else { |
134 | $this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra. |
135 | ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$instancename.'</a>'.$editbuttons; |
dd97c328 |
136 | //Accessibility: incidental image - should be empty Alt text |
f82c88ab |
137 | $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />'; |
89adb174 |
138 | } |
139 | } |
140 | } |
141 | } |
142 | |
143 | if ($ismoving) { |
d4a1fcaf |
144 | $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&sesskey='.sesskey().'">'. |
e63f88c9 |
145 | '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->old_icon_url('movehere') . '" alt="'.$strmovehere.'" /></a>'; |
89adb174 |
146 | $this->content->icons[] = ''; |
147 | } |
148 | |
51f2e837 |
149 | if (!empty($modnames)) { |
4fad3618 |
150 | $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true); |
89adb174 |
151 | } else { |
152 | $this->content->footer = ''; |
153 | } |
154 | |
155 | return $this->content; |
156 | } |
157 | } |
158 | |
159 | ?> |