function process_course($fields, $now) { list($year, $semester_name) = $this->parse_semester($fields[0]); $semester = CoursePrefsSemester::findByUnique($year, $semester_name, $fields[2]); if (!$semester) { throw new Exception(get_string('no_semester', 'block_courseprefs')); } // Check to see if the course already exists; if not, then create it $course = CoursePrefsCourse::findByUnique($fields[3], $fields[4]); $first_year = $fields[12] == 'FY' ? 1 : 0; if (!$course) { $course = new CoursePrefsCourse($fields[3], $fields[4], $fields[6], $fields[10], $fields[11], $fields[12]); } // For updating pruposes $course->setCourseType($fields[10]); $course->setGradeType($fields[11]); $course->setFirstYear($first_year); // Log exception if the course doesn't exist and could not be created try { $course->save(); } catch (Exception $e) { throw new Exception($e->getMessage()); } $section = CoursePrefsSection::findByUnique($semester->getId(), $course->getId(), $fields[5]); if (!$section) { $section = new CoursePrefsSection($semester->getId(), $course->getId(), $fields[5]); } // Log exception if the section doesn't exist and could not be created try { // Only attempt to save the section if it doesn't have an id; new entry if (!$section->getId()) { $section->save(); $name = "{$year} {$semester_name} {$course->getDepartment()} {$course->getCourseNumber()}"; CoursePrefsLog::add_to_log(0, $section->getId(), $now, 'create', $name); } } catch (Exception $e) { throw new Exception($e->getMessage()); } return $section; }