-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard-intake.php
More file actions
377 lines (352 loc) · 11.2 KB
/
dashboard-intake.php
File metadata and controls
377 lines (352 loc) · 11.2 KB
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?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/>.
/**
* Intake run history dashboard showing sync run statistics and chart.
*
* @package local_psaelmsync
* @copyright 2025 BC Public Service
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// This file mixes HTML and PHP; disable the per-block docblock check.
// phpcs:disable moodle.Commenting.MissingDocblock
require_once('../../config.php');
require_login();
global $DB;
$context = context_system::instance();
require_capability('local/psaelmsync:viewlogs', $context);
$PAGE->set_url('/local/psaelmsync/dashboard-intake.php');
$PAGE->set_context($context);
$PAGE->set_title(
get_string('pluginname', 'local_psaelmsync') . ' - '
. get_string('intakerunhistory', 'local_psaelmsync')
);
$PAGE->set_heading(get_string('intakerunhistory', 'local_psaelmsync'));
echo $OUTPUT->header();
?>
<!-- Tabbed Navigation -->
<nav aria-label="PSA ELM Sync sections">
<ul class="nav nav-tabs mb-3">
<li class="nav-item">
<a class="nav-link"
href="/admin/settings.php?section=local_psaelmsync">
Settings</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="/local/psaelmsync/dashboard.php">
Learner Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="/local/psaelmsync/dashboard-courses.php">
Course Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link active"
href="/local/psaelmsync/dashboard-intake.php"
aria-current="page">Intake Run Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="/local/psaelmsync/manual-intake.php">
Manual Intake</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="/local/psaelmsync/manual-complete.php">
Manual Complete</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="/local/psaelmsync/api-test.php">
API Test</a>
</li>
</ul>
</nav>
<?php
// Setup pagination variables.
$perpage = optional_param('perpage', 100, PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$offset = $page * $perpage;
// Get the total count of records.
$totalcount = $DB->count_records_select('local_psaelmsync_runs', '');
// Get the most recent records with pagination.
$sql = "SELECT * FROM {local_psaelmsync_runs} ORDER BY endtime DESC";
$lastruns = $DB->get_records_sql($sql, null, $offset, $perpage);
// Prepare data for Chart.js.
$chartdata = [
'labels' => [],
'enrolments' => [],
'suspends' => [],
'errors' => [],
];
foreach ($lastruns as $run) {
$start = (int) ($run->starttime / 1000);
$chartdata['labels'][] = date('Y-m-d H:i:s', $start);
$chartdata['enrolments'][] = $run->enrolcount;
$chartdata['suspends'][] = $run->suspendcount;
$chartdata['errors'][] = $run->errorcount;
}
?>
<!-- Include Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
var ctx = document.getElementById('runsChart').getContext('2d');
var chartData = <?php echo json_encode($chartdata, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT); ?>;
new Chart(ctx, {
type: 'line',
data: {
labels: chartData.labels,
datasets: [
{
label: 'Enrolments',
data: chartData.enrolments,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
fill: true
},
{
label: 'Suspends',
data: chartData.suspends,
borderColor: 'rgba(255, 159, 64, 1)',
backgroundColor: 'rgba(255, 159, 64, 0.2)',
fill: true
},
{
label: 'Errors',
data: chartData.errors,
borderColor: 'rgba(255, 99, 132, 1)',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
fill: true
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: true,
text: 'Recent Runs Overview'
},
scales: {
xAxes: [{
type: 'time',
time: {
unit: 'minute'
},
scaleLabel: {
display: true,
labelString: 'Time'
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Count'
},
ticks: {
beginAtZero: true
}
}]
}
}
});
});
</script>
<?php
$sql = "SELECT
SUM(enrolcount) AS total_enrols,
SUM(suspendcount) AS total_suspends,
SUM(errorcount) AS total_errors
FROM {local_psaelmsync_runs}";
$totals = $DB->get_record_sql($sql);
?>
<style>
.stat-card {
background: #f8f9fa;
border-radius: 0.5rem;
padding: 1.25rem;
text-align: center;
border-left: 4px solid;
}
.stat-card.enrols {
border-left-color: rgba(75, 192, 192, 1);
}
.stat-card.suspends {
border-left-color: rgba(255, 159, 64, 1);
}
.stat-card.errors {
border-left-color: rgba(255, 99, 132, 1);
}
.stat-card .stat-value {
font-size: 2rem;
font-weight: bold;
line-height: 1.2;
}
.stat-card .stat-label {
font-size: 0.85rem;
color: #6c757d;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.stat-card.enrols .stat-value {
color: rgba(75, 192, 192, 1);
}
.stat-card.suspends .stat-value {
color: rgba(255, 159, 64, 1);
}
.stat-card.errors .stat-value {
color: rgba(255, 99, 132, 1);
}
.sync-info-details {
margin-top: 1rem;
margin-bottom: 1rem;
}
.sync-info-details summary {
cursor: pointer;
padding: 0.5rem;
background: #f8f9fa;
border-radius: 0.25rem;
font-weight: 500;
}
.sync-info-details[open] summary {
margin-bottom: 0.5rem;
}
.sync-info-details .info-content {
padding: 0.75rem;
background: #fff;
border: 1px solid #dee2e6;
border-radius: 0.25rem;
font-size: 0.9rem;
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
</style>
<!-- Stats Cards -->
<div class="row mb-3">
<div class="col-md-4">
<div class="stat-card enrols">
<div class="stat-value">
<?php echo number_format($totals->total_enrols ?? 0); ?>
</div>
<div class="stat-label">Total Enrolments</div>
</div>
</div>
<div class="col-md-4">
<div class="stat-card suspends">
<div class="stat-value">
<?php echo number_format($totals->total_suspends ?? 0); ?>
</div>
<div class="stat-label">Total Suspends</div>
</div>
</div>
<div class="col-md-4">
<div class="stat-card errors">
<div class="stat-value">
<?php echo number_format($totals->total_errors ?? 0); ?>
</div>
<div class="stat-label">Total Errors</div>
</div>
</div>
</div>
<p class="text-muted text-center"
style="margin-top: -0.5rem; font-size: 0.85rem;">
Since Sept. 4, 2024</p>
<!-- Sync Info -->
<details class="sync-info-details">
<summary>Sync Info</summary>
<div class="info-content">
<p class="mb-2">The cron job for intake (from CData)
happens every 5 minutes, starting on the 2nd minute
of the hour, (ELM posts to CData every 5 minutes
on the 0) between the hours of 06:00 and 18:00;<br>
<pre>2,7,12,17,22,27,32,37,42,47,52,57</pre>
</p>
</div>
</details>
<div class="row mb-2">
<div class="col-md-12">
<figure role="figure" aria-labelledby="chart-description">
<div style="height: 320px;">
<canvas id="runsChart" aria-hidden="true"></canvas>
</div>
<figcaption id="chart-description" class="sr-only">
Line chart showing enrollment, suspension, and
error counts over time for recent sync runs.
The same data is available in the table below.
</figcaption>
</figure>
<!-- Results Table -->
<table class="table table-striped table-bordered mt-4">
<caption class="sr-only">
Intake run history showing date, enrolments,
drops, errors, and skipped counts for each
sync run
</caption>
<thead>
<tr>
<th scope="col">Date and Time</th>
<th scope="col">Enrolments</th>
<th scope="col">Drops</th>
<th scope="col">Errors</th>
<th scope="col">Skipped</th>
</tr>
</thead>
<tbody>
<?php foreach ($lastruns as $run) : ?>
<?php
$starttime = (int) ($run->starttime / 1000);
$endtime = (int) ($run->endtime / 1000);
$searchdate = urlencode(
date('Y-m-d H:i:s', $starttime)
);
$startlabel = date('Y-m-d H:i:s', $starttime);
$endlabel = date('H:i:s', $endtime);
?>
<tr>
<td>
<a href="/local/psaelmsync/dashboard.php?search=<?php
echo $searchdate; ?>">
<?php echo $startlabel; ?> -
<?php echo $endlabel; ?>
</a>
</td>
<td><?php echo $run->enrolcount; ?></td>
<td><?php echo $run->suspendcount; ?></td>
<td><?php echo $run->errorcount; ?></td>
<td><?php echo $run->skippedcount; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<!-- Pagination controls -->
<?php
echo $OUTPUT->paging_bar($totalcount, $page, $perpage, $PAGE->url);
?>
</div>
</div>
<?php
echo $OUTPUT->footer();