Merge commit 'catalyst/MOODLE_19_STABLE' into mdl19-linuxchix
[moodle-linuxchix.git] / blocks / social_activities / block_social_activities.php
blobf425a22a4a7c23dce8515c383aa5d01caf365951
1 <?php //$Id$
3 class block_social_activities extends block_list {
4 function init(){
5 $this->title = get_string('blockname', 'block_social_activities');
6 $this->version = 2007101509;
9 function applicable_formats() {
10 return array('course-view-social' => true);
13 function get_content() {
14 global $USER, $CFG, $COURSE;
16 if ($this->content !== NULL) {
17 return $this->content;
20 $this->content = new object();
21 $this->content->items = array();
22 $this->content->icons = array();
23 $this->content->footer = '';
25 if (empty($this->instance)) {
26 return $this->content;
29 if ($COURSE->id == $this->instance->pageid) {
30 $course = $COURSE;
31 } else {
32 $course = get_record('course', 'id', $this->instance->pageid);
35 require_once($CFG->dirroot.'/course/lib.php');
37 $context = get_context_instance(CONTEXT_COURSE, $course->id);
38 $isediting = isediting($this->instance->pageid) && has_capability('moodle/course:manageactivities', $context);
39 $modinfo = get_fast_modinfo($course);
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;
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';
63 $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
67 return $this->content;
71 /// slow & hacky editing mode
72 $ismoving = ismoving($this->instance->pageid);
73 $sections = get_all_sections($this->instance->pageid);
75 if(!empty($sections) && isset($sections[0])) {
76 $section = $sections[0];
79 if (!empty($section)) {
80 get_all_mods($this->instance->pageid, $mods, $modnames, $modnamesplural, $modnamesused);
83 $groupbuttons = $course->groupmode;
84 $groupbuttonslink = (!$course->groupmodeforce);
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;
92 /// Casting $course->modinfo to string prevents one notice when the field is null
93 $editbuttons = '';
95 if ($ismoving) {
96 $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" alt="" />';
97 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
100 if (!empty($section) && !empty($section->sequence)) {
101 $sectionmods = explode(',', $section->sequence);
102 foreach ($sectionmods as $modnumber) {
103 if (empty($mods[$modnumber])) {
104 continue;
106 $mod = $mods[$modnumber];
107 if (!$ismoving) {
108 if ($groupbuttons) {
109 if (! $mod->groupmodelink = $groupbuttonslink) {
110 $mod->groupmode = $course->groupmode;
113 } else {
114 $mod->groupmode = false;
116 $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
117 } else {
118 $editbuttons = '';
120 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
121 if ($ismoving) {
122 if ($mod->id == $USER->activitycopy) {
123 continue;
125 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.$USER->sesskey.'">'.
126 '<img style="height:16px; width:80px; border:0px" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" /></a>';
127 $this->content->icons[] = '';
129 $instancename = $modinfo->cms[$modnumber]->name;
130 $instancename = format_string($instancename, true, $this->instance->pageid);
131 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
132 if (!empty($modinfo->cms[$modnumber]->extra)) {
133 $extra = $modinfo->cms[$modnumber]->extra;
134 } else {
135 $extra = '';
137 if (!empty($modinfo->cms[$modnumber]->icon)) {
138 $icon = $CFG->pixpath.'/'.$modinfo->cms[$modnumber]->icon;
139 } else {
140 $icon = $CFG->modpixpath.'/'.$mod->modname.'/icon.gif';
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;
149 //Accessibility: incidental image - should be empty Alt text
150 $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
156 if ($ismoving) {
157 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.$USER->sesskey.'">'.
158 '<img style="height:16px; width:80px; border:0px" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" /></a>';
159 $this->content->icons[] = '';
162 if ($modnames) {
163 $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
164 } else {
165 $this->content->footer = '';
168 return $this->content;