3 class block_site_main_menu extends block_list {
5 $this->title = get_string('pluginname', 'block_site_main_menu');
8 function applicable_formats() {
9 return array('site' => true);
12 function get_content() {
13 global $USER, $CFG, $DB, $OUTPUT;
15 if ($this->content !== NULL) {
16 return $this->content;
19 $this->content = new stdClass();
20 $this->content->items = array();
21 $this->content->icons = array();
22 $this->content->footer = '';
24 if (empty($this->instance)) {
25 return $this->content;
28 $course = $this->page->course;
29 require_once($CFG->dirroot.'/course/lib.php');
30 $context = context_course::instance($course->id);
31 $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
33 /// extra fast view mode
35 $modinfo = get_fast_modinfo($course);
36 if (!empty($modinfo->sections[0])) {
37 $options = array('overflowdiv'=>true);
38 foreach($modinfo->sections[0] as $cmid) {
39 $cm = $modinfo->cms[$cmid];
40 if (!$cm->uservisible) {
44 $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
45 $instancename = $cm->get_formatted_name();
47 if (!($url = $cm->get_url())) {
48 $this->content->items[] = $content;
49 $this->content->icons[] = '';
51 $linkcss = $cm->visible ? '' : ' class="dimmed" ';
52 //Accessibility: incidental image - should be empty Alt text
53 $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
54 $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
55 ' href="' . $url . '">' . $icon . $instancename . '</a>';
59 return $this->content;
62 /// slow & hacky editing mode
63 $ismoving = ismoving($course->id);
64 course_create_sections_if_missing($course, 0);
65 $modinfo = get_fast_modinfo($course);
66 $section = $modinfo->get_section_info(0);
68 $groupbuttons = $course->groupmode;
69 $groupbuttonslink = (!$course->groupmodeforce);
72 $strmovehere = get_string('movehere');
73 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
74 $strcancel= get_string('cancel');
75 $stractivityclipboard = $USER->activitycopyname;
77 /// Casting $course->modinfo to string prevents one notice when the field is null
81 $this->content->icons[] = '<img src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
82 $this->content->items[] = $USER->activitycopyname.' (<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&sesskey='.sesskey().'">'.$strcancel.'</a>)';
85 if (!empty($modinfo->sections[0])) {
86 $options = array('overflowdiv'=>true);
87 foreach ($modinfo->sections[0] as $modnumber) {
88 $mod = $modinfo->cms[$modnumber];
89 if (!$mod->uservisible) {
94 if (! $mod->groupmodelink = $groupbuttonslink) {
95 $mod->groupmode = $course->groupmode;
99 $mod->groupmode = false;
101 $editbuttons = '<div class="buttons">'.make_editing_buttons($mod, true, true).'</div>';
105 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
107 if ($mod->id == $USER->activitycopy) {
110 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&sesskey='.sesskey().'">'.
111 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
112 $this->content->icons[] = '';
114 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
115 $instancename = $mod->get_formatted_name();
116 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
118 if (!($url = $mod->get_url())) {
119 $this->content->items[] = $content . $editbuttons;
120 $this->content->icons[] = '';
122 //Accessibility: incidental image - should be empty Alt text
123 $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />';
124 $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
125 ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
132 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&sesskey='.sesskey().'">'.
133 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
134 $this->content->icons[] = '';
137 $courserenderer = $this->page->get_renderer('core', 'course');
138 $this->content->footer = $courserenderer->course_section_add_cm_control($course,
139 0, null, array('inblock' => true));
141 return $this->content;