-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathuserlog.php
executable file
·103 lines (89 loc) · 3.69 KB
/
userlog.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Assign report - file dump
*
* @copyright 2021 Howard Miller ([email protected])
* @package report
* @subpackage assign
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(dirname(__FILE__).'/../../config.php');
// Parameters.
$userid = required_param('userid', PARAM_INT);
$assignid = required_param('assignid', PARAM_INT);
$courseid = required_param('courseid', PARAM_INT);
$cmid = required_param('cmid', PARAM_INT);
$fullname = required_param('fullname', PARAM_NOTAGS);
$url = new moodle_url('/report/assign/userlog.php', ['userid' => $userid, 'courseid' => $courseid, 'assignid' => $assignid, 'cmid' => $cmid]);
// Page setup.
$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
require_login($course);
$PAGE->set_url($url);
$PAGE->set_pagelayout('report');
$PAGE->set_title($course->shortname .': '. get_string('pluginname', 'report_assign'));
$PAGE->set_heading($course->fullname);
// Security.
$output = $PAGE->get_renderer('report_assign');
$context = context_course::instance($course->id);
require_capability('mod/assign:grade', $context);
require_capability('report/assign:view', $context);
$assignment = $DB->get_record('assign', ['id' => $assignid], '*', MUST_EXIST);
// log events that we want to show
// event_name_in_log_table => string name in mod_assign
$eventfilter = [
'\mod_assign\event\assessable_submitted' => 'eventassessablesubmitted',
'\mod_assign\event\remove_submission_form_viewed' => 'eventremovesubmissionformviewed',
'\mod_assign\event\statement_accepted' => 'eventstatementaccepted',
'\mod_assign\event\submission_form_viewed' => 'eventsubmissionformviewed',
'\mod_assign\event\submission_viewed' => 'eventsubmissionviewed',
];
$events = array_keys($eventfilter);
$dateformat = get_string('strftimedatetimeshort', 'langconfig');
// Don't check eventname in SQL as it's not indexed :(
$sql = 'SELECT * FROM {logstore_standard_log}
WHERE userid = :userid
AND contextinstanceid = :cmid
ORDER BY timecreated DESC';
$params['userid'] = $userid;
$params['cmid'] = $cmid;
$logs = $DB->get_records_sql($sql, $params);
$logs = array_filter($logs, function($v, $k) use ($events) {
return in_array($v->eventname, $events);
}, ARRAY_FILTER_USE_BOTH);
foreach ($logs as $log) {
$log->selfaction = $log->userid == $userid;
$log->byuser = '-';
if (!$log->selfaction) {
$user = $DB->get_record('user', ['id' => $log->userid], '*', MUST_EXIST);
$log->byuser = fullname($user);
}
$log->logtime = userdate($log->timecreated, $dateformat);
$log->description = get_string($eventfilter[$log->eventname], 'mod_assign');
}
$backlink = new moodle_url('/report/assign/index.php',[
'id' => $courseid,
'assign' => $assignid,
]);
$templatecontext = (object)[
'fullname' => $fullname,
'anylogs' => !count($logs) == 0,
'logs' => array_values($logs),
'back' => $backlink,
];
echo $output->header();
echo $output->render_from_template('report_assign/userlog', $templatecontext);
echo $output->footer();