MDL-22054 converting block name strings to pluginname
[moodle.git] / blocks / social_activities / block_social_activities.php
1 <?php
3 class block_social_activities extends block_list {
4     function init(){
5         $this->title = get_string('pluginname', 'block_social_activities');
6         $this->version = 2007101509;
7     }
9     function applicable_formats() {
10         return array('course-view-social' => true);
11     }
13     function get_content() {
14         global $USER, $CFG, $DB, $OUTPUT;
16         if ($this->content !== NULL) {
17             return $this->content;
18         }
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;
27         }
29         $course = $this->page->course;
31         require_once($CFG->dirroot.'/course/lib.php');
33         $context = get_context_instance(CONTEXT_COURSE, $course->id);
34         $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
35         $modinfo = get_fast_modinfo($course);
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)) {
55                             $icon = $OUTPUT->pix_url($cm->icon);
56                         } else {
57                             $icon = $OUTPUT->pix_url('icon', $cm->modname);
58                         }
59                         $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
60                     }
61                 }
62             }
63             return $this->content;
64         }
67 /// slow & hacky editing mode
68         $ismoving = ismoving($course->id);
69         $sections = get_all_sections($course->id);
71         if(!empty($sections) && isset($sections[0])) {
72             $section = $sections[0];
73         }
75         if (!empty($section)) {
76             get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
77         }
79         $groupbuttons = $course->groupmode;
80         $groupbuttonslink = (!$course->groupmodeforce);
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         }
88     /// Casting $course->modinfo to string prevents one notice when the field is null
89         $editbuttons = '';
91         if ($ismoving) {
92             $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
93             $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
94         }
96         if (!empty($section) && !empty($section->sequence)) {
97             $sectionmods = explode(',', $section->sequence);
98             foreach ($sectionmods as $modnumber) {
99                 if (empty($mods[$modnumber])) {
100                     continue;
101                 }
102                 $mod = $mods[$modnumber];
103                 if (!$ismoving) {
104                     if ($groupbuttons) {
105                         if (! $mod->groupmodelink = $groupbuttonslink) {
106                             $mod->groupmode = $course->groupmode;
107                         }
109                     } else {
110                         $mod->groupmode = false;
111                     }
112                     $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
113                 } else {
114                     $editbuttons = '';
115                 }
116                 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
117                     if ($ismoving) {
118                         if ($mod->id == $USER->activitycopy) {
119                             continue;
120                         }
121                         $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
122                             '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
123                         $this->content->icons[] = '';
124                     }
125                     $instancename = $modinfo->cms[$modnumber]->name;
126                     $instancename = format_string($instancename, true, $course->id);
127                     $linkcss = $mod->visible ? '' : ' class="dimmed" ';
128                     if (!empty($modinfo->cms[$modnumber]->extra)) {
129                         $extra = $modinfo->cms[$modnumber]->extra;
130                     } else {
131                         $extra = '';
132                     }
133                     if (!empty($modinfo->cms[$modnumber]->icon)) {
134                         $icon = $OUTPUT->pix_url($modinfo->cms[$modnumber]->icon);
135                     } else {
136                         $icon = $OUTPUT->pix_url('icon', $mod->modname);
137                     }
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;
145                         //Accessibility: incidental image - should be empty Alt text
146                         $this->content->icons[] = '<img src="'.$icon.'" class="icon" alt="" />';
147                     }
148                 }
149             }
150         }
152         if ($ismoving) {
153             $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
154                                       '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
155             $this->content->icons[] = '';
156         }
158         if ($modnames) {
159             $this->content->footer = print_section_add_menus($course, 0, $modnames, true, true);
160         } else {
161             $this->content->footer = '';
162         }
164         return $this->content;
165     }