MDL-65448 block_social_activities: Restyle moving.
[moodle.git] / blocks / social_activities / block_social_activities.php
CommitLineData
4ca6cfbf 1<?php
f25a6839
SH
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.
13//
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/>.
16
17/**
18 * Social activities block.
19 *
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
23 */
0f3fe4b6 24
3ef642d9 25class block_social_activities extends block_list {
9b4b78fd 26 function init(){
513d33d6 27 $this->title = get_string('pluginname', 'block_social_activities');
0f3fe4b6 28 }
29
30 function applicable_formats() {
8a47e075 31 return array('course-view-social' => true);
0f3fe4b6 32 }
33
34 function get_content() {
6b608f8f 35 global $USER, $CFG, $DB, $OUTPUT;
0f3fe4b6 36
2eb68e6f 37 if ($this->content !== NULL) {
0f3fe4b6 38 return $this->content;
39 }
40
dd4bee83 41 $this->content = new stdClass();
0f3fe4b6 42 $this->content->items = array();
43 $this->content->icons = array();
44 $this->content->footer = '';
45
9b4b78fd 46 if (empty($this->instance)) {
47 return $this->content;
48 }
49
3179b000 50 $course = $this->page->course;
f59f89b4 51 $courserenderer = $this->page->get_renderer('core', 'course');
dd97c328 52
53 require_once($CFG->dirroot.'/course/lib.php');
54
fe2fdd11 55 $context = context_course::instance($course->id);
cb640229 56 $isediting = $this->page->user_is_editing() && has_capability('moodle/course:manageactivities', $context);
dd97c328 57 $modinfo = get_fast_modinfo($course);
58
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];
8341055e 64 if (!$cm->uservisible || !$cm->is_visible_on_course_page()) {
dd97c328 65 continue;
66 }
0d8b6a69 67
f59f89b4 68 if (!$cm->url) {
8341055e 69 $content = $courserenderer->course_section_cm_text($cm);
0d8b6a69 70 $this->content->items[] = $content;
dd97c328 71 $this->content->icons[] = '';
72 } else {
f59f89b4 73 $this->content->items[] = html_writer::div($courserenderer->course_section_cm_name($cm), 'activity');
dd97c328 74 }
75 }
76 }
77 return $this->content;
78 }
79
80
ea5a01fb 81 // Slow & hacky editing mode.
3179b000 82 $ismoving = ismoving($course->id);
71a56e08 83 $section = $modinfo->get_section_info(0);
0f3fe4b6 84
0f3fe4b6 85 if ($ismoving) {
0f3fe4b6 86 $strmovefull = strip_tags(get_string('movefull', '', "'$USER->activitycopyname'"));
87 $strcancel= get_string('cancel');
0c74b33f
MG
88 } else {
89 $strmove = get_string('move');
0f3fe4b6 90 }
0f3fe4b6 91
92 if ($ismoving) {
663640f5 93 $this->content->icons[] = '&nbsp;' . $OUTPUT->pix_icon('t/move', get_string('move'));
19933320
LB
94 $cancelurl = new moodle_url('/course/mod.php', array('cancelcopy' => 'true', 'sesskey' => sesskey()));
95 $this->content->items[] = $USER->activitycopyname . '&nbsp;(<a href="' . $cancelurl . '">' . $strcancel . '</a>)';
0f3fe4b6 96 }
97
71a56e08 98 if (!empty($modinfo->sections[0])) {
71a56e08
MG
99 foreach ($modinfo->sections[0] as $modnumber) {
100 $mod = $modinfo->cms[$modnumber];
8341055e 101 if (!$mod->uservisible || !$mod->is_visible_on_course_page()) {
0f3fe4b6 102 continue;
103 }
dd97c328 104 if (!$ismoving) {
9a36be73 105 $actions = course_get_cm_edit_actions($mod, -1);
0c74b33f
MG
106
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;
113
fc630b2b
MG
114 $editbuttons = html_writer::tag('div',
115 $courserenderer->course_section_cm_edit_actions($actions, $mod, array('donotenhance' => true)),
116 array('class' => 'buttons')
117 );
0f3fe4b6 118 } else {
119 $editbuttons = '';
120 }
45ad1693 121 if ($mod->visible || has_capability('moodle/course:viewhiddenactivities', $mod->context)) {
0f3fe4b6 122 if ($ismoving) {
123 if ($mod->id == $USER->activitycopy) {
124 continue;
125 }
19933320
LB
126 $movingurl = new moodle_url('/course/mod.php', array('moveto' => $mod->id, 'sesskey' => sesskey()));
127 $this->content->items[] = html_writer::link($movingurl, '', array('title' => $strmovefull,
128 'class' => 'movehere'));
0f3fe4b6 129 $this->content->icons[] = '';
130 }
f59f89b4 131 if (!$mod->url) {
8341055e 132 $content = $courserenderer->course_section_cm_text($mod);
0d8b6a69 133 $this->content->items[] = $content . $editbuttons;
0f3fe4b6 134 $this->content->icons[] = '';
135 } else {
f59f89b4
MG
136 $this->content->items[] = html_writer::div($courserenderer->course_section_cm_name($mod), 'activity') .
137 $editbuttons;
0f3fe4b6 138 }
139 }
140 }
141 }
142
143 if ($ismoving) {
19933320
LB
144 $movingurl = new moodle_url('/course/mod.php', array('movetosection' => $section->id, 'sesskey' => sesskey()));
145 $this->content->items[] = html_writer::link($movingurl, '', array('title' => $strmovefull, 'class' => 'movehere'));
0f3fe4b6 146 $this->content->icons[] = '';
147 }
148
9a6aa5c1
MG
149 $this->content->footer = $courserenderer->course_section_add_cm_control($course,
150 0, null, array('inblock' => true));
0f3fe4b6 151
152 return $this->content;
153 }
154}