Skip to content

Commit 8459787

Browse files
committed
RCOS course mapping
Code refactoring, fixes, and comment/documentation improvements.
1 parent 9556ae0 commit 8459787

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

student_auto_feed/config.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,15 @@
133133
* permit a student to declare their credit load. The data feed will need
134134
* a column showing a student's credit load. See above: COLUMN_CREDITS
135135
*
136-
* DO NOT MAP RCOS COURSES IN THE SUBMITTY DATABASE
136+
* RCOS courses need to be mapped to a "primary" course in the database,
137+
* but the autofeed will override the registration section as
138+
* "{course_code}-{credit_load}". e.g. "csci4700-4".
137139
*/
138140

139-
// List all RCOS courses, as an array. If you are not tracking RCOS, then set as null or an empty array.
141+
// 1. List all RCOS courses, as an array. If you are not tracking RCOS, then set as null or an empty array.
142+
// 2. One (any which one) of these courses needs to be designated as "primary" and the others need to be mapped to the
143+
// primary within the database. Registration sections need to be defined in the database, but are otherwise irrelevant
144+
// as the auto feed will override registration sections.
140145
define('RCOS_COURSE_LIST', null);
141146

142147
/* DATA SOURCING --------------------------------------------------------------

student_auto_feed/ssaf_rcos.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,28 @@
44
/**
55
* Static utilty class to support RCOS (Rensselaer Center for Open Source)
66
*
7+
* This will override enrollment registration sections for RCOS courses. Some RCOS students may declare how many
8+
* credits they are registered for, but are otherwise all placed in the same course and registration section.
9+
* (currently) Submitty does not keep records for regsitered credits per student, but this record is needed for
10+
* RCOS. Therefore, this helper class will override a RCOS student's enrollment record to `{course}-{credits}`
11+
* e.g. `csci4700-4`. This must done while processing the CSV because every override requires the student's
12+
* registered credits from the CSV.
13+
*
714
* @author Peter Bailie
815
*/
916
class rcos {
1017
private array $course_list;
1118

1219
public function __construct() {
1320
$this->course_list = RCOS_COURSE_LIST ?? [];
21+
sort($this->course_list, SORT_STRING);
1422
array_walk($this->course_list, function(&$v, $i) { $v = strtolower($v); });
1523
}
1624

1725
/** Adjusts `$row[COLUMN_SECTION]` when `$course` is an RCOS course. */
1826
public function map(string $course, array &$row): void {
19-
if ($this->check($course)) {
20-
$row[COLUMN_SECTION] = "{$row[COLUMN_COURSE_NUMBER]}-{$row[COLUMN_CREDITS]}";
27+
if (in_array($course, $this->course_list, true)) {
28+
$row[COLUMN_SECTION] = "{$course}-{$row[COLUMN_CREDITS]}";
2129
}
2230
}
23-
24-
/** Returns `true` if `$course` is an RCOS course and `false` otherwise. */
25-
public function check(string $course): bool {
26-
return array_search($course, self::$course_list) !== false;
27-
}
2831
}

student_auto_feed/submitty_student_auto_feed.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/** primary process class */
3030
class submitty_student_auto_feed {
3131
/** File handle to read CSV */
32-
private resource $fh;
32+
private $fh;
3333
/** Semester code */
3434
private string $semester;
3535
/** List of courses registered in Submitty */
@@ -83,9 +83,6 @@ public function __construct() {
8383
exit(1);
8484
}
8585

86-
// Helper object for special-cases involving RCOS.
87-
$this->rcos = new rcos();
88-
8986
// Get course list
9087
$error = null;
9188
$this->course_list = db::get_course_list($this->semester, $error);
@@ -103,12 +100,12 @@ public function __construct() {
103100
exit(1);
104101
}
105102

106-
// RCOS courses should not be mapped in the database.
107-
108-
109103
// Get CRN shared courses/sections (when a course/section is copied to another course/section)
110104
$this->crn_copymap = $this->read_crn_copymap();
111105

106+
// Helper object for special-cases involving RCOS.
107+
$this->rcos = new rcos();
108+
112109
// Init other properties.
113110
$this->invalid_courses = [];
114111
$this->data = [];
@@ -203,9 +200,6 @@ private function get_csv_data() {
203200
// Course is comprised of an alphabetic prefix and a numeric suffix.
204201
$course = strtolower($row[COLUMN_COURSE_PREFIX] . $row[COLUMN_COURSE_NUMBER]);
205202

206-
// Check/perform special-case RCOS registration section mapping.
207-
rcos::map($course, $row);
208-
209203
switch(true) {
210204
// Check that $row has an appropriate student registration.
211205
case array_search($row[COLUMN_REGISTRATION], $all_valid_reg_codes) === false:
@@ -224,6 +218,9 @@ private function get_csv_data() {
224218
// Check that $row is associated with the course list.
225219
case array_search($course, $this->course_list) !== false:
226220
if (validate::validate_row($row, $row_num)) {
221+
// Check (and perform) special-case RCOS registration section mapping.
222+
$this->rcos->map($course, $row);
223+
227224
// Include $row
228225
$this->data[$course][] = $row;
229226

@@ -245,8 +242,13 @@ private function get_csv_data() {
245242
if (array_key_exists($section, $this->mapped_courses[$course])) {
246243
$m_course = $this->mapped_courses[$course][$section]['mapped_course'];
247244
if (validate::validate_row($row, $row_num)) {
248-
// Include $row.
245+
// Do course mapping (alters registration section).
249246
$row[COLUMN_SECTION] = $this->mapped_courses[$course][$section]['mapped_section'];
247+
248+
// Check (and override) for special-case RCOS registration section mapping.
249+
$this->rcos->map($course, $row);
250+
251+
// Include $row.
250252
$this->data[$m_course][] = $row;
251253

252254
// $row with a blank email is allowed, but it is also logged.

0 commit comments

Comments
 (0)