MDL-22054 converting block name strings to pluginname
[moodle.git] / blocks / site_main_menu / block_site_main_menu.php
1 <?php
3 class block_site_main_menu extends block_list {
4     function init() {
5         $this->title = get_string('pluginname', 'block_site_main_menu');
6         $this->version = 2007101509;
7     }
8     
9     function applicable_formats() {
10         return array('site' => true);
11     }
13     function get_content() {
14         global $USER, $CFG, $DB, $OUTPUT;
16         if ($this->content !== NULL) {
17             return $this->content;
18         }
20         $this->content = new object();
21         $this->content->items = array();
22         $this->content->icons = array();
23         $this->content->footer = '';
25         if (empty($this->instance)) {
26             return $this->content;
27         }
29         $course = $this->page->course;
30         require_once($CFG->dirroot.'/course/lib.php');
31         $context = get_context_instance(CONTEXT_COURSE, $course->id);
32         $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
33         $modinfo = get_fast_modinfo($course);
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)) {
53                             $icon = $OUTPUT->pix_url($cm->icon);
54                         } else {
55                             $icon = $OUTPUT->pix_url('icon', $cm->modname);
56                         }
57                         $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
58                     }
59                 }
60             }
61             return $this->content;
62         }
64 /// slow & hacky editing mode
65         $ismoving = ismoving($course->id);
66         $section  = get_course_section(0, $course->id);
68         get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
70         $groupbuttons = $course->groupmode;
71         $groupbuttonslink = (!$course->groupmodeforce);
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         }
79     /// Casting $course->modinfo to string prevents one notice when the field is null
80         $editbuttons = '';
82         if ($ismoving) {
83             $this->content->icons[] = '<img src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
84             $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
85         }
87         if (!empty($section->sequence)) {
88             $sectionmods = explode(',', $section->sequence);
89             foreach ($sectionmods as $modnumber) {
90                 if (empty($mods[$modnumber])) {
91                     continue;
92                 }
93                 $mod = $mods[$modnumber];
94                 if (!$ismoving) {
95                     if ($groupbuttons) {
96                         if (! $mod->groupmodelink = $groupbuttonslink) {
97                             $mod->groupmode = $course->groupmode;
98                         }
100                     } else {
101                         $mod->groupmode = false;
102                     }
103                     $editbuttons = '<div class="buttons">'.make_editing_buttons($mod, true, true).'</div>';
104                 } else {
105                     $editbuttons = '';
106                 }
107                 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
108                     if ($ismoving) {
109                         if ($mod->id == $USER->activitycopy) {
110                             continue;
111                         }
112                         $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
113                             '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
114                         $this->content->icons[] = '';
115                     }
116                     $instancename = $modinfo->cms[$modnumber]->name;
117                     $instancename = format_string($instancename, true, $course->id);
118                     $linkcss = $mod->visible ? '' : ' class="dimmed" ';
119                     if (!empty($modinfo->cms[$modnumber]->extra)) {
120                         $extra = $modinfo->cms[$modnumber]->extra;
121                     } else {
122                         $extra = '';
123                     }
124                     if (!empty($modinfo->cms[$modnumber]->icon)) {
125                         $icon = $OUTPUT->pix_url($modinfo->cms[$modnumber]->icon);
126                     } else {
127                         $icon = $OUTPUT->pix_url('icon', $mod->modname);
128                     }
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;
136                         //Accessibility: incidental image - should be empty Alt text
137                         $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
138                     }
139                 }
140             }
141         }
143         if ($ismoving) {
144             $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
145                                       '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
146             $this->content->icons[] = '';
147         }
149         if (!empty($modnames)) {
150             $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
151         } else {
152             $this->content->footer = '';
153         }
155         return $this->content;
156     }