Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions schema/migrationScripts/f_4charcourses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ CREATE PROCEDURE InsertOrUpdateCourse(
IN p_course VARCHAR(4),
IN p_credits INT,
IN p_title VARCHAR(50),
IN p_description TEXT
IN p_description TEXT,
IN p_prerequisites TEXT,
IN p_typically_offered TEXT,
IN p_contact_hours TEXT
)
BEGIN
-- Determine if the course already exists
Expand Down Expand Up @@ -52,13 +55,13 @@ CREATE PROCEDURE InsertOrUpdateCourse(
IF recordFound > 0 THEN
-- Course exists, so update it
UPDATE courses AS c
SET c.title = p_title, c.description = p_description, c.credits = p_credits
SET c.title = p_title, c.description = p_description, c.credits = p_credits, c.prerequisites = p_prerequisites, c.typically_offered = p_typically_offered, c.contact_hours = p_contact_hours
WHERE c.department = v_department AND course = p_course AND quarter = p_quarter;
SELECT "updated" AS action;
ELSE
-- Course doesn't exist, so insert it
INSERT INTO courses (quarter, department, course, title, description, credits)
VALUES(p_quarter, v_department, p_course, p_title, p_description, p_credits);
INSERT INTO courses (quarter, department, course, title, description, credits, prerequisites, typically_offered, contact_hours)
VALUES(p_quarter, v_department, p_course, p_title, p_description, p_credits, p_prerequisites, p_typically_offered, p_contact_hours);
SELECT "inserted" AS action;
END IF;

Expand Down
11 changes: 7 additions & 4 deletions schema/procedures/InsertOrUpdateCourse.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ CREATE PROCEDURE InsertOrUpdateCourse(
IN p_course VARCHAR(4),
IN p_credits INT,
IN p_title VARCHAR(50),
IN p_description TEXT
IN p_description TEXT,
IN p_prerequisites TEXT,
IN p_typically_offered TEXT,
IN p_contact_hours TEXT
)
BEGIN
-- Determine if the course already exists
Expand Down Expand Up @@ -40,13 +43,13 @@ BEGIN
IF recordFound > 0 THEN
-- Course exists, so update it
UPDATE courses AS c
SET c.title = p_title, c.description = p_description, c.credits = p_credits
SET c.title = p_title, c.description = p_description, c.credits = p_credits, c.prerequisites = p_prerequisites, c.typically_offered = p_typically_offered, c.contact_hours = p_contact_hours
WHERE c.department = v_department AND course = p_course AND quarter = p_quarter;
SELECT "updated" AS action;
ELSE
-- Course doesn't exist, so insert it
INSERT INTO courses (quarter, department, course, title, description, credits)
VALUES(p_quarter, v_department, p_course, p_title, p_description, p_credits);
INSERT INTO courses (quarter, department, course, title, description, credits, prerequisites, typically_offered, contact_hours)
VALUES(p_quarter, v_department, p_course, p_title, p_description, p_credits, p_prerequisites, p_typically_offered, p_contact_hours);
SELECT "inserted" AS action;
END IF;

Expand Down
5 changes: 4 additions & 1 deletion schema/tables/courses.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ CREATE TABLE courses (
`course` VARCHAR(4) NOT NULL,
`credits` TINYINT(2) UNSIGNED NOT NULL DEFAULT 0,
`title` VARCHAR(50) NOT NULL,
`description` TEXT NOT NULL
`description` TEXT NOT NULL,
`prerequisites` TEXT NOT NULL,
`typically_offered` TEXT NOT NULL,
`contact_hours` TEXT NOT NULL
)ENGINE=InnoDb;

-- INDEXING ----------------------------------------------------------------
Expand Down
23 changes: 13 additions & 10 deletions tools/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,31 @@ function halt($messages) {
/**
* Inserts or updates a course. This function calls the stored procedure for
* inserting or updating a course.
* @param $quarter int The term that the course is in
* @param $departCode string The code of the department
* @param $classCode string The code for the class
* @param $course string The number of the course
* @param $credits int The credits the course offers
* @param $title string The title of the course
* @param $description string The description for the course
* @param $quarter int The term that the course is in
* @param $departCode string The code of the department
* @param $classCode string The code for the class
* @param $course string The number of the course
* @param $credits int The credits the course offers
* @param $title string The title of the course
* @param $description string The description for the course
* @param $prerequisites string The prerequisites for the course
* @param $typicallyOffered string The typically offered semester for the course
* @param $contactHours string The contact hours for the course
* @return mixed String of error message returned on failure.
* Integer of course ID returned on success
*/
function insertOrUpdateCourse(int $quarter, string $departCode, string $classCode, string $course, int $credits, string $title, string $description) {
function insertOrUpdateCourse(int $quarter, string $departCode, string $classCode, string $course, int $credits, string $title, string $description, string $prerequisites, string $typicallyOffered, string $contactHours) {
global $coursesUpdated, $coursesAdded;
// Call the stored proc
// TODO: Refactor out department ID number (0000)
$query = "CALL InsertOrUpdateCourse({$quarter}, 0000, '{$classCode}', '{$course}', {$credits}, '{$title}', '{$description}')";
$query = "CALL InsertOrUpdateCourse({$quarter}, 0000, '{$classCode}', '{$course}', {$credits}, '{$title}', '{$description}', '{$prerequisites}', '{$typicallyOffered}', '{$contactHours}')";
$success = mysqli_multi_query($this->dbConn, $query);

// Catch errors or return the id
if (!$success) {
// If the class code errors out, try the department code
// TODO: Refactor out department ID number (0000)
$query = "CALL InsertOrUpdateCourse({$quarter}, 0000, '{$departCode}', '{$course}', {$credits}, '{$title}', '{$description}')";
$query = "CALL InsertOrUpdateCourse({$quarter}, 0000, '{$departCode}', '{$course}', {$credits}, '{$title}', '{$description}', '{$prerequisites}', '{$typicallyOffered}', '{$contactHours}')";
$success = mysqli_multi_query($this->dbConn, $query);
if (!$success) {
return mysqli_error($this->dbConn);
Expand Down
13 changes: 9 additions & 4 deletions tools/processDump.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
`acad_career` varchar(4) NOT NULL,
`instruction_mode` varchar(2) NOT NULL,
`course_descrlong` text NOT NULL,
`prereqs` text NOT NULL,
`typ_offr` text NOT NULL,
`ctc_hrs` text NOT NULL,
PRIMARY KEY (`crse_id`,`crse_offer_nbr`,`strm`,`session_code`,`class_section`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
ENE;
Expand All @@ -112,7 +115,7 @@
$parser->halt(["Error: Failed to create temporary class table", mysqli_error($dbConn)]);
}

$parser->fileToTempTable("classes", $classFile, 24, $classSize, "procClassArray");
$parser->fileToTempTable("classes", $classFile, 27, $classSize, "procClassArray");
fclose($classFile);

// Build a temporary table for the meeting patterns
Expand Down Expand Up @@ -266,9 +269,8 @@
$failures++;
}
$departmentsProc = mysqli_affected_rows($dbConn);

// Grab each COURSE from the classes table
$courseQuery = "SELECT strm, subject, units, acad_org, catalog_nbr, descr, course_descrlong,";
$courseQuery = "SELECT strm, subject, units, acad_org, catalog_nbr, descr, course_descrlong, prereqs, typ_offr, ctc_hrs";
$courseQuery .= " crse_id, crse_offer_nbr, session_code";
$courseQuery .= " FROM classes WHERE strm < 20130 GROUP BY crse_id, strm, session_code";
$parser->debug("... Updating courses\n0%", false);
Expand Down Expand Up @@ -298,10 +300,13 @@
// Escape the necessary fields
$row['descr'] = mysqli_real_escape_string($dbConn, $row['descr']);
$row['course_descrlong'] = mysqli_real_escape_string($dbConn, $row['course_descrlong']);
$row['prereqs'] = mysqli_real_escape_string($dbConn, $row['prereqs']);
$row['typ_offr'] = mysqli_real_escape_string($dbConn, $row['typ_offr']);
$row['ctc_hrs'] = mysqli_real_escape_string($dbConn, $row['ctc_hrs']);

// Insert or update the course
@$courseId = $parser->insertOrUpdateCourse($row['qtr'], $row['acad_org'], $row['subject'], $row['catalog_nbr'],
(int)$row['units'], $row['descr'], $row['course_descrlong']);
(int)$row['units'], $row['descr'], $row['course_descrlong'], $row['prereqs'], $row['typ_offr'], $row['ctc_hrs']);
if (!is_numeric($courseId)) {
echo(" *** Error: Failed to update {$row['qtr']} {$row['subject']}-{$row['catalog_nbr']}\n");
echo(" ");
Expand Down
Loading