MDL-22054 converting block name strings to pluginname
[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');
433c242f 6 $this->version = 2007101509;
0f3fe4b6 7 }
8
9 function applicable_formats() {
8a47e075 10 return array('course-view-social' => true);
0f3fe4b6 11 }
12
13 function get_content() {
6b608f8f 14 global $USER, $CFG, $DB, $OUTPUT;
0f3fe4b6 15
2eb68e6f 16 if ($this->content !== NULL) {
0f3fe4b6 17 return $this->content;
18 }
19
dd97c328 20 $this->content = new object();
0f3fe4b6 21 $this->content->items = array();
22 $this->content->icons = array();
23 $this->content->footer = '';
24
9b4b78fd 25 if (empty($this->instance)) {
26 return $this->content;
27 }
28
3179b000 29 $course = $this->page->course;
dd97c328 30
31 require_once($CFG->dirroot.'/course/lib.php');
32
01199ea9 33 $context = get_context_instance(CONTEXT_COURSE, $course->id);
cb640229 34 $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
dd97c328 35 $modinfo = get_fast_modinfo($course);
36
37/// extra fast view mode
38 if (!$isediting) {
39 if (!empty($modinfo->sections[0])) {
40 foreach($modinfo->sections[0] as $cmid) {
41 $cm = $modinfo->cms[$cmid];
42 if (!$cm->uservisible) {
43 continue;
44 }
45 if ($cm->modname == 'label') {
46 $this->content->items[] = format_text($cm->extra, FORMAT_HTML);
47 $this->content->icons[] = '';
48 } else {
49 $linkcss = $cm->visible ? '' : ' class="dimmed" ';
50 $instancename = format_string($cm->name, true, $course->id);
51 $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
52 ' href="'.$CFG->wwwroot.'/mod/'.$cm->modname.'/view.php?id='.$cm->id.'">'.$instancename.'</a>';
53 //Accessibility: incidental image - should be empty Alt text
54 if (!empty($cm->icon)) {
b5d0cafc 55 $icon = $OUTPUT->pix_url($cm->icon);
dd97c328 56 } else {
b5d0cafc 57 $icon = $OUTPUT->pix_url('icon', $cm->modname);
dd97c328 58 }
59 $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
60 }
61 }
62 }
63 return $this->content;
64 }
65
66
67/// slow & hacky editing mode
3179b000 68 $ismoving = ismoving($course->id);
69 $sections = get_all_sections($course->id);
9b4b78fd 70
dd97c328 71 if(!empty($sections) && isset($sections[0])) {
72 $section = $sections[0];
73 }
0f3fe4b6 74
dd97c328 75 if (!empty($section)) {
3179b000 76 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
dd97c328 77 }
0f3fe4b6 78
9b4b78fd 79 $groupbuttons = $course->groupmode;
80 $groupbuttonslink = (!$course->groupmodeforce);
dd97c328 81
0f3fe4b6 82 if ($ismoving) {
83 $strmovehere = get_string('movehere');
84 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
85 $strcancel= get_string('cancel');
86 $stractivityclipboard = $USER->activitycopyname;
87 }
fea43a7f 88 /// Casting $course->modinfo to string prevents one notice when the field is null
0f3fe4b6 89 $editbuttons = '';
90
91 if ($ismoving) {
b5d0cafc 92 $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
d4a1fcaf 93 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
0f3fe4b6 94 }
95
dd97c328 96 if (!empty($section) && !empty($section->sequence)) {
0f3fe4b6 97 $sectionmods = explode(',', $section->sequence);
98 foreach ($sectionmods as $modnumber) {
99 if (empty($mods[$modnumber])) {
100 continue;
101 }
102 $mod = $mods[$modnumber];
dd97c328 103 if (!$ismoving) {
0f3fe4b6 104 if ($groupbuttons) {
105 if (! $mod->groupmodelink = $groupbuttonslink) {
9b4b78fd 106 $mod->groupmode = $course->groupmode;
0f3fe4b6 107 }
108
109 } else {
110 $mod->groupmode = false;
111 }
112 $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
113 } else {
114 $editbuttons = '';
115 }
dd97c328 116 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
0f3fe4b6 117 if ($ismoving) {
118 if ($mod->id == $USER->activitycopy) {
119 continue;
120 }
d4a1fcaf 121 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 122 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
0f3fe4b6 123 $this->content->icons[] = '';
124 }
dd97c328 125 $instancename = $modinfo->cms[$modnumber]->name;
3179b000 126 $instancename = format_string($instancename, true, $course->id);
0f3fe4b6 127 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
dd97c328 128 if (!empty($modinfo->cms[$modnumber]->extra)) {
129 $extra = $modinfo->cms[$modnumber]->extra;
0f3fe4b6 130 } else {
131 $extra = '';
132 }
dd97c328 133 if (!empty($modinfo->cms[$modnumber]->icon)) {
b5d0cafc 134 $icon = $OUTPUT->pix_url($modinfo->cms[$modnumber]->icon);
facf75c1 135 } else {
b5d0cafc 136 $icon = $OUTPUT->pix_url('icon', $mod->modname);
facf75c1 137 }
0f3fe4b6 138
139 if ($mod->modname == 'label') {
140 $this->content->items[] = format_text($extra, FORMAT_HTML).$editbuttons;
141 $this->content->icons[] = '';
142 } else {
143 $this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
144 ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$instancename.'</a>'.$editbuttons;
dd97c328 145 //Accessibility: incidental image - should be empty Alt text
146 $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
0f3fe4b6 147 }
148 }
149 }
150 }
151
152 if ($ismoving) {
d4a1fcaf 153 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
b5d0cafc 154 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
0f3fe4b6 155 $this->content->icons[] = '';
156 }
157
dd97c328 158 if ($modnames) {
4fad3618 159 $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
0f3fe4b6 160 } else {
161 $this->content->footer = '';
162 }
163
164 return $this->content;
165 }
166}
167
4ca6cfbf 168