@@ -80,24 +80,31 @@ function halt($messages) {
8080 * Inserts or updates a course. This function calls the stored procedure for
8181 * inserting or updating a course.
8282 * @param $quarter int The term that the course is in
83- * @param $departNum int The number of the department
84- * @param $departCode int The code for the department
83+ * @param $departCode String The code of the department
84+ * @param $classCode String The code for the class
8585 * @param $course int The number of the course
8686 * @param $credits int The credits the course offers
8787 * @param $title String The title of the course
8888 * @param $description String The description for the course
8989 * @return mixed String of error message returned on failure.
9090 * Integer of course ID returned on success
9191 */
92- function insertOrUpdateCourse ($ quarter , $ departNum , $ departCode , $ course , $ credits , $ title , $ description ) {
92+ function insertOrUpdateCourse ($ quarter , $ departCode , $ classCode , $ course , $ credits , $ title , $ description ) {
9393 global $ dbConn , $ coursesUpdated , $ coursesAdded ;
9494 // Call the stored proc
95- $ query = "CALL InsertOrUpdateCourse( {$ quarter }, {$ departNum }, ' {$ departCode }', ' {$ course }', {$ credits }, ' {$ title }', ' {$ description }') " ;
95+ // TODO: Refactor out department ID number (0000)
96+ $ query = "CALL InsertOrUpdateCourse( {$ quarter }, 0000, ' {$ classCode }', ' {$ course }', {$ credits }, ' {$ title }', ' {$ description }') " ;
9697 $ success = mysqli_multi_query ($ dbConn , $ query );
9798
9899 // Catch errors or return the id
99100 if (!$ success ) {
100- return mysqli_error ($ dbConn );
101+ // If the class code errors out, try the department code
102+ // TODO: Refactor out department ID number (0000)
103+ $ query = "CALL InsertOrUpdateCourse( {$ quarter }, 0000, ' {$ departCode }', ' {$ course }', {$ credits }, ' {$ title }', ' {$ description }') " ;
104+ $ success = mysqli_multi_query ($ dbConn , $ query );
105+ if (!$ success ) {
106+ return mysqli_error ($ dbConn );
107+ }
101108 }
102109
103110 // First result set is updated vs inserted
@@ -457,13 +464,10 @@ function procInstrArray($lineSplit) {
457464 preg_match ("/(\d)(\d{3})/ " , $ row ['strm ' ], $ match );
458465 $ row ['strm ' ] = $ match [1 ] . 0 . $ match [2 ];
459466
460- // Create a default break value
461- $ break = '0000-00-00 ' ;
462-
463467 // Insert the quarter
464468 // TODO: Change schema from quarters to semesters (I doubt they're switching back anytime soon)
465- $ query = "INSERT INTO quarters (quarter, start, end, breakstart, breakend ) " ;
466- $ query .= " VALUES( {$ row ['strm ' ]}, ' {$ row ['start_dt ' ]}', ' {$ row ['end_dt ' ]}', $ break , $ break ) " ;
469+ $ query = "INSERT INTO quarters (` quarter`, ` start`, ` end` ) " ;
470+ $ query .= " VALUES( {$ row ['strm ' ]}, ' {$ row ['start_dt ' ]}', ' {$ row ['end_dt ' ]}') " ;
467471 $ query .= " ON DUPLICATE KEY UPDATE " ;
468472 $ query .= " start=' {$ row ['start_dt ' ]}', end=' {$ row ['end_dt ' ]}' " ;
469473
@@ -561,10 +565,10 @@ function procInstrArray($lineSplit) {
561565 $ row ['course_descrlong ' ] = mysqli_real_escape_string ($ dbConn , $ row ['course_descrlong ' ]);
562566
563567 // Insert or update the course
564- $ courseId = insertOrUpdateCourse ($ row ['qtr ' ], 0000 , $ row ['acad_org ' ], $ row ['catalog_nbr ' ],
568+ $ courseId = insertOrUpdateCourse ($ row ['qtr ' ], $ row [ ' acad_org ' ] , $ row ['subject ' ], $ row ['catalog_nbr ' ],
565569 $ row ['units ' ], $ row ['descr ' ], $ row ['course_descrlong ' ]);
566- if (!is_numeric ($ courseId )) {
567- echo (" *** Error: Failed to update {$ row ['qtr ' ]} {$ row ['subject ' ]}{ $ row [ ' acad_org ' ]} - {$ row ['catalog_nbr ' ]}\n" );
570+ if (!is_numeric ($ courseId )) {
571+ echo (" *** Error: Failed to update {$ row ['qtr ' ]} {$ row ['subject ' ]}- {$ row ['catalog_nbr ' ]}\n" );
568572 echo (" " );
569573 var_dump ($ courseId );
570574 echo ("\n" );
0 commit comments