MDL-37085 Substitute function print_section_add_menus() with core_course_renderer...
[moodle.git] / blocks / social_activities / block_social_activities.php
CommitLineData
4ca6cfbf 1<?php
0f3fe4b6 2
3ef642d9 3class block_social_activities extends block_list {
9b4b78fd 4 function init(){
513d33d6 5 $this->title = get_string('pluginname', 'block_social_activities');
0f3fe4b6 6 }
7
8 function applicable_formats() {
8a47e075 9 return array('course-view-social' => true);
0f3fe4b6 10 }
11
12 function get_content() {
6b608f8f 13 global $USER, $CFG, $DB, $OUTPUT;
0f3fe4b6 14
2eb68e6f 15 if ($this->content !== NULL) {
0f3fe4b6 16 return $this->content;
17 }
18
dd4bee83 19 $this->content = new stdClass();
0f3fe4b6 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
30 require_once($CFG->dirroot.'/course/lib.php');
31
fe2fdd11 32 $context = context_course::instance($course->id);
cb640229 33 $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
dd97c328 34 $modinfo = get_fast_modinfo($course);
35
36/// extra fast view mode
37 if (!$isediting) {
38 if (!empty($modinfo->sections[0])) {
367a75fa 39 $options = array('overflowdiv'=>true);
dd97c328 40 foreach($modinfo->sections[0] as $cmid) {
41 $cm = $modinfo->cms[$cmid];
42 if (!$cm->uservisible) {
43 continue;
44 }
0d8b6a69 45
f89c53f6
MG
46 $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
47 $instancename = $cm->get_formatted_name();
0d8b6a69 48
49 if (!($url = $cm->get_url())) {
50 $this->content->items[] = $content;
dd97c328 51 $this->content->icons[] = '';
52 } else {
53 $linkcss = $cm->visible ? '' : ' class="dimmed" ';
dd97c328 54 //Accessibility: incidental image - should be empty Alt text
0d8b6a69 55 $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />&nbsp;';
710363c9 56 $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
0d8b6a69 57 ' href="' . $url . '">' . $icon . $instancename . '</a>';
dd97c328 58 }
59 }
60 }
61 return $this->content;
62 }
63
64
65/// slow & hacky editing mode
3179b000 66 $ismoving = ismoving($course->id);
71a56e08
MG
67 $modinfo = get_fast_modinfo($course);
68 $section = $modinfo->get_section_info(0);
0f3fe4b6 69
9b4b78fd 70 $groupbuttons = $course->groupmode;
71 $groupbuttonslink = (!$course->groupmodeforce);
dd97c328 72
0f3fe4b6 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
0f3fe4b6 80 $editbuttons = '';
81
82 if ($ismoving) {
b5d0cafc 83 $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
d4a1fcaf 84 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
0f3fe4b6 85 }
86
71a56e08 87 if (!empty($modinfo->sections[0])) {
367a75fa 88 $options = array('overflowdiv'=>true);
71a56e08
MG
89 foreach ($modinfo->sections[0] as $modnumber) {
90 $mod = $modinfo->cms[$modnumber];
91 if (!$mod->uservisible) {
0f3fe4b6 92 continue;
93 }
dd97c328 94 if (!$ismoving) {
0f3fe4b6 95 if ($groupbuttons) {
96 if (! $mod->groupmodelink = $groupbuttonslink) {
9b4b78fd 97 $mod->groupmode = $course->groupmode;
0f3fe4b6 98 }
99
100 } else {
101 $mod->groupmode = false;
102 }
103 $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
104 } else {
105 $editbuttons = '';
106 }
dd97c328 107 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
0f3fe4b6 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.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 113 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
0f3fe4b6 114 $this->content->icons[] = '';
115 }
f89c53f6
MG
116 $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
117 $instancename = $mod->get_formatted_name();
0d8b6a69 118
0f3fe4b6 119 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
0f3fe4b6 120
0d8b6a69 121 if (!($url = $mod->get_url())) {
122 $this->content->items[] = $content . $editbuttons;
0f3fe4b6 123 $this->content->icons[] = '';
124 } else {
dd97c328 125 //Accessibility: incidental image - should be empty Alt text
0d8b6a69 126 $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
127 $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
128 ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
0f3fe4b6 129 }
130 }
131 }
132 }
133
134 if ($ismoving) {
d4a1fcaf 135 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 136 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
0f3fe4b6 137 $this->content->icons[] = '';
138 }
139
9a6aa5c1
MG
140 $courserenderer = $this->page->get_renderer('core', 'course');
141 $this->content->footer = $courserenderer->course_section_add_cm_control($course,
142 0, null, array('inblock' => true));
0f3fe4b6 143
144 return $this->content;
145 }
146}
147
4ca6cfbf 148