1 |
efrain |
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.
|
|
|
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 |
* Renderer for block recent_activity
|
|
|
19 |
*
|
|
|
20 |
* @package block_recent_activity
|
|
|
21 |
* @copyright 2012 Marina Glancy
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die;
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* recent_activity block rendrer
|
|
|
29 |
*
|
|
|
30 |
* @package block_recent_activity
|
|
|
31 |
* @copyright 2012 Marina Glancy
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
class block_recent_activity_renderer extends plugin_renderer_base {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Renders HTML to display recent_activity block
|
|
|
38 |
*
|
|
|
39 |
* @param stdClass $course
|
|
|
40 |
* @param int $timestart
|
|
|
41 |
* @param array $recentenrolments array of changes in enrolments
|
|
|
42 |
* @param array $structuralchanges array of changes in course structure
|
|
|
43 |
* @param array $modulesrecentactivity array of changes in modules (provided by modules)
|
|
|
44 |
* @return string
|
|
|
45 |
*/
|
|
|
46 |
public function recent_activity($course, $timestart, $recentenrolments, $structuralchanges,
|
|
|
47 |
$modulesrecentactivity) {
|
|
|
48 |
|
|
|
49 |
$output = html_writer::tag('div',
|
|
|
50 |
get_string('activitysince', '', userdate($timestart)),
|
|
|
51 |
array('class' => 'activityhead'));
|
|
|
52 |
|
|
|
53 |
$output .= html_writer::tag('div',
|
|
|
54 |
html_writer::link(new moodle_url('/course/recent.php', array('id' => $course->id)),
|
|
|
55 |
get_string('recentactivityreport')),
|
|
|
56 |
array('class' => 'activityhead mb-3'));
|
|
|
57 |
|
|
|
58 |
$content = false;
|
|
|
59 |
|
|
|
60 |
// Firstly, have there been any new enrolments?
|
|
|
61 |
if ($recentenrolments) {
|
|
|
62 |
$content = true;
|
|
|
63 |
$context = context_course::instance($course->id);
|
|
|
64 |
$viewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
|
|
65 |
$output .= html_writer::start_tag('div', array('class' => 'newusers'));
|
|
|
66 |
$output .= $this->heading(get_string("newusers").':', 3);
|
|
|
67 |
//Accessibility: new users now appear in an <OL> list.
|
|
|
68 |
$output .= html_writer::start_tag('ol', array('class' => 'list'));
|
|
|
69 |
foreach ($recentenrolments as $user) {
|
|
|
70 |
$output .= html_writer::tag('li',
|
|
|
71 |
html_writer::link(new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)),
|
|
|
72 |
fullname($user, $viewfullnames)),
|
|
|
73 |
array('class' => 'name'));
|
|
|
74 |
}
|
|
|
75 |
$output .= html_writer::end_tag('ol');
|
|
|
76 |
$output .= html_writer::end_tag('div');
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
// Next, have there been any modifications to the course structure?
|
|
|
80 |
if (!empty($structuralchanges)) {
|
|
|
81 |
$content = true;
|
|
|
82 |
$output .= $this->heading(get_string("courseupdates") . ':', 6);
|
|
|
83 |
foreach ($structuralchanges as $changeinfo => $change) {
|
|
|
84 |
$output .= $this->structural_change($change);
|
|
|
85 |
}
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
// Now display new things from each module
|
|
|
89 |
foreach ($modulesrecentactivity as $modname => $moduleactivity) {
|
|
|
90 |
$content = true;
|
|
|
91 |
$output .= $moduleactivity;
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
if (! $content) {
|
|
|
95 |
$output .= html_writer::tag('p', get_string('nothingnew'), array('class' => 'message'));
|
|
|
96 |
}
|
|
|
97 |
return $output;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Renders HTML for one change in course structure
|
|
|
102 |
*
|
|
|
103 |
* @see block_recent_activity::get_structural_changes()
|
|
|
104 |
* @param array $change array containing attributes
|
|
|
105 |
* 'action' - one of: 'add mod', 'update mod', 'delete mod'
|
|
|
106 |
* 'module' - instance of cm_info (for 'delete mod' it is an object with attributes modname and modfullname)
|
|
|
107 |
* @return string
|
|
|
108 |
*/
|
|
|
109 |
protected function structural_change($change) {
|
|
|
110 |
$cm = $change['module'];
|
|
|
111 |
switch ($change['action']) {
|
|
|
112 |
case 'delete mod':
|
|
|
113 |
$text = get_string('deletedactivity', 'moodle', $cm->modfullname);
|
|
|
114 |
break;
|
|
|
115 |
case 'add mod':
|
|
|
116 |
$text = get_string('added', 'moodle', $cm->modfullname). '<br />'.
|
|
|
117 |
html_writer::link($cm->url, format_string($cm->name, true));
|
|
|
118 |
break;
|
|
|
119 |
case 'update mod':
|
|
|
120 |
$text = get_string('updated', 'moodle', $cm->modfullname). '<br />'.
|
|
|
121 |
html_writer::link($cm->url, format_string($cm->name, true));
|
|
|
122 |
break;
|
|
|
123 |
default:
|
|
|
124 |
return '';
|
|
|
125 |
}
|
|
|
126 |
return html_writer::tag('p', $text, array('class' => 'activity'));
|
|
|
127 |
}
|
|
|
128 |
}
|