-
Notifications
You must be signed in to change notification settings - Fork 39
/
teacher_performed_units_report.php
executable file
·260 lines (218 loc) · 9.15 KB
/
teacher_performed_units_report.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?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/>.
/**
* Report to track individual performed units of a specific teacher.
*
* @package mod_booking
* @copyright 2022 Wunderbyte GmbH <[email protected]>
* @author Bernhard Fischer
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use mod_booking\form\teacher_performed_units_report_form;
use mod_booking\table\teacher_performed_units_table;
require_once(__DIR__ . '/../../config.php');
$teacherid = required_param('teacherid', PARAM_INT);
$download = optional_param('download', '', PARAM_ALPHA);
$filterstartdate = 0;
$filterenddate = 0;
// No guest autologin.
require_login(0, false);
$urlparams = [
'teacherid' => $teacherid,
];
$context = context_system::instance();
$PAGE->set_context($context);
$baseurl = new moodle_url('/mod/booking/teacher_performed_units_report.php', $urlparams);
$PAGE->set_url($baseurl);
if ((has_capability('mod/booking:updatebooking', $context) || has_capability('mod/booking:addeditownoption', $context)) == false) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('accessdenied', 'mod_booking'), 4);
echo get_string('nopermissiontoaccesspage', 'mod_booking');
echo $OUTPUT->footer();
die();
}
if (!$teacherobj = $DB->get_record('user', ['id' => $teacherid])) {
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('error'), 4);
echo get_string('error:missingteacherid', 'mod_booking');
echo $OUTPUT->footer();
die();
}
// File name and sheet name.
$fileandsheetname = "performance_report_" . $teacherobj->firstname . "_" . $teacherobj->lastname;
$teacherperformedunitstable = new teacher_performed_units_table('teacher_performed_units_table');
$teacherperformedunitstable->is_downloading($download, $fileandsheetname, $fileandsheetname);
$tablebaseurl = $baseurl;
$tablebaseurl->remove_params('page');
$teacherperformedunitstable->define_baseurl($tablebaseurl);
$teacherperformedunitstable->sortable(false);
$teacherperformedunitstable->collapsible(false);
$teacherperformedunitstable->show_download_buttons_at([TABLE_P_TOP]);
// Get unit length from config (should be something like 45, 50 or 60 minutes).
if (!$unitlength = get_config('booking', 'educationalunitinminutes')) {
$unitlength = '60';
}
// Initialize the Moodle form for filtering the table.
$mform = new teacher_performed_units_report_form();
$mform->set_data(['teacherid' => $teacherid]);
// Form processing and displaying is done here.
if ($fromform = $mform->get_data()) {
if (!empty($fromform->filterstartdate) && !empty($fromform->filterenddate)) {
$filterstartdate = $fromform->filterstartdate;
// Add 23:59:59 (in seconds) to the end time.
$filterenddate = $fromform->filterenddate + 86399;
// Little hack, so we don't use the dates with downloading.
set_user_preference('unitsreport_filterstartdate', $filterstartdate);
set_user_preference('unitsreport_filterenddate', $filterenddate);
} else {
debugging('error:missingfilters');
}
}
if (!$teacherperformedunitstable->is_downloading()) {
// Table will be shown normally.
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('teachingreportfortrainer', 'mod_booking') . ': '
. $teacherobj->firstname . " " . $teacherobj->lastname);
echo '<div class="alert alert-secondary alert-dismissible fade show" role="alert">' .
get_string('teachingreportfortrainer:subtitle', 'mod_booking') .
'<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
// Now show the mform for filtering.
$mform->display();
// Headers.
$teacherperformedunitstable->define_headers([
get_string('titleprefix', 'mod_booking'),
get_string('course'),
get_string('time'),
get_string('duration:minutes', 'mod_booking'),
get_string('duration:units', 'mod_booking', $unitlength),
]);
// Columns.
$teacherperformedunitstable->define_columns([
'titleprefix',
'optionname',
'optiondate',
'duration_min',
'duration_units',
]);
// Header column.
$teacherperformedunitstable->define_header_column('optionname');
// SQL query. The subselect will fix the "Did you remember to make the first column something...
// ...unique in your call to get_records?" bug.
$fields = "s.id, s.prefix, s.optionname, s.coursestarttime, s.courseendtime,
s.duration_min, s.duration_units";
$from = "(
SELECT bodt.id,
bo.titleprefix prefix,
bo.text optionname,
bod.coursestarttime, bod.courseendtime,
ROUND((cast((bod.courseendtime - bod.coursestarttime) as decimal))/60) as duration_min,
ROUND(((cast((bod.courseendtime - bod.coursestarttime) as decimal))/60) /
cast(:unitlength as decimal), 2) as duration_units
FROM
{booking_optiondates_teachers} bodt
JOIN {booking_optiondates} bod
ON bod.id = bodt.optiondateid
JOIN {booking_options} bo
on bo.id = bod.optionid
WHERE
bodt.userid = :teacherid
AND bod.coursestarttime >= :filterstartdate
AND bod.courseendtime <= :filterenddate
ORDER BY bod.coursestarttime ASC
) s";
$where = "1=1";
// Set the SQL filtering params now.
$params = [
'unitlength' => $unitlength,
'teacherid' => $teacherid,
'filterstartdate' => $filterstartdate,
'filterenddate' => $filterenddate,
];
// Now build the table.
$teacherperformedunitstable->set_sql($fields, $from, $where, $params);
$teacherperformedunitstable->out(TABLE_SHOW_ALL_PAGE_SIZE, false);
echo $OUTPUT->footer();
} else {
// The table is being downloaded.
// Headers.
$teacherperformedunitstable->define_headers([
get_string('firstname'),
get_string('lastname'),
get_string('email'),
get_string('bookinginstance', 'mod_booking'),
get_string('titleprefix', 'mod_booking'),
get_string('course'),
get_string('optiondatestart', 'mod_booking'),
get_string('optiondateend', 'mod_booking'),
get_string('duration:minutes', 'mod_booking'),
get_string('duration:units', 'mod_booking', $unitlength),
]);
// Columns.
$teacherperformedunitstable->define_columns([
'firstname',
'lastname',
'email',
'instancename',
'titleprefix',
'optionname',
'coursestarttime',
'courseendtime',
'duration_min',
'duration_units',
]);
// Header column.
$teacherperformedunitstable->define_header_column('optionname');
// SQL query. The subselect will fix the "Did you remember to make the first column something...
// ...unique in your call to get_records?" bug.
$fields = "bodt.id,
u.firstname, u.lastname, u.email,
b.name instancename,
bo.text optionname,
bod.coursestarttime, bod.courseendtime,
ROUND((cast((bod.courseendtime - bod.coursestarttime) as decimal))/60) as duration_min,
ROUND(((cast((bod.courseendtime - bod.coursestarttime) as decimal))/60) /
cast(:unitlength as decimal), 2) as duration_units";
$from = "{booking_optiondates_teachers} bodt
JOIN {booking_optiondates} bod
ON bod.id = bodt.optiondateid
JOIN {booking_options} bo
on bo.id = bod.optionid
JOIN {user} u
on u.id = bodt.userid
JOIN {booking} b
ON b.id = bo.bookingid";
$where = "bodt.userid = :teacherid
AND bod.coursestarttime >= :filterstartdate
AND bod.courseendtime <= :filterenddate
ORDER BY bod.coursestarttime ASC";
// Set the SQL filtering params now.
$params = [
'unitlength' => (int) $unitlength,
'teacherid' => $teacherid,
'filterstartdate' => (int) get_user_preferences('unitsreport_filterstartdate'),
'filterenddate' => (int) get_user_preferences('unitsreport_filterenddate'),
];
// Now build the table.
$teacherperformedunitstable->set_sql($fields, $from, $where, $params);
$teacherperformedunitstable->setup();
$teacherperformedunitstable->pagesize(50, 500);
$teacherperformedunitstable->query_db(500);
$teacherperformedunitstable->build_table();
$teacherperformedunitstable->finish_output();
}