| 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 |
* Display user activity reports for a course (totals)
|
|
|
19 |
*
|
|
|
20 |
* @package report
|
|
|
21 |
* @subpackage outline
|
|
|
22 |
* @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
| 1441 |
ariadna |
26 |
use report_outline\output\hierarchicalactivities;
|
|
|
27 |
|
| 1 |
efrain |
28 |
require('../../config.php');
|
|
|
29 |
require_once($CFG->dirroot.'/report/outline/locallib.php');
|
|
|
30 |
require_once($CFG->dirroot.'/report/outline/lib.php');
|
|
|
31 |
|
|
|
32 |
$userid = required_param('id', PARAM_INT);
|
|
|
33 |
$courseid = required_param('course', PARAM_INT);
|
|
|
34 |
$mode = optional_param('mode', 'outline', PARAM_ALPHA);
|
|
|
35 |
|
|
|
36 |
if ($mode !== 'complete' and $mode !== 'outline') {
|
|
|
37 |
$mode = 'outline';
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
$user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST);
|
|
|
41 |
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
|
|
|
42 |
|
|
|
43 |
$coursecontext = context_course::instance($course->id);
|
|
|
44 |
$personalcontext = context_user::instance($user->id);
|
|
|
45 |
|
|
|
46 |
if ($courseid == SITEID) {
|
|
|
47 |
$PAGE->set_context($personalcontext);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)
|
|
|
51 |
and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) {
|
|
|
52 |
//TODO: do not require parents to be enrolled in courses - this is a hack!
|
|
|
53 |
require_login();
|
|
|
54 |
$PAGE->set_course($course);
|
|
|
55 |
} else {
|
|
|
56 |
require_login($course);
|
|
|
57 |
}
|
|
|
58 |
$PAGE->set_url('/report/outline/user.php', array('id'=>$userid, 'course'=>$courseid, 'mode'=>$mode));
|
|
|
59 |
|
|
|
60 |
if (!report_outline_can_access_user_report($user, $course)) {
|
|
|
61 |
throw new \moodle_exception('nocapability', 'report_outline');
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
$stractivityreport = get_string('activityreport');
|
|
|
65 |
|
|
|
66 |
$PAGE->set_pagelayout('report');
|
|
|
67 |
$PAGE->set_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$mode));
|
|
|
68 |
$PAGE->navigation->extend_for_user($user);
|
|
|
69 |
$PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
|
|
|
70 |
$PAGE->set_title("$course->shortname: $stractivityreport");
|
|
|
71 |
|
|
|
72 |
// Create the appropriate breadcrumb.
|
|
|
73 |
$navigationnode = array(
|
|
|
74 |
'url' => new moodle_url('/report/outline/user.php', array('id' => $user->id, 'course' => $course->id, 'mode' => $mode))
|
|
|
75 |
);
|
|
|
76 |
if ($mode === 'complete') {
|
|
|
77 |
$navigationnode['name'] = get_string('completereport');
|
|
|
78 |
} else {
|
|
|
79 |
$navigationnode['name'] = get_string('outlinereport');
|
|
|
80 |
}
|
|
|
81 |
$PAGE->add_report_nodes($user->id, $navigationnode);
|
|
|
82 |
|
|
|
83 |
if ($courseid == SITEID) {
|
|
|
84 |
$PAGE->set_heading(fullname($user));
|
|
|
85 |
} else {
|
|
|
86 |
$PAGE->set_heading($course->fullname);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
// Trigger a report viewed event.
|
|
|
90 |
$event = \report_outline\event\report_viewed::create(array('context' => context_course::instance($course->id),
|
|
|
91 |
'relateduserid' => $userid, 'other' => array('mode' => $mode)));
|
|
|
92 |
$event->trigger();
|
|
|
93 |
|
|
|
94 |
echo $OUTPUT->header();
|
|
|
95 |
if ($courseid != SITEID) {
|
|
|
96 |
$backurl = new moodle_url('/user/view.php', ['id' => $userid, 'course' => $courseid]);
|
|
|
97 |
echo $OUTPUT->single_button($backurl, get_string('back'), 'get', ['class' => 'mb-3']);
|
|
|
98 |
echo $OUTPUT->context_header(
|
|
|
99 |
array(
|
|
|
100 |
'heading' => fullname($user),
|
|
|
101 |
'user' => $user,
|
|
|
102 |
'usercontext' => $personalcontext
|
|
|
103 |
), 2);
|
|
|
104 |
if ($mode === 'outline') {
|
|
|
105 |
echo $OUTPUT->heading(get_string('outlinereport', 'moodle'), 2, 'main mt-4 mb-4');
|
|
|
106 |
} else {
|
|
|
107 |
echo $OUTPUT->heading(get_string('completereport', 'moodle'), 2, 'main mt-4 mb-4');
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
$modinfo = get_fast_modinfo($course, $user->id);
|
|
|
112 |
$itemsprinted = false;
|
|
|
113 |
|
| 1441 |
ariadna |
114 |
$coursestructure = new hierarchicalactivities($modinfo);
|
|
|
115 |
$sections = $coursestructure->export_hierarchy($OUTPUT);
|
|
|
116 |
|
| 1 |
efrain |
117 |
foreach ($sections as $i => $section) {
|
| 1441 |
ariadna |
118 |
if (!$section['visible']) {
|
|
|
119 |
continue;
|
|
|
120 |
}
|
|
|
121 |
$section = (object) $section;
|
|
|
122 |
$itemsprinted = true;
|
|
|
123 |
echo '<div class="section p-3 my-4">';
|
|
|
124 |
echo '<h2 class="h4">';
|
|
|
125 |
echo $section->text;
|
|
|
126 |
echo "</h2>";
|
| 1 |
efrain |
127 |
|
| 1441 |
ariadna |
128 |
echo '<div class="content">';
|
| 1 |
efrain |
129 |
|
| 1441 |
ariadna |
130 |
if ($mode == "outline") {
|
|
|
131 |
echo "<table>";
|
|
|
132 |
}
|
| 1 |
efrain |
133 |
|
| 1441 |
ariadna |
134 |
foreach ($section->activities as $cm) {
|
|
|
135 |
if (!$cm['visible']) {
|
|
|
136 |
continue;
|
|
|
137 |
}
|
|
|
138 |
$cm = (object) $cm;
|
|
|
139 |
if ($cm->isdelegated) {
|
|
|
140 |
// Print subsection box.
|
|
|
141 |
if ($mode == "outline") {
|
|
|
142 |
echo "</table>";
|
|
|
143 |
}
|
|
|
144 |
echo '<div class="section subsection p-3 my-2">';
|
|
|
145 |
echo '<h3 class="font-lg">';
|
|
|
146 |
echo $cm->text;
|
|
|
147 |
echo "</h3>";
|
| 1 |
efrain |
148 |
|
| 1441 |
ariadna |
149 |
echo '<div class="content">';
|
| 1 |
efrain |
150 |
|
| 1441 |
ariadna |
151 |
if ($mode == "outline") {
|
|
|
152 |
echo "<table>";
|
|
|
153 |
}
|
| 1 |
efrain |
154 |
|
| 1441 |
ariadna |
155 |
foreach ($cm->activities as $subcm) {
|
|
|
156 |
if (!$subcm['visible']) {
|
|
|
157 |
continue;
|
|
|
158 |
}
|
|
|
159 |
$subcm = (object) $subcm;
|
|
|
160 |
$mod = $modinfo->cms[$subcm->id];
|
|
|
161 |
$coursestructure->print_activity($OUTPUT, $mode, $mod, $user, $course);
|
|
|
162 |
}
|
|
|
163 |
if ($mode == "outline") {
|
|
|
164 |
echo "</table>";
|
|
|
165 |
}
|
|
|
166 |
echo "</div>"; // Content.
|
|
|
167 |
echo "</div>"; // Subsection.
|
|
|
168 |
if ($mode == "outline") {
|
|
|
169 |
echo "<table>";
|
|
|
170 |
}
|
| 1 |
efrain |
171 |
|
| 1441 |
ariadna |
172 |
continue;
|
|
|
173 |
}
|
| 1 |
efrain |
174 |
|
| 1441 |
ariadna |
175 |
$mod = $modinfo->cms[$cm->id];
|
|
|
176 |
$coursestructure->print_activity($OUTPUT, $mode, $mod, $user, $course);
|
|
|
177 |
}
|
| 1 |
efrain |
178 |
|
| 1441 |
ariadna |
179 |
if ($mode == "outline") {
|
|
|
180 |
echo "</table>";
|
|
|
181 |
}
|
|
|
182 |
echo '</div>'; // Content.
|
|
|
183 |
echo '</div>'; // Section.
|
| 1 |
efrain |
184 |
}
|
|
|
185 |
|
|
|
186 |
if (!$itemsprinted) {
|
|
|
187 |
echo $OUTPUT->notification(get_string('nothingtodisplay'), 'info', false);
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
echo $OUTPUT->footer();
|