This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewstatistics.php
273 lines (252 loc) · 9.77 KB
/
viewstatistics.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
261
262
263
264
265
266
267
268
269
270
271
272
273
<?php
/**
* @package mod-scheduler
* @category mod
* @author Valery Fremaux > 1.8
*/
/**
* Security traps
*/
if (!defined('MOODLE_INTERNAL')){
error("This file cannot be loaded directly");
}
// a function utility for sorting stat results
function byName($a, $b){
return strcasecmp($a[0],$b[0]);
}
// precompute groups in case partial popuation is considered by grouping
if ($cm->groupmembersonly){
$groups = groups_get_all_groups($COURSE->id, 0, $cm->groupingid);
$usergroups = array_keys($groups);
} else {
$groups = get_groups($COURSE->id);
$usergroups = '';
}
//display statistics tabs
$tabs = array('overall', 'studentbreakdown', 'staffbreakdown','lengthbreakdown','groupbreakdown');
$tabrows = array();
$row = array();
$currenttab = '';
foreach ($tabs as $tab) {
$a = ($tab == 'staffbreakdown') ? format_string($scheduler->staffrolename) : '';
$tabname = get_string($tab, 'scheduler', strtolower($a));
$row[] = new tabobject($tabname, "view.php?what=viewstatistics&id=$cm->id&course=$scheduler->course&page=".$tab, $tabname);
}
$tabrows[] = $row;
print_tabs($tabrows, get_string($page, 'scheduler'));
//display correct type of statistics by request
$attendees = get_users_by_capability($context, 'mod/scheduler:appoint', '*', 'u.lastname', '', '', $usergroups);
switch ($page) {
case 'overall':
$sql = "
SELECT
COUNT(DISTINCT(a.studentid))
FROM
{$CFG->prefix}scheduler_slots s,
{$CFG->prefix}scheduler_appointment a
WHERE
s.id = a.slotid AND
s.schedulerid = {$scheduler->id} AND
a.attended = 1
";
$attended = count_records_sql($sql);
$sql = "
SELECT
COUNT(DISTINCT(a.studentid))
FROM
{$CFG->prefix}scheduler_slots s,
{$CFG->prefix}scheduler_appointment a
WHERE
s.id = a.slotid AND
s.schedulerid = {$scheduler->id} AND
a.attended = 0
";
$registered = count_records_sql($sql);
$sql = "
SELECT
COUNT(DISTINCT(s.id))
FROM
{$CFG->prefix}scheduler_slots s
LEFT JOIN
{$CFG->prefix}scheduler_appointment a
ON
s.id = a.slotid
WHERE
s.schedulerid = {$scheduler->id} AND
s.teacherid = {$USER->id} AND
a.attended IS NULL
";
$freeowned = count_records_sql($sql);
$sql = "
SELECT
COUNT(DISTINCT(s.id))
FROM
{$CFG->prefix}scheduler_slots s
LEFT JOIN
{$CFG->prefix}scheduler_appointment a
ON
s.id = a.slotid
WHERE
s.schedulerid = {$scheduler->id} AND
s.teacherid != {$USER->id} AND
a.attended IS NULL
";
$freenotowned = count_records_sql($sql);
$allattendees = ($attendees) ? count($attendees) : 0 ;
$str = '<h3>'.get_string('attendable', 'scheduler').'</h3>';
$str .= '<b>'.get_string('attendablelbl', 'scheduler').'</b>: ' . $allattendees . '<br/>';
$str .= '<h3>'.get_string('attended', 'scheduler').'</h3>';
$str .= '<b>'.get_string('attendedlbl', 'scheduler').'</b>: ' . $attended . '<br/><br/>';
$str .= '<h3>'.get_string('unattended', 'scheduler').'</h3>';
$str .= '<b>'.get_string('registeredlbl', 'scheduler').'</b>: ' . $registered . '<br/>';
$str .= '<b>'.get_string('unregisteredlbl', 'scheduler').'</b>: ' . ($allattendees - $registered) . '<br/>';
$str .= '<h3>'.get_string('availableslots', 'scheduler').'</h3>';
$str .= '<b>'.get_string('availableslotsowned', 'scheduler').'</b>: ' . $freeowned . '<br/>';
$str .= '<b>'.get_string('availableslotsnotowned', 'scheduler').'</b>: ' . $freenotowned . '<br/>';
$str .= '<b>'.get_string('availableslotsall', 'scheduler').'</b>: ' . ($freeowned + $freenotowned) . '<br/>';
print_simple_box($str);
break;
case 'studentbreakdown':
//display the ammount of time each student has received
if (!empty($attendees)) {
$table->head = array (get_string('student', 'scheduler'), get_string('duration', 'scheduler'));
$table->align = array ('LEFT', 'CENTER');
$table->width = '70%';
$table->data = array();
$sql = "
SELECT
a.studentid,
SUM(s.duration) as totaltime
FROM
{$CFG->prefix}scheduler_slots s,
{$CFG->prefix}scheduler_appointment a
WHERE
s.id = a.slotid AND
a.studentid > 0 AND
s.schedulerid = '{$scheduler->id}'
GROUP BY
a.studentid
";
if ($statrecords = get_records_sql($sql)) {
foreach($statrecords as $aRecord){
$aStudent = get_record('user', 'id', $aRecord->studentid);
$table->data[] = array (fullname($aStudent), $aRecord->totaltime);
}
uasort($table->data, 'byName');
}
print_table($table);
}
else{
print_simple_box(get_string('nostudents', 'scheduler'), 'center', '70%');
}
break;
case 'staffbreakdown':
//display break down by member of staff
$sql = "
SELECT
s.teacherid,
SUM(s.duration) as totaltime
FROM
{$CFG->prefix}scheduler_slots s
LEFT JOIN
{$CFG->prefix}scheduler_appointment a
ON
a.slotid = s.id
WHERE
s.schedulerid = '{$scheduler->id}' AND
s.teacherid = '{$scheduler->teacher}' AND
a.studentid IS NOT NULL
GROUP BY
s.teacherid
";
if ($statrecords = get_records_sql($sql)) {
$table->width = '70%';
$table->head = array (format_string($scheduler->staffrolename), get_string('cumulatedduration', 'scheduler'));
$table->align = array ('LEFT', 'CENTER');
foreach($statrecords as $aRecord){
$aTeacher = get_record('user', 'id', $aRecord->teacherid);
$table->data[] = array (fullname($aTeacher), $aRecord->totaltime);
}
uasort($table->data, 'byName');
print_table($table);
}
break;
case 'lengthbreakdown':
//display break down my duration
$sql = "
SELECT
s.*
FROM
{$CFG->prefix}scheduler_slots s
LEFT JOIN
{$CFG->prefix}scheduler_appointment a
ON
a.slotid = s.id
WHERE
a.studentid IS NOT NULL AND
schedulerid = '{$scheduler->id}'
";
if ($slots = get_records_sql($sql)) {
$table->head = array (get_string('duration', 'scheduler'), get_string('appointments', 'scheduler'));
$table->align = array ('LEFT', 'CENTER');
$table->width = '70%';
$durationcount = array();
foreach($slots as $slot) {
if (array_key_exists($slot->duration, $durationcount)) {
$durationcount[$slot->duration] ++;
} else {
$durationcount[$slot->duration] = 1;
}
}
foreach ($durationcount as $key => $duration) {
$table->data[] = array ($key, $duration);
}
print_table($table);
}
break;
case 'groupbreakdown':
//display by number of atendees to one member of staff
$sql = "
SELECT
s.starttime,
COUNT(*) as groupsize,
MAX(s.duration) as duration
FROM
{$CFG->prefix}scheduler_slots s
LEFT JOIN
{$CFG->prefix}scheduler_appointment a
ON
a.slotid = s.id
WHERE
a.studentid IS NOT NULL AND
schedulerid = '{$scheduler->id}'
GROUP BY
s.starttime
ORDER BY
groupsize DESC
";
if ($groupslots = get_records_sql($sql)){
$table->head = array (get_string('groupsize', 'scheduler'), get_string('occurrences', 'scheduler'), get_string('cumulatedduration', 'scheduler'));
$table->align = array ('LEFT', 'CENTER', 'CENTER');
$table->width = '70%';
$grouprows = array();
foreach($groupslots as $aGroup){
if (!array_key_exists($aGroup->groupsize, $grouprows)){
$grouprows[$aGroup->groupsize]->occurrences = 0;
$grouprows[$aGroup->groupsize]->duration = 0;
}
$grouprows[$aGroup->groupsize]->occurrences++;
$grouprows[$aGroup->groupsize]->duration += $aGroup->duration;
}
foreach(array_keys($grouprows) as $aGroupSize){
$table->data[] = array ($aGroupSize,$grouprows[$aGroupSize]->occurrences, $grouprows[$aGroupSize]->duration);
}
print_table($table);
}
}
echo '<br/>';
print_continue("$CFG->wwwroot/mod/scheduler/view.php?id=".$cm->id);
/// Finish the page
print_footer($course);
exit;
?>