d7d48c03847939b73c0c21ae10b326f982ea23b5
[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     }
8     function applicable_formats() {
9         return array('course-view-social' => true);
10     }
12     function get_content() {
13         global $USER, $CFG, $DB, $OUTPUT;
15         if ($this->content !== NULL) {
16             return $this->content;
17         }
19         $this->content = new stdClass();
20         $this->content->items = array();
21         $this->content->icons = array();
22         $this->content->footer = '';
24         if (empty($this->instance)) {
25             return $this->content;
26         }
28         $course = $this->page->course;
30         require_once($CFG->dirroot.'/course/lib.php');
32         $context = context_course::instance($course->id);
33         $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
34         $modinfo = get_fast_modinfo($course);
36 /// extra fast view mode
37         if (!$isediting) {
38             if (!empty($modinfo->sections[0])) {
39                 $options = array('overflowdiv'=>true);
40                 foreach($modinfo->sections[0] as $cmid) {
41                     $cm = $modinfo->cms[$cmid];
42                     if (!$cm->uservisible) {
43                         continue;
44                     }
46                     $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
47                     $instancename = $cm->get_formatted_name();
49                     if (!($url = $cm->get_url())) {
50                         $this->content->items[] = $content;
51                         $this->content->icons[] = '';
52                     } else {
53                         $linkcss = $cm->visible ? '' : ' class="dimmed" ';
54                         //Accessibility: incidental image - should be empty Alt text
55                         $icon = '<img src="' . $cm->get_icon_url() . '" class="icon" alt="" />&nbsp;';
56                         $this->content->items[] = '<a title="'.$cm->modplural.'" '.$linkcss.' '.$cm->extra.
57                                 ' href="' . $url . '">' . $icon . $instancename . '</a>';
58                     }
59                 }
60             }
61             return $this->content;
62         }
65 /// slow & hacky editing mode
66         $ismoving = ismoving($course->id);
67         $modinfo = get_fast_modinfo($course);
68         $section = $modinfo->get_section_info(0);
70         $groupbuttons = $course->groupmode;
71         $groupbuttonslink = (!$course->groupmodeforce);
73         if ($ismoving) {
74             $strmovehere = get_string('movehere');
75             $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
76             $strcancel= get_string('cancel');
77             $stractivityclipboard = $USER->activitycopyname;
78         }
79     /// Casting $course->modinfo to string prevents one notice when the field is null
80         $editbuttons = '';
82         if ($ismoving) {
83             $this->content->icons[] = '&nbsp;<img align="bottom" src="'.$OUTPUT->pix_url('t/move') . '" class="iconsmall" alt="" />';
84             $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
85         }
87         if (!empty($modinfo->sections[0])) {
88             $options = array('overflowdiv'=>true);
89             foreach ($modinfo->sections[0] as $modnumber) {
90                 $mod = $modinfo->cms[$modnumber];
91                 if (!$mod->uservisible) {
92                     continue;
93                 }
94                 if (!$ismoving) {
95                     if ($groupbuttons) {
96                         if (! $mod->groupmodelink = $groupbuttonslink) {
97                             $mod->groupmode = $course->groupmode;
98                         }
100                     } else {
101                         $mod->groupmode = false;
102                     }
103                     $editbuttons = '<br />'.make_editing_buttons($mod, true, true);
104                 } else {
105                     $editbuttons = '';
106                 }
107                 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $context)) {
108                     if ($ismoving) {
109                         if ($mod->id == $USER->activitycopy) {
110                             continue;
111                         }
112                         $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
113                             '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
114                         $this->content->icons[] = '';
115                     }
116                     $content = $mod->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
117                     $instancename = $mod->get_formatted_name();
119                     $linkcss = $mod->visible ? '' : ' class="dimmed" ';
121                     if (!($url = $mod->get_url())) {
122                         $this->content->items[] = $content . $editbuttons;
123                         $this->content->icons[] = '';
124                     } else {
125                         //Accessibility: incidental image - should be empty Alt text
126                         $icon = '<img src="' . $mod->get_icon_url() . '" class="icon" alt="" />&nbsp;';
127                         $this->content->items[] = '<a title="' . $mod->modfullname . '" ' . $linkcss . ' ' . $mod->extra .
128                             ' href="' . $url . '">' . $icon . $instancename . '</a>' . $editbuttons;
129                     }
130                 }
131             }
132         }
134         if ($ismoving) {
135             $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
136                                       '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->pix_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
137             $this->content->icons[] = '';
138         }
140         $this->content->footer = print_section_add_menus($course, 0, null, true, true);
142         return $this->content;
143     }