-
Notifications
You must be signed in to change notification settings - Fork 3
/
userprogramreport.php
159 lines (132 loc) · 5.91 KB
/
userprogramreport.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?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, but aggegating all courses in a courseset.
*
* @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, 'userprogram');
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);
}
$iscourseset = !is_null($rt->get_courseset($course->id));
$rt->process_bounds($data, $course);
// Need renew the form if process bounds have changed something.
$selform = new SelectorForm($id, 'userprogram');
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 courseset infos in trainingsessions condig.
$courseset = $rt->get_courseset($course->id);
if (is_null($courseset)) {
echo $OUTPUT->notification("Not a course set.");
return;
}
$sessions = [];
$str = '';
foreach ($courseset as $course) {
// 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, '', false, $course);
$weekaggregate = use_stats_aggregate_logs($logs, $data->to - WEEKSECS, $data->to, '', false, $course);
// Get course structure.
$coursestructure = $rt->get_course_structure($course->id, $items); // provides item count.
$cols = $rt->get_summary_cols('keys');
$courseheaddata = $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);
if (!isset($headdata)) {
$headdata = (object) $courseheaddata;
$headdata->gradecols = $gradedata;
$headdata->done = 0;
$headdata->items = 0;
} else {
$rt->aggregate_objects($headdata, (object) $courseheaddata);
}
$courseurl = new moodle_url('/course/view.php', ['id' => $course->id]);
$str .= '<H2>'.format_string($course->fullname).' - ID: '.$course->id;
$str .= ' <a target="_blank" href="'.$courseurl.'">'.get_string('gotocourse', 'report_trainingsessions');
$str .= '</a></H2>';
$str .= $renderer->print_html($coursestructure, $aggregate);
$headdata->done = $done;
$headdata->items = $items;
if (!empty($tsconfig->showsessions)) {
$sessions[$course->id] = $aggregate['sessions'];
}
}
echo $renderer->print_header_html($user, $course, $headdata, $cols);
echo $str;
if (!empty($tsconfig->showsessions)) {
foreach ($courseset as $course) {
echo $renderer->print_session_list($sessions[$course->id], $course, $data->userid);
}
}
echo $rtrenderer->xls_userexport_button($data, 'courseset');
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, 'courseset');
}
echo '<br/>';