MDL-12627 - when visiting the gradebook for the first time, we don't sort
[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(){
0f3fe4b6 5 $this->title = get_string('blockname','block_social_activities');
0f3fe4b6 6 $this->version = 2004041800;
7 }
8
9 function applicable_formats() {
8a47e075 10 return array('course-view-social' => true);
0f3fe4b6 11 }
12
13 function get_content() {
14 global $USER, $CFG;
15
2eb68e6f 16 if ($this->content !== NULL) {
0f3fe4b6 17 return $this->content;
18 }
19
9b4b78fd 20 $this->content = new stdClass;
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
29 $course = get_record('course', 'id', $this->instance->pageid);
01199ea9 30 $context = get_context_instance(CONTEXT_COURSE, $course->id);
9b4b78fd 31
0f3fe4b6 32 // To make our day, we start with an ugly hack
33 global $sections, $mods, $modnames;
34
35 $section = $sections[0];
36 // That wasn't so bad, was it?
37
9b4b78fd 38 $groupbuttons = $course->groupmode;
39 $groupbuttonslink = (!$course->groupmodeforce);
01199ea9 40 $viewhiddenactivities = has_capability('moodle/course:viewhiddenactivities', $context);
6fdfb347 41 $isediting = isediting($this->instance->pageid);
9b4b78fd 42 $ismoving = ismoving($this->instance->pageid);
0f3fe4b6 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;
48 }
fea43a7f 49 /// Casting $course->modinfo to string prevents one notice when the field is null
50 $modinfo = unserialize((string)$course->modinfo);
0f3fe4b6 51 $editbuttons = '';
52
53 if ($ismoving) {
0d905d9f 54 $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$CFG->pixpath.'/t/move.gif" class="iconsmall" alt="" />';
00b61a66 55 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.$USER->sesskey.'">'.$strcancel.'</a>)';
0f3fe4b6 56 }
57
58 if (!empty($section->sequence)) {
59 $sectionmods = explode(',', $section->sequence);
60 foreach ($sectionmods as $modnumber) {
61 if (empty($mods[$modnumber])) {
62 continue;
63 }
64 $mod = $mods[$modnumber];
6fdfb347 65 if ($isediting && !$ismoving) {
0f3fe4b6 66 if ($groupbuttons) {
67 if (! $mod->groupmodelink = $groupbuttonslink) {
9b4b78fd 68 $mod->groupmode = $course->groupmode;
0f3fe4b6 69 }
70
71 } else {
72 $mod->groupmode = false;
73 }
74 $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
75 } else {
76 $editbuttons = '';
77 }
01199ea9 78 if ($mod->visible || $viewhiddenactivities) {
0f3fe4b6 79 if ($ismoving) {
80 if ($mod->id == $USER->activitycopy) {
81 continue;
82 }
35a0379a 83 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.$USER->sesskey.'">'.
98ea2a6e 84 '<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0" /></a>';
0f3fe4b6 85 $this->content->icons[] = '';
86 }
87 $instancename = urldecode($modinfo[$modnumber]->name);
958ab253 88 $instancename = format_string($instancename, true, $this->instance->pageid);
0f3fe4b6 89 $linkcss = $mod->visible ? '' : ' class="dimmed" ';
90 if (!empty($modinfo[$modnumber]->extra)) {
91 $extra = urldecode($modinfo[$modnumber]->extra);
92 } else {
93 $extra = '';
94 }
facf75c1 95 if (!empty($modinfo[$modnumber]->icon)) {
96 $icon = $CFG->pixpath.'/'.urldecode($modinfo[$modnumber]->icon);
97 } else {
98 $icon = $CFG->modpixpath.'/'.$mod->modname.'/icon.gif';
99 }
0f3fe4b6 100
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;
0d905d9f 107 $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="'.$mod->modfullname.'" />';
0f3fe4b6 108 }
109 }
110 }
111 }
112
113 if ($ismoving) {
35a0379a 114 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.$USER->sesskey.'">'.
98ea2a6e 115 '<img height="16" width="80" src="'.$CFG->pixpath.'/movehere.gif" alt="'.$strmovehere.'" border="0" /></a>';
0f3fe4b6 116 $this->content->icons[] = '';
117 }
118
6fdfb347 119 if ($isediting && $modnames) {
4fad3618 120 $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
0f3fe4b6 121 } else {
122 $this->content->footer = '';
123 }
124
125 return $this->content;
126 }
127}
128
fea43a7f 129?>