on-demand release 2.4dev
[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
46 list($content, $instancename) =
47 get_print_section_cm_text($cm, $course);
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);
67 $sections = get_all_sections($course->id);
9b4b78fd 68
dd97c328 69 if(!empty($sections) && isset($sections[0])) {
70 $section = $sections[0];
71 }
0f3fe4b6 72
dd97c328 73 if (!empty($section)) {
3179b000 74 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
dd97c328 75 }
0f3fe4b6 76
9b4b78fd 77 $groupbuttons = $course->groupmode;
78 $groupbuttonslink = (!$course->groupmodeforce);
dd97c328 79
0f3fe4b6 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
0f3fe4b6 87 $editbuttons = '';
88
89 if ($ismoving) {
b5d0cafc 90 $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
d4a1fcaf 91 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
0f3fe4b6 92 }
93
dd97c328 94 if (!empty($section) && !empty($section->sequence)) {
0f3fe4b6 95 $sectionmods = explode(',', $section->sequence);
367a75fa 96 $options = array('overflowdiv'=>true);
0f3fe4b6 97 foreach ($sectionmods as $modnumber) {
98 if (empty($mods[$modnumber])) {
99 continue;
100 }
101 $mod = $mods[$modnumber];
dd97c328 102 if (!$ismoving) {
0f3fe4b6 103 if ($groupbuttons) {
104 if (! $mod->groupmodelink = $groupbuttonslink) {
9b4b78fd 105 $mod->groupmode = $course->groupmode;
0f3fe4b6 106 }
107
108 } else {
109 $mod->groupmode = false;
110 }
111 $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
112 } else {
113 $editbuttons = '';
114 }
dd97c328 115 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
0f3fe4b6 116 if ($ismoving) {
117 if ($mod->id == $USER->activitycopy) {
118 continue;
119 }
d4a1fcaf 120 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 121 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
0f3fe4b6 122 $this->content->icons[] = '';
123 }
0d8b6a69 124 list($content, $instancename) =
125 get_print_section_cm_text($modinfo->cms[$modnumber], $course);
126
0f3fe4b6 127 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
0f3fe4b6 128
0d8b6a69 129 if (!($url = $mod->get_url())) {
130 $this->content->items[] = $content . $editbuttons;
0f3fe4b6 131 $this->content->icons[] = '';
132 } else {
dd97c328 133 //Accessibility: incidental image - should be empty Alt text
0d8b6a69 134 $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
135 $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
136 ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
0f3fe4b6 137 }
138 }
139 }
140 }
141
142 if ($ismoving) {
d4a1fcaf 143 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 144 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
0f3fe4b6 145 $this->content->icons[] = '';
146 }
147
dd97c328 148 if ($modnames) {
4fad3618 149 $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
0f3fe4b6 150 } else {
151 $this->content->footer = '';
152 }
153
154 return $this->content;
155 }
156}
157
4ca6cfbf 158