diff --git a/student_auto_feed/config.php b/student_auto_feed/config.php index 5595e2e..2aa4e60 100644 --- a/student_auto_feed/config.php +++ b/student_auto_feed/config.php @@ -52,17 +52,35 @@ // accessed locally or remotely. define('CSV_FILE', '/path/to/datafile.csv'); -// Student registration status is important, as data dumps can contain students -// who have dropped a course either before the semester starts or during the -// semester. This array will contain all valid registered-student codes can be -// expected in the data dump. -// -// IMPORTANT: Consult with your University's IT administrator and/or registrar -// to add all pertinant student-is-registered codes that can be found -// in your CSV data dump. EXAMPLE: 'RA' may mean "registered by -// advisor" and 'RW' may mean "registered via web" +/* STUDENT REGISTRATION CODES -------------------------------------------------- + * + * Student registration status is important, as data dumps can contain students + * who have dropped a course either before the semester starts or during the + * semester. Be sure that all codes are set as an array, even when only one + * code is found in the CSV data. Set to NULL when there are no codes for + * either student auditing a course or students late-withdrawn from a course. + * + * IMPORTANT: Consult with your University's IT administrator and/or registrar + * for the pertinant student registration codes that can be found in + * your CSV data dump. + * + * -------------------------------------------------------------------------- */ + +// These codes are for students who are registered to take a course for a grade. +// EXAMPLE: 'RA' may mean "registered by advisor" and 'RW' may mean +// "registered via web". Do not set to NULL. define('STUDENT_REGISTERED_CODES', array('RA', 'RW')); +// These codes are for students auditing a course. These students will not be +// given a grade. +// Set this to NULL if your CSV data does not provide this information. +define('STUDENT_AUDIT_CODES', array('AU')); + +// These codes are for students who have dropped their course after the drop +// deadline and are given a late-drop or withdrawn code on their transcript. +// Set this to NULL if your CSV data does not provide this information. +define('STUDENT_LATEDROP_CODES', array('W')); + //An exceptionally small file size can indicate a problem with the feed, and //therefore the feed should not be processed to preserve data integrity of the //users table. Value is in bytes. You should pick a reasonable minimum diff --git a/student_auto_feed/ssaf_db.php b/student_auto_feed/ssaf_db.php index 9804054..19fec1a 100644 --- a/student_auto_feed/ssaf_db.php +++ b/student_auto_feed/ssaf_db.php @@ -175,12 +175,27 @@ public static function upsert($semester, $course, $rows) : bool { $row[COLUMN_EMAIL] ); + // Determine registration type for courses_users table + // Registration type code has already been validated by now. + switch(true) { + case in_array($row[COLUMN_REGISTRATION], STUDENT_REGISTERED_CODES): + $registration_type = sql::RT_GRADED; + break; + case in_array($row[COLUMN_REGISTRATION], STUDENT_AUDIT_CODES): + $registration_type = sql::RT_AUDIT; + break; + default: + $registration_type = sql::RT_LATEDROP; + break; + } + $courses_users_params = array( $semester, $course, $row[COLUMN_USER_ID], 4, $row[COLUMN_SECTION], + $registration_type, "FALSE" ); diff --git a/student_auto_feed/ssaf_sql.php b/student_auto_feed/ssaf_sql.php index 34f103b..298e512 100644 --- a/student_auto_feed/ssaf_sql.php +++ b/student_auto_feed/ssaf_sql.php @@ -12,6 +12,11 @@ class sql { public const COMMIT = "COMMIT"; public const ROLLBACK = "ROLLBACK"; + // Registration type constants + public const RT_GRADED = "graded"; + public const RT_AUDIT = "audit"; + public const RT_LATEDROP = "withdrawn"; + // SELECT queries public const GET_COURSES = <<course_list) !== false) { if (validate::validate_row($row, $row_num)) { @@ -192,6 +196,10 @@ private function get_csv_data() { if (validate::validate_row($row, $row_num)) { $row[COLUMN_SECTION] = $this->mapped_courses[$course][$section]['mapped_section']; $this->data[$m_course][] = $row; + // Rows with blank emails are allowed, but they are being logged. + if ($row[COLUMN_EMAIL] === "") { + $this->log_it("Blank email found for user {$row[COLUMN_USER_ID]}, row {$row_num}."); + } } else { $this->invalid_courses[$m_course] = true; $this->log_it(validate::$error); @@ -335,20 +343,12 @@ private function invalidate_courses() { */ private function open_csv() { $this->fh = fopen(CSV_FILE, "r"); - if ($this->fh !== false) { - if (flock($this->fh, LOCK_SH, $wouldblock)) { - return true; - } else if ($wouldblock === 1) { - $this->logit("Another process has locked the CSV."); - return false; - } else { - $this->logit("CSV not blocked, but still could not attain lock for reading."); - return false; - } - } else { + if ($this->fh === false) { $this->log_it("Could not open CSV file."); return false; } + + return true; } /** Close CSV file */