/** * Retrieves the meeting information for a section * @param $sectionData array Information about a section MUST HAVE: * title, instructor, curenroll, maxenroll, * department, course, section, section id, * type. * @return array A course array with all the information about the course */ function getMeetingInfo($sectionData) { // Store the course information $course = array("title" => $sectionData['title'], "instructor" => $sectionData['instructor'], "curenroll" => $sectionData['curenroll'], "maxenroll" => $sectionData['maxenroll'], "courseNum" => "{$sectionData['department']}-{$sectionData['course']}-{$sectionData['section']}", "courseParentNum" => "{$sectionData['department']}-{$sectionData['course']}", "courseId" => $sectionData['courseId'], "id" => $sectionData['id'], "online" => $sectionData['type'] == "O", "credits" => $sectionData['credits']); if (isset($sectionData['description'])) { $course['description'] = $sectionData['description']; } // Make sure special sections don't get double-counted for their credits if (isSpecialSection($course)) { $course['credits'] = "0"; // string for consistency's sake } // Now we query for the times of the section $query = "SELECT b.code, b.number, b.off_campus, t.room, t.day, t.start, t.end "; $query .= "FROM times AS t JOIN buildings AS b ON b.number=t.building "; $query .= "WHERE section = {$sectionData['id']}"; $result = mysql_query($query); if (!$result) { throw new Exception("mysql:" . mysql_error()); } while ($row = mysql_fetch_assoc($result)) { $course["times"][] = array("bldg" => array("code" => $row['code'], "number" => $row['number']), "room" => $row['room'], "day" => $row['day'], "start" => $row['start'], "end" => $row['end'], "off_campus" => $row['off_campus'] == '1'); } return $course; }
/** * Prunes invalid schedules based on courseGroups * @param $schedules * @param $courseGroups * @return array */ function pruneSpecialCourses($schedules, $courseGroups) { // The array of schedules that meet all course requirements $validSchedules = array(); // Loop through each possible schedule foreach ($schedules as $schedule) { // Flattened schedule [courseNum => <value>] where <value> is: // false: no co-requirements // true: is a co-requirement // string[]: list of possible requirements $flattenedSchedule = array(); // Loop through each course foreach ($schedule as &$course) { $cleanCourseNum = getCleanCourseNum($course); // This course has selected labs or is a lab if (array_key_exists($cleanCourseNum, $courseGroups) && count($courseGroups[$cleanCourseNum]) > 0) { if (!isSpecialSection($course)) { // Set the course requirement as an array of courseNum strings $flattenedSchedule[$course['courseNum']] = array_keys($courseGroups[$cleanCourseNum]); } else { $flattenedSchedule[$course['courseNum']] = true; } } else { $flattenedSchedule[$course['courseNum']] = false; } } $scheduleMeetsRequirements = true; // Loop through the flatten schedules foreach ($flattenedSchedule as $courseNum => $courseRequirements) { // Check if course has requirements if (is_array($courseRequirements)) { $courseMeetsRequirement = false; // Loop through the requirements, checking if the schedule contains AT LEAST one required course foreach ($courseRequirements as $specialCourseNum) { if (array_key_exists($specialCourseNum, $flattenedSchedule)) { $courseMeetsRequirement = true; break; } } // "AND" the previous results with the current one $scheduleMeetsRequirements = $scheduleMeetsRequirements && $courseMeetsRequirement; // Don't bother checking other courses if the schedule already does not meet requirements if (!$scheduleMeetsRequirements) { continue; } } } // Add this to the valid schedules if it meets all requirements if ($scheduleMeetsRequirements) { $validSchedules[] = $schedule; } } // Return the resulting array of all schedules that met co-requirements return $validSchedules; }