Merge branch 'MDL-65060-36' of git://github.com/aanabit/moodle into MOODLE_36_STABLE
[moodle.git] / blocks / social_activities / block_social_activities.php
blob2e5ec902fd97318f721e8bf10813183652209009
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Social activities block.
20 * @package block_social_activities
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 class block_social_activities extends block_list {
26 function init(){
27 $this->title = get_string('pluginname', 'block_social_activities');
30 function applicable_formats() {
31 return array('course-view-social' => true);
34 function get_content() {
35 global $USER, $CFG, $DB, $OUTPUT;
37 if ($this->content !== NULL) {
38 return $this->content;
41 $this->content = new stdClass();
42 $this->content->items = array();
43 $this->content->icons = array();
44 $this->content->footer = '';
46 if (empty($this->instance)) {
47 return $this->content;
50 $course = $this->page->course;
51 $courserenderer = $this->page->get_renderer('core', 'course');
53 require_once($CFG->dirroot.'/course/lib.php');
55 $context = context_course::instance($course->id);
56 $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
57 $modinfo = get_fast_modinfo($course);
59 /// extra fast view mode
60 if (!$isediting) {
61 if (!empty($modinfo->sections[0])) {
62 foreach($modinfo->sections[0] as $cmid) {
63 $cm = $modinfo->cms[$cmid];
64 if (!$cm->uservisible || !$cm->is_visible_on_course_page()) {
65 continue;
68 if (!$cm->url) {
69 $content = $courserenderer->course_section_cm_text($cm);
70 $this->content->items[] = $content;
71 $this->content->icons[] = '';
72 } else {
73 $this->content->items[] = html_writer::div($courserenderer->course_section_cm_name($cm), 'activity');
77 return $this->content;
81 // Slow & hacky editing mode.
82 $ismoving = ismoving($course->id);
83 $section = $modinfo->get_section_info(0);
85 if ($ismoving) {
86 $strmovehere = get_string('movehere');
87 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
88 $strcancel= get_string('cancel');
89 } else {
90 $strmove = get_string('move');
93 if ($ismoving) {
94 $this->content->icons[] = '&nbsp;' . $OUTPUT->pix_icon('t/move', get_string('move'));
95 $this->content->items[] = $USER->activitycopyname.'&nbsp;(<a href="'.$CFG->wwwroot.'/course/mod.php?cancelcopy=true&amp;sesskey='.sesskey().'">'.$strcancel.'</a>)';
98 if (!empty($modinfo->sections[0])) {
99 foreach ($modinfo->sections[0] as $modnumber) {
100 $mod = $modinfo->cms[$modnumber];
101 if (!$mod->uservisible || !$mod->is_visible_on_course_page()) {
102 continue;
104 if (!$ismoving) {
105 $actions = course_get_cm_edit_actions($mod, -1);
107 // Prepend list of actions with the 'move' action.
108 $actions = array('move' => new action_menu_link_primary(
109 new moodle_url('/course/mod.php', array('sesskey' => sesskey(), 'copy' => $mod->id)),
110 new pix_icon('t/move', $strmove, 'moodle', array('class' => 'iconsmall', 'title' => '')),
111 $strmove
112 )) + $actions;
114 $editbuttons = html_writer::tag('div',
115 $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)),
116 array('class' => 'buttons')
118 } else {
119 $editbuttons = '';
121 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) {
122 if ($ismoving) {
123 if ($mod->id == $USER->activitycopy) {
124 continue;
126 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&amp;sesskey='.sesskey().'">'.
127 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->image_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
128 $this->content->icons[] = '';
130 if (!$mod->url) {
131 $content = $courserenderer->course_section_cm_text($mod);
132 $this->content->items[] = $content . $editbuttons;
133 $this->content->icons[] = '';
134 } else {
135 $this->content->items[] = html_writer::div($courserenderer->course_section_cm_name($mod), 'activity') .
136 $editbuttons;
142 if ($ismoving) {
143 $this->content->items[] = '<a title="'.$strmovefull.'" href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&amp;sesskey='.sesskey().'">'.
144 '<img style="height:16px; width:80px; border:0px" src="'.$OUTPUT->image_url('movehere') . '" alt="'.$strmovehere.'" /></a>';
145 $this->content->icons[] = '';
148 $this->content->footer = $courserenderer->course_section_add_cm_control($course,
149 0, null, array('inblock' => true));
151 return $this->content;