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