letter = $letter; $this->start = $time_start; $this->tend = $time_end; $this->idays = $days; $this->bdays = $this->setbdays(); $this->synonym = $synonym; $this->prof = $prof; $this->room = $room; } private function setbdays() { $result = array(FALSE, FALSE, FALSE, FALSE, FALSE); if($this->idays == 12345) {$result[0] = true; $result[1] = true; $result[2] = true; $result[3] = true; $result[4] = true;} if($this->idays == 1234) {$result[0] = true; $result[1] = true; $result[2] = true; $result[3] = true; $result[4] = false;} if($this->idays == 1235) {$result[0] = true; $result[1] = true; $result[2] = true; $result[3] = false; $result[4] = true;} if($this->idays == 1245) {$result[0] = true; $result[1] = true; $result[2] = false; $result[3] = true; $result[4] = true;} if($this->idays == 1345) {$result[0] = true; $result[1] = false; $result[2] = true; $result[3] = true; $result[4] = true;} if($this->idays == 2345) {$result[0] = false; $result[1] = true; $result[2] = true; $result[3] = true; $result[4] = true;} if($this->idays == 123) {$result[0] = true; $result[1] = true; $result[2] = true; $result[3] = false; $result[4] = false;} if($this->idays == 124) {$result[0] = true; $result[1] = true; $result[2] = false; $result[3] = true; $result[4] = false;} if($this->idays == 125) {$result[0] = true; $result[1] = true; $result[2] = false; $result[3] = false; $result[4] = true;} if($this->idays == 134) {$result[0] = true; $result[1] = false; $result[2] = true; $result[3] = true; $result[4] = false;} if($this->idays == 135) {$result[0] = true; $result[1] = false; $result[2] = true; $result[3] = false; $result[4] = true;} if($this->idays == 145) {$result[0] = true; $result[1] = false; $result[2] = false; $result[3] = true; $result[4] = true;} if($this->idays == 234) {$result[0] = false; $result[1] = true; $result[2] = true; $result[3] = true; $result[4] = false;} if($this->idays == 235) {$result[0] = false; $result[1] = true; $result[2] = true; $result[3] = false; $result[4] = true;} if($this->idays == 245) {$result[0] = false; $result[1] = true; $result[2] = false; $result[3] = true; $result[4] = true;} if($this->idays == 345) {$result[0] = false; $result[1] = false; $result[2] = true; $result[3] = true; $result[4] = true;} if($this->idays == 12) {$result[0] = true; $result[1] = true; $result[2] = false; $result[3] = false; $result[4] = false;} if($this->idays == 13) {$result[0] = true; $result[1] = false; $result[2] = true; $result[3] = false; $result[4] = false;} if($this->idays == 14) {$result[0] = true; $result[1] = false; $result[2] = false; $result[3] = true; $result[4] = false;} if($this->idays == 15) {$result[0] = true; $result[1] = false; $result[2] = false; $result[3] = false; $result[4] = true;} if($this->idays == 23) {$result[0] = false; $result[1] = true; $result[2] = true; $result[3] = false; $result[4] = false;} if($this->idays == 24) {$result[0] = false; $result[1] = true; $result[2] = false; $result[3] = true; $result[4] = false;} if($this->idays == 25) {$result[0] = false; $result[1] = true; $result[2] = false; $result[3] = false; $result[4] = true;} if($this->idays == 34) {$result[0] = false; $result[1] = false; $result[2] = true; $result[3] = true; $result[4] = false;} if($this->idays == 35) {$result[0] = false; $result[1] = false; $result[2] = true; $result[3] = false; $result[4] = true;} if($this->idays == 45) {$result[0] = false; $result[1] = false; $result[2] = false; $result[3] = true; $result[4] = true;} if($this->idays == 1) {$result[0] = true; $result[1] = false; $result[2] = false; $result[3] = false; $result[4] = false;} if($this->idays == 2) {$result[0] = false; $result[1] = true; $result[2] = false; $result[3] = false; $result[4] = false;} if($this->idays == 3) {$result[0] = false; $result[1] = false; $result[2] = true; $result[3] = false; $result[4] = false;} if($this->idays == 4) {$result[0] = false; $result[1] = false; $result[2] = false; $result[3] = true; $result[4] = false;} if($this->idays == 5) {$result[0] = false; $result[1] = false; $result[2] = false; $result[3] = false; $result[4] = true;} return $result; } public function getLetter() { return $this->letter; } public function getProf() { return $this->prof; } /** * \return * This Section's room or NULL if none is defined. */ public function getRoom() { return $this->room; } /** * \return * This section's synonym -- a unique numeric identifier for this * course. NULL if undefined. */ public function getSynonym() { return $this->synonym; } public function getStartTime() { return $this->start; } public function getEndTime() { return $this->tend; } public function getM() { return $this->bdays[0]; } public function getTu() { return $this->bdays[1]; } public function getW() { return $this->bdays[2]; } public function getTh() { return $this->bdays[3]; } public function getF() { return $this->bdays[4]; } public function getDay($i) { return $this->bdays[$i]; } /** * \brief * Check if this section conflicts withthe given section. * * \param $that * The other section for which I should check for conflicts. * \return * TRUE if there is a conflict, FALSE otherwise. */ public function conflictsWith(Section $that) { /* * The two sections can't conflict if the start/end times don't * overlap. Also, use >= or <= here so that one can say ``I have * gym from 10 through 11 and then latin from 11 though 12''. */ if ($this->getStartTime() >= $that->getEndTime() || $this->getEndTime() <= $that->getStartTime()) { return FALSE; } /* * Now we know that the sections overlap in start/end times. But * if they don't both meet on the same day at least once, they * don't conflict. */ for ($day = 0; $day < 5; $day ++) { if ($this->getDay($day) && $that->getDay($day)) return TRUE; } /* * The sections don't both share a day of the week. */ return FALSE; } /** * \brief * Splits up a section specifier into dept, course number, and * section. * * For example, will return array('CS', '262', 'A') for 'CS-262-A' * or 'CS262 A' or 'cs-262,a'. This function is not for dealing with * course synonyms. * * Note: Section specifiers where the section numeral/letter is * directly adjacent to the course number is not valid. Calvin * College distinguishes between normal courses and their labs by * appending an `L' to the course number. Thus, 'CS262A' is not a * valid specifier for 'CS-262-A' because there may exist another * course called 'CS-262L-A' (which is likely the lab for the * 'CS-262-A' class ;-)). * * \param $section_spec * A string starting with a section specifier. If only the * department is found, an array of size one is returned. If the * course number is also found, both department and course id are * returned. If all three are found, the array has three elements. * * This array is keyed, so the found items may be referred to as * 'deptartment', 'course', and 'section'. * * \return * An array with the department, course number, and section * identifier. This array may be empty or have from one through * three elements depending on the validity and precision of the * $section_spec. */ public static function parse($section_spec) { $ret = array(); $section_spec = trim($section_spec); if (!preg_match(';([a-zA-Z]+)[^0-9]*;', $section_spec, $dept_matches)) return $ret; /* * remove away the already-parsed stuff, including gunk between the * dept and the course num. */ $section_spec = trim(substr($section_spec, strlen($dept_matches[0]))); $ret['department'] = strtoupper($dept_matches[1]); if (!preg_match(';([0-9a-zA-Z]+)[^a-zA-Z0-9]*;', $section_spec, $course_matches)) return $ret; /* skip gunk */ $section_spec = trim(substr($section_spec, strlen($course_matches[0]))); $ret['course'] = strtoupper($course_matches[1]); /* * we accept _either_ alphabetic section _or_ numeric section (the * latter is for cedarville, particulaly) */ if (!preg_match(';([0-9]+|[a-zA-Z]+);', $section_spec, $section_matches)) return $ret; $ret['section'] = strtoupper($section_matches[1]); return $ret; } /** * \brief * Get an array of information needed by the AJAX stuff. */ public function to_json_array() { static $daymap = array(0 => 'm', 1 => 't', 2 => 'w', 3 => 'h', 4 => 'f'); $json_array = array('section' => $this->letter, 'prof' => $this->prof, 'time_start' => $this->start, 'time_end' => $this->tend, 'days' => array(), 'synonym' => $this->synonym, 'room' => $this->room, ); for ($day = 0; $day < 5; $day ++) $json_array['days'][$daymap[$day]] = $this->getDay($day); return $json_array; } }