-
Notifications
You must be signed in to change notification settings - Fork 3
/
userreport.php
130 lines (107 loc) · 4.84 KB
/
userreport.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?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/>.
/**
* Course trainingsessions report for a single user
*
* @package report_trainingsessions
* @category report
* @author Valery Fremaux ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
ob_start();
require_once($CFG->dirroot.'/blocks/use_stats/locallib.php');
require_once($CFG->dirroot.'/report/trainingsessions/locallib.php');
require_once($CFG->dirroot.'/report/trainingsessions/renderers/htmlrenderers.php');
$tsconfig = get_config('report_trainingsessions');
$rt = \report\trainingsessions\trainingsessions::instance();
$renderer = new \report\trainingsessions\HtmlRenderer($rt);
raise_memory_limit(MEMORY_EXTRA);
// Selector form.
require_once($CFG->dirroot.'/report/trainingsessions/selector_form.php');
$selform = new SelectorForm($id, 'user');
if (!$data = $selform->get_data()) {
$data = new StdClass;
$data->from = optional_param('from', $course->startdate, PARAM_NUMBER);
$data->to = optional_param('to', time(), PARAM_NUMBER);
if (has_capability('report/trainingsessions:viewother', $context, $USER->id)) {
$firstcompiledusers = get_users_by_capability($context, 'report/trainingsessions:iscompiled', 'u.*', 'u.lastname, u.firstname', 0, 1);
if (!empty($firstcompiledusers)) {
$user = array_shift($firstcompiledusers);
$data->userid = $user->id;
} else {
// No users in the course. Use "me".
$data->userid = $USER->id;
}
} else {
$data->userid = $USER->id;
}
$data->fromstart = optional_param('fromstart', $tsconfig->defaultstartdate, PARAM_TEXT);
$data->tonow = optional_param('tonow', 0, PARAM_BOOL);
}
$rt->process_bounds($data, $course);
// Need renew the form if process bounds have changed something.
$selform = new SelectorForm($id, 'user');
$iscourseset = !is_null($rt->get_courseset($course->id));
echo $OUTPUT->header();
echo $OUTPUT->container_start();
echo $rtrenderer->tabs($course, $view, $data->from, $data->to, $iscourseset);
echo $OUTPUT->container_end();
echo $OUTPUT->box_start('block');
$selform->set_data($data);
$selform->display();
echo $OUTPUT->box_end();
echo get_string('from', 'report_trainingsessions')." : ".userdate($data->from);
echo ' '.get_string('to', 'report_trainingsessions')." : ".userdate($data->to);
$usconfig = get_config('block_use_stats');
if ($usconfig->enrolmentfilter && has_capability('report/trainingsessions:viewother', $context)) {
echo $OUTPUT->notification(get_string('warningusestateenrolfilter', 'block_use_stats'));
}
if (empty($aggregate['sessions'])) {
$aggregate['sessions'] = array();
}
if (!isset($user)) {
$user = $DB->get_record('user', array('id' => $data->userid));
}
// Get data.
use_stats_fix_last_course_access($data->userid, $course->id);
$logs = use_stats_extract_logs($data->from, $data->to, $data->userid, $course->id);
$aggregate = use_stats_aggregate_logs($logs, $data->from, $data->to);
$weekaggregate = use_stats_aggregate_logs($logs, $data->to - WEEKSECS, $data->to);
// Get course structure.
$coursestructure = $rt->get_course_structure($course->id, $structureitems);
$cols = $rt->get_summary_cols('keys');
$headdata = $rt->map_summary_cols($cols, $user, $aggregate, $weekaggregate, $course->id, true);
$rt->add_graded_columns($cols, $unusedtitles);
$rt->add_graded_data($gradedata, $data->userid, $aggregate);
$rt->calculate_course_structure($coursestructure, $aggregate, $done, $items);
$headdata = (object) $headdata;
$headdata->gradecols = $gradedata;
$str = $renderer->print_html($coursestructure, $aggregate);
$headdata->done = $done;
$headdata->items = $items;
echo $renderer->print_header_html($user, $course, $headdata, $cols);
echo $str;
if (!empty($tsconfig->showsessions)) {
echo $renderer->print_session_list($aggregate['sessions'], $course, $data->userid);
}
echo $rtrenderer->xls_userexport_button($data);
if (report_trainingsessions_supports_feature('format/pdf')) {
include_once($CFG->dirroot.'/report/trainingsessions/pro/renderer.php');
$rendererext = new \report_trainingsessions\output\pro_renderer($PAGE, '');
echo $rendererext->pdf_userexport_buttons($data);
}
echo '<br/>';