blocklib: MDL-19010 refactor blocklib to use block_manager to get the blocks for...
[moodle.git] / blocks / social_activities / block_social_activities.php
CommitLineData
0f3fe4b6 1<?php //$Id$
2
3ef642d9 3class block_social_activities extends block_list {
9b4b78fd 4 function init(){
dd97c328 5 $this->title = get_string('blockname', '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() {
830dd6e9 14 global $USER, $CFG, $COURSE, $DB, $PAGE;
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
dd97c328 29 if ($COURSE->id == $this->instance->pageid) {
30 $course = $COURSE;
31 } else {
98891b93 32 $course = $DB->get_record('course', array('id'=>$this->instance->pageid));
dd97c328 33 }
34
35 require_once($CFG->dirroot.'/course/lib.php');
36
01199ea9 37 $context = get_context_instance(CONTEXT_COURSE, $course->id);
830dd6e9 38 $isediting = $PAGE->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
dd97c328 39 $modinfo = get_fast_modinfo($course);
40
41/// extra fast view mode
42 if (!$isediting) {
43 if (!empty($modinfo->sections[0])) {
44 foreach($modinfo->sections[0] as $cmid) {
45 $cm = $modinfo->cms[$cmid];
46 if (!$cm->uservisible) {
47 continue;
48 }
49 if ($cm->modname == 'label') {
50 $this->content->items[] = format_text($cm->extra, FORMAT_HTML);
51 $this->content->icons[] = '';
52 } else {
53 $linkcss = $cm->visible ? '' : ' class="dimmed" ';
54 $instancename = format_string($cm->name, true, $course->id);
55 $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
56 ' href="'.$CFG->wwwroot.'/mod/'.$cm->modname.'/view.php?id='.$cm->id.'">'.$instancename.'</a>';
57 //Accessibility: incidental image - should be empty Alt text
58 if (!empty($cm->icon)) {
59 $icon = $CFG->pixpath.'/'.$cm->icon;
60 } else {
61 $icon = $CFG->modpixpath.'/'.$cm->modname.'/icon.gif';
62 }
63 $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
64 }
65 }
66 }
67 return $this->content;
68 }
69
70
71/// slow & hacky editing mode
72 $ismoving = ismoving($this->instance->pageid);
73 $sections = get_all_sections($this->instance->pageid);
9b4b78fd 74
dd97c328 75 if(!empty($sections) && isset($sections[0])) {
76 $section = $sections[0];
77 }
0f3fe4b6 78
dd97c328 79 if (!empty($section)) {
80 get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
81 }
0f3fe4b6 82
9b4b78fd 83 $groupbuttons = $course->groupmode;
84 $groupbuttonslink = (!$course->groupmodeforce);
dd97c328 85
0f3fe4b6 86 if ($ismoving) {
87 $strmovehere = get_string('movehere');
88 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
89 $strcancel= get_string('cancel');
90 $stractivityclipboard = $USER->activitycopyname;
91 }
fea43a7f 92 /// Casting $course->modinfo to string prevents one notice when the field is null
0f3fe4b6 93 $editbuttons = '';
94
95 if ($ismoving) {
0d905d9f 96 $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" alt="" />';
d4a1fcaf 97 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
0f3fe4b6 98 }
99
dd97c328 100 if (!empty($section) && !empty($section->sequence)) {
0f3fe4b6 101 $sectionmods = explode(',', $section->sequence);
102 foreach ($sectionmods as $modnumber) {
103 if (empty($mods[$modnumber])) {
104 continue;
105 }
106 $mod = $mods[$modnumber];
dd97c328 107 if (!$ismoving) {
0f3fe4b6 108 if ($groupbuttons) {
109 if (! $mod->groupmodelink = $groupbuttonslink) {
9b4b78fd 110 $mod->groupmode = $course->groupmode;
0f3fe4b6 111 }
112
113 } else {
114 $mod->groupmode = false;
115 }
116 $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
117 } else {
118 $editbuttons = '';
119 }
dd97c328 120 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
0f3fe4b6 121 if ($ismoving) {
122 if ($mod->id == $USER->activitycopy) {
123 continue;
124 }
d4a1fcaf 125 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
dd97c328 126 '<img style="height:16px; width:80px; border:0px" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" /></a>';
0f3fe4b6 127 $this->content->icons[] = '';
128 }
dd97c328 129 $instancename = $modinfo->cms[$modnumber]->name;
958ab253 130 $instancename = format_string($instancename, true, $this->instance->pageid);
0f3fe4b6 131 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
dd97c328 132 if (!empty($modinfo->cms[$modnumber]->extra)) {
133 $extra = $modinfo->cms[$modnumber]->extra;
0f3fe4b6 134 } else {
135 $extra = '';
136 }
dd97c328 137 if (!empty($modinfo->cms[$modnumber]->icon)) {
138 $icon = $CFG->pixpath.'/'.$modinfo->cms[$modnumber]->icon;
facf75c1 139 } else {
140 $icon = $CFG->modpixpath.'/'.$mod->modname.'/icon.gif';
141 }
0f3fe4b6 142
143 if ($mod->modname == 'label') {
144 $this->content->items[] = format_text($extra, FORMAT_HTML).$editbuttons;
145 $this->content->icons[] = '';
146 } else {
147 $this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
148 ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$instancename.'</a>'.$editbuttons;
dd97c328 149 //Accessibility: incidental image - should be empty Alt text
150 $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
0f3fe4b6 151 }
152 }
153 }
154 }
155
156 if ($ismoving) {
d4a1fcaf 157 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
dd97c328 158 '<img style="height:16px; width:80px; border:0px" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" /></a>';
0f3fe4b6 159 $this->content->icons[] = '';
160 }
161
dd97c328 162 if ($modnames) {
4fad3618 163 $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
0f3fe4b6 164 } else {
165 $this->content->footer = '';
166 }
167
168 return $this->content;
169 }
170}
171
fea43a7f 172?>