MDL-10870 All files updated to new build_navigation() method. Most are untested,...
[moodle-pu.git] / blocks / social_activities / block_social_activities.php
blob2a67f4d868e545c8f8f96d46e4bdcb381b529360
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 = 2004041800;
9 function applicable_formats() {
10 return array('course-view-social' => true);
13 function get_content() {
14 global $USER, $CFG;
16 if ($this->content !== NULL) {
17 return $this->content;
20 $this->content = new stdClass;
21 $this->content->items = array();
22 $this->content->icons = array();
23 $this->content->footer = '';
25 if (empty($this->instance)) {
26 return $this->content;
29 $course = get_record('course', 'id', $this->instance->pageid);
30 $context = get_context_instance(CONTEXT_COURSE, $course->id);
32 // To make our day, we start with an ugly hack
33 global $sections, $mods, $modnames;
35 $section = $sections[0];
36 // That wasn't so bad, was it?
38 $groupbuttons = $course->groupmode;
39 $groupbuttonslink = (!$course->groupmodeforce);
40 $viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context);
41 $isediting = isediting($this->instance->pageid);
42 $ismoving = ismoving($this->instance->pageid);
43 if ($ismoving) {
44 $strmovehere = get_string('movehere');
45 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
46 $strcancel= get_string('cancel');
47 $stractivityclipboard = $USER->activitycopyname;
49 /// Casting $course->modinfo to string prevents one notice when the field is null
50 $modinfo = unserialize((string)$course->modinfo);
51 $editbuttons = '';
53 if ($ismoving) {
54 $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" alt="" />';
55 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
58 if (!empty($section->sequence)) {
59 $sectionmods = explode(',', $section->sequence);
60 foreach ($sectionmods as $modnumber) {
61 if (empty($mods[$modnumber])) {
62 continue;
64 $mod = $mods[$modnumber];
65 if ($isediting && !$ismoving) {
66 if ($groupbuttons) {
67 if (! $mod->groupmodelink = $groupbuttonslink) {
68 $mod->groupmode = $course->groupmode;
71 } else {
72 $mod->groupmode = false;
74 $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
75 } else {
76 $editbuttons = '';
78 if ($mod->visible || $viewhiddenactivities) {
79 if ($ismoving) {
80 if ($mod->id == $USER->activitycopy) {
81 continue;
83 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.$USER->sesskey.'">'.
84 '<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0" /></a>';
85 $this->content->icons[] = '';
87 $instancename = urldecode($modinfo[$modnumber]->name);
88 $instancename = format_string($instancename, true, $this->instance->pageid);
89 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
90 if (!empty($modinfo[$modnumber]->extra)) {
91 $extra = urldecode($modinfo[$modnumber]->extra);
92 } else {
93 $extra = '';
95 if (!empty($modinfo[$modnumber]->icon)) {
96 $icon = $CFG->pixpath.'/'.urldecode($modinfo[$modnumber]->icon);
97 } else {
98 $icon = $CFG->modpixpath.'/'.$mod->modname.'/icon.gif';
101 if ($mod->modname == 'label') {
102 $this->content->items[] = format_text($extra, FORMAT_HTML).$editbuttons;
103 $this->content->icons[] = '';
104 } else {
105 $this->content->items[] = '<a title="'.$mod->modfullname.'" '.$linkcss.' '.$extra.
106 ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'.$instancename.'</a>'.$editbuttons;
107 $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="'.$mod->modfullname.'" />';
113 if ($ismoving) {
114 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.$USER->sesskey.'">'.
115 '<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0" /></a>';
116 $this->content->icons[] = '';
119 if ($isediting && $modnames) {
120 $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
121 } else {
122 $this->content->footer = '';
125 return $this->content;