@@ -80,9 +80,10 @@ public function go() {
80
80
$ enrollments = db::count_enrollments ($ this ->term , $ courses , $ mapped_courses );
81
81
$ course_enrollments = $ enrollments [0 ];
82
82
$ manual_flags = $ enrollments [1 ];
83
+ $ withdrawn = $ enrollments [2 ];
83
84
// -----------------------------------------------------------------
84
85
$ prev_course_enrollments = reports::read_temp_csv ();
85
- $ report = reports::compile_report ($ prev_course_enrollments , $ course_enrollments , $ manual_flags );
86
+ $ report = reports::compile_report ($ prev_course_enrollments , $ course_enrollments , $ manual_flags, $ withdrawn );
86
87
reports::send_report ($ this ->term , $ report );
87
88
return null ;
88
89
default :
@@ -204,6 +205,7 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
204
205
205
206
$ course_enrollments = [];
206
207
$ manual_flags = [];
208
+ $ withdrawn = [];
207
209
208
210
foreach ($ course_list as $ course ) {
209
211
$ grad_course = array_search ($ course , $ mapped_courses );
@@ -222,6 +224,13 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
222
224
if ($ res === false )
223
225
die ("Failed to lookup counts with manual flag set for {$ course }\n" );
224
226
$ manual_flags [$ course ] = (int ) pg_fetch_result ($ res , 0 );
227
+
228
+ // Get withdrawn enrollments count
229
+ $ sql = "SELECT COUNT(registration_type) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section IS NOT NULL AND registration_type='withdrawn' " ;
230
+ $ res = pg_query_params (self ::$ db , $ sql , $ params );
231
+ if ($ res === false )
232
+ die ("Failed to lookup counts with manual flag set for {$ course }\n" );
233
+ $ withdrawn [$ course ] = (int ) pg_fetch_result ($ res , 0 );
225
234
} else {
226
235
// UNDERGRADUATE SECTION
227
236
$ sql = "SELECT COUNT(*) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section='1' " ;
@@ -238,6 +247,13 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
238
247
die ("Failed to lookup counts with manual flag set for {$ course } (undergrads) \n" );
239
248
$ manual_flags [$ course ] = (int ) pg_fetch_result ($ res , 0 );
240
249
250
+ // Get withdrawn enrollments count
251
+ $ sql = "SELECT COUNT(registration_type) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section='1' AND registration_type='withdrawn' " ;
252
+ $ res = pg_query_params (self ::$ db , $ sql , $ params );
253
+ if ($ res === false )
254
+ die ("Failed to lookup counts with manual flag set for {$ course }\n" );
255
+ $ withdrawn [$ course ] = (int ) pg_fetch_result ($ res , 0 );
256
+
241
257
// GRADUATE SECTION
242
258
$ sql = "SELECT COUNT(*) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section='2' " ;
243
259
$ res = pg_query_params (self ::$ db , $ sql , $ params );
@@ -251,13 +267,21 @@ public static function count_enrollments($term, $course_list, $mapped_courses) {
251
267
if ($ res === false )
252
268
die ("Failed to lookup counts with manual flag set for {$ course } (grads) \n" );
253
269
$ manual_flags [$ grad_course ] = (int ) pg_fetch_result ($ res , 0 );
270
+
271
+ // Get withdrawn enrollments count
272
+ $ sql = "SELECT COUNT(registration_type) FROM courses_users WHERE term=$1 AND course=$2 AND user_group=4 AND registration_section='2' AND registration_type='withdrawn' " ;
273
+ $ res = pg_query_params (self ::$ db , $ sql , $ params );
274
+ if ($ res === false )
275
+ die ("Failed to lookup counts with manual flag set for {$ course }\n" );
276
+ $ withdrawn [$ grad_course ] = (int ) pg_fetch_result ($ res , 0 );
254
277
}
255
278
}
256
279
257
280
// Courses make up array keys. Sort by courses.
258
281
ksort ($ course_enrollments );
259
282
ksort ($ manual_flags );
260
- return [$ course_enrollments , $ manual_flags ];
283
+ ksort ($ withdrawn );
284
+ return [$ course_enrollments , $ manual_flags , $ withdrawn ];
261
285
}
262
286
}
263
287
@@ -320,20 +344,21 @@ public static function read_temp_csv() {
320
344
* @param $manual_flags
321
345
* @return string $report
322
346
*/
323
- public static function compile_report ($ prev_course_enrollments , $ course_enrollments , $ manual_flags ) {
347
+ public static function compile_report ($ prev_course_enrollments , $ course_enrollments , $ manual_flags, $ withdrawn ) {
324
348
// Compile stats
325
349
$ date = date ("F j, Y " );
326
350
$ time = date ("g:i A " );
327
351
$ report = <<<HEADING
328
352
Student autofeed counts report for {$ date } at {$ time }
329
353
NOTE: Difference and ratio do not account for the manual flag.
330
- COURSE YESTERDAY TODAY MANUAL DIFFERENCE RATIO \n
354
+ COURSE YESTERDAY TODAY MANUAL DIFFERENCE RATIO WITHDRAWN \n
331
355
HEADING ;
332
356
333
357
foreach ($ course_enrollments as $ course =>$ course_enrollment ) {
334
358
// Calculate data
335
- $ prev_course_enrollment = array_key_exists ($ course , $ prev_course_enrollments ) ? $ prev_course_enrollments [$ course ] : 0 ;
336
- $ manual_flag = array_key_exists ($ course , $ manual_flags ) ? $ manual_flags [$ course ] : 0 ;
359
+ $ prev_course_enrollment = $ prev_course_enrollments [$ course ] ?? 0 ;
360
+ $ manual_flag = $ manual_flags [$ course ] ?? 0 ;
361
+ $ withdrew = $ withdrawn [$ course ] ?? 0 ;
337
362
$ diff = $ course_enrollment - $ prev_course_enrollment ;
338
363
$ ratio = $ prev_course_enrollment != 0 ? abs (round (($ diff / $ prev_course_enrollment ), 3 )) : "N/A " ;
339
364
@@ -343,9 +368,10 @@ public static function compile_report($prev_course_enrollments, $course_enrollme
343
368
$ course_enrollment = str_pad ($ course_enrollment , 5 , " " , STR_PAD_LEFT );
344
369
$ manual_flag = str_pad ($ manual_flag , 6 , " " , STR_PAD_LEFT );
345
370
$ diff = str_pad ($ diff , 10 , " " , STR_PAD_LEFT );
371
+ $ ratio = str_pad ($ ratio , 5 , " " , STR_PAD_RIGHT );
346
372
347
373
// Add row to report.
348
- $ report .= "{$ course }{$ prev_course_enrollment } {$ course_enrollment } {$ manual_flag } {$ diff } {$ ratio }\n" ;
374
+ $ report .= "{$ course }{$ prev_course_enrollment } {$ course_enrollment } {$ manual_flag } {$ diff } {$ ratio } { $ withdrew } \n" ;
349
375
}
350
376
351
377
return $ report ;
0 commit comments