MDL-43211 blocks: style edit icons in main menu and social activities
[moodle.git] / blocks / site_main_menu / block_site_main_menu.php
CommitLineData
4ca6cfbf 1<?php
89adb174 2
3ef642d9 3class block_site_main_menu extends block_list {
9b4b78fd 4 function init() {
0f14f7e6 5 $this->title = get_string('pluginname', 'block_site_main_menu');
89adb174 6 }
8571833f 7
89adb174 8 function applicable_formats() {
2b0d60ec 9 return array('site' => true);
89adb174 10 }
11
12 function get_content() {
6b608f8f 13 global $USER, $CFG, $DB, $OUTPUT;
89adb174 14
2eb68e6f 15 if ($this->content !== NULL) {
89adb174 16 return $this->content;
17 }
18
dd4bee83 19 $this->content = new stdClass();
89adb174 20 $this->content->items = array();
21 $this->content->icons = array();
22 $this->content->footer = '';
23
9b4b78fd 24 if (empty($this->instance)) {
25 return $this->content;
26 }
27
3179b000 28 $course = $this->page->course;
dd97c328 29 require_once($CFG->dirroot.'/course/lib.php');
fe2fdd11 30 $context = context_course::instance($course->id);
cb640229 31 $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
dd97c328 32
33/// extra fast view mode
34 if (!$isediting) {
71a56e08 35 $modinfo = get_fast_modinfo($course);
dd97c328 36 if (!empty($modinfo->sections[0])) {
367a75fa 37 $options = array('overflowdiv'=>true);
dd97c328 38 foreach($modinfo->sections[0] as $cmid) {
39 $cm = $modinfo->cms[$cmid];
40 if (!$cm->uservisible) {
41 continue;
42 }
0d8b6a69 43
f89c53f6
MG
44 $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
45 $instancename = $cm->get_formatted_name();
0d8b6a69 46
73ee2fda 47 if (!($url = $cm->url)) {
0d8b6a69 48 $this->content->items[] = $content;
dd97c328 49 $this->content->icons[] = '';
50 } else {
51 $linkcss = $cm->visible ? '' : ' class="dimmed" ';
dd97c328 52 //Accessibility: incidental image - should be empty Alt text
11f87187 53 $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />';
710363c9 54 $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
0d8b6a69 55 ' href="' . $url . '">' . $icon . $instancename . '</a>';
dd97c328 56 }
57 }
58 }
59 return $this->content;
60 }
61
ea5a01fb
SH
62 // Slow & hacky editing mode.
63 /** @var core_course_renderer $courserenderer */
9a36be73 64 $courserenderer = $this->page->get_renderer('core', 'course');
3179b000 65 $ismoving = ismoving($course->id);
4ede27b2 66 course_create_sections_if_missing($course, 0);
71a56e08 67 $modinfo = get_fast_modinfo($course);
4ede27b2 68 $section = $modinfo->get_section_info(0);
89adb174 69
89adb174 70 if ($ismoving) {
71 $strmovehere = get_string('movehere');
72 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
73 $strcancel= get_string('cancel');
74 $stractivityclipboard = $USER->activitycopyname;
75 }
89adb174 76 $editbuttons = '';
77
78 if ($ismoving) {
b5d0cafc 79 $this->content->icons[] = '<img src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
d4a1fcaf 80 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
89adb174 81 }
82
71a56e08 83 if (!empty($modinfo->sections[0])) {
367a75fa 84 $options = array('overflowdiv'=>true);
71a56e08
MG
85 foreach ($modinfo->sections[0] as $modnumber) {
86 $mod = $modinfo->cms[$modnumber];
87 if (!$mod->uservisible) {
89adb174 88 continue;
89 }
dd97c328 90 if (!$ismoving) {
9a36be73 91 $actions = course_get_cm_edit_actions($mod, -1);
2a974bb7
JM
92
93 // Add the action move.
94 $modcontext = context_module::instance($mod->id);
95 $hasmanageactivities = has_capability('moodle/course:manageactivities', $modcontext);
96 if ($hasmanageactivities) {
97 $baseurl = new moodle_url('/course/mod.php', array('sesskey' => sesskey()));
98 $actions['move'] = new action_menu_link_primary(
99 new moodle_url($baseurl, array('copy' => $mod->id)),
100 new pix_icon('t/move', get_string('move'), 'moodle', array('class' => 'iconsmall', 'title' => '')),
101 null,
102 array('title' => get_string('move'))
103 );
104 }
105
9a36be73 106 $editbuttons = html_writer::tag('div',
f803ce26
SH
107 $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)),
108 array('class' => 'buttons')
109 );
89adb174 110 } else {
111 $editbuttons = '';
112 }
6006c31d 113 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
89adb174 114 if ($ismoving) {
115 if ($mod->id == $USER->activitycopy) {
116 continue;
117 }
d4a1fcaf 118 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 119 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 120 $this->content->icons[] = '';
dd97c328 121 }
f89c53f6
MG
122 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
123 $instancename = $mod->get_formatted_name();
89adb174 124 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
89adb174 125
73ee2fda 126 if (!($url = $mod->url)) {
0d8b6a69 127 $this->content->items[] = $content . $editbuttons;
89adb174 128 $this->content->icons[] = '';
129 } else {
dd97c328 130 //Accessibility: incidental image - should be empty Alt text
11f87187 131 $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />';
0d8b6a69 132 $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
133 ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
89adb174 134 }
135 }
136 }
137 }
138
139 if ($ismoving) {
d4a1fcaf 140 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 141 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
89adb174 142 $this->content->icons[] = '';
143 }
144
9a6aa5c1
MG
145 $this->content->footer = $courserenderer->course_section_add_cm_control($course,
146 0, null, array('inblock' => true));
89adb174 147
148 return $this->content;
149 }
150}
151
4ca6cfbf 152