-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard-courses.php
More file actions
203 lines (190 loc) · 6.89 KB
/
dashboard-courses.php
File metadata and controls
203 lines (190 loc) · 6.89 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
<?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 dashboard page displaying per-course enrollment statistics.
*
* @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, $OUTPUT, $PAGE;
$context = context_system::instance();
require_capability('local/psaelmsync:viewlogs', $context);
$PAGE->set_url('/local/psaelmsync/dashboard-courses.php');
$PAGE->set_context($context);
$PAGE->set_title(
get_string('pluginname', 'local_psaelmsync') . ' - '
. get_string('courseenrolstats', 'local_psaelmsync')
);
$PAGE->set_heading(get_string('courseenrolstats', 'local_psaelmsync'));
echo $OUTPUT->header();
// Select all courses with IDNumber and their completion_opt_in field.
$courses = $DB->get_records_sql("
SELECT c.id, c.fullname, c.idnumber,
COALESCE(cfd.intvalue, 0) AS completion_opt_in
FROM {course} c
LEFT JOIN {customfield_data} cfd ON cfd.instanceid = c.id
LEFT JOIN {customfield_field} cff ON cff.id = cfd.fieldid
WHERE c.idnumber IS NOT NULL
AND c.idnumber <> ''
AND cff.shortname = 'completion_opt_in'
ORDER BY c.fullname ASC
");
?>
<!-- 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 active"
href="/local/psaelmsync/dashboard-courses.php"
aria-current="page">Course Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link"
href="/local/psaelmsync/dashboard-intake.php">
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>
<p>This dashboard is a work in progress. It is only meant to
give a count of the log records that have come through CData
and does not reflect the actual number of enrolments in a
given course.</p>
<!-- Results Table -->
<table class="table table-striped table-bordered">
<caption class="sr-only">
Course enrollment statistics from CData sync logs
</caption>
<thead>
<tr>
<th scope="col">
<?php echo get_string('course', 'local_psaelmsync'); ?>
</th>
<th scope="col">
<?php echo get_string('idnumber', 'local_psaelmsync'); ?>
</th>
<th scope="col">
<?php echo get_string('completion_opt_in', 'local_psaelmsync'); ?>
</th>
<th scope="col">
<?php echo get_string('completions', 'local_psaelmsync'); ?>
</th>
<th scope="col">
<?php echo get_string('enrolments', 'local_psaelmsync'); ?>
</th>
<th scope="col">
<?php echo get_string('suspends', 'local_psaelmsync'); ?>
</th>
<th scope="col">
<?php echo get_string('errors', 'local_psaelmsync'); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($courses as $course) : ?>
<?php
// Count enrol, suspend, and error log entries for each course.
$enrolments = $DB->count_records(
'local_psaelmsync_logs',
['course_id' => $course->id, 'action' => 'Enrol']
);
$suspends = $DB->count_records(
'local_psaelmsync_logs',
['course_id' => $course->id, 'action' => 'Suspend']
);
$errors = $DB->count_records(
'local_psaelmsync_logs',
['course_id' => $course->id, 'status' => 'Error']
);
$completions = $DB->count_records(
'local_psaelmsync_logs',
['course_id' => $course->id, 'action' => 'Complete']
);
$optinlabel = ($course->completion_opt_in == 1)
? 'Opted In' : 'Not Opted In';
?>
<tr>
<td>
<a href="/course/view.php?id=<?php echo $course->id; ?>"
target="_blank">
<?php echo format_string($course->fullname); ?>
<span class="sr-only">
(opens in new window)
</span>
</a>
<small>(<a
href="/user/index.php?id=<?php echo $course->id; ?>"
target="_blank"
aria-label="Participants for <?php
echo format_string($course->fullname);
?> (opens in new window)">
Participants
</a>)</small>
</td>
<td><?php echo format_string($course->idnumber); ?></td>
<td><?php echo $optinlabel; ?></td>
<td><?php echo $completions; ?></td>
<td><?php echo $enrolments; ?></td>
<td><?php echo $suspends; ?></td>
<td><?php echo $errors; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<style>
.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>
<?php
echo $OUTPUT->footer();