. */ //************************************************** // class.schedule.php Author: Nathan Gelderloos // // Represents a schedule of a week. Stores the // classes that are part of that week and calculates // all the possible permutations. //************************************************** $incdir = dirname(__FILE__) . DIRECTORY_SEPARATOR; include_once $incdir . 'class.course.inc'; include_once $incdir . 'class.section.php'; include_once $incdir . 'class.page.php'; /* * Load a Classes -> Course converter class for the sake of the * Schedule::__wakeup() magic function. */ require_once $incdir . 'class.classes_convert.inc'; class Schedule { /* * Variables for upgrading from saved schedules created when there * was a class called Classes. */ private $classStorage; // array of courses private $nclasses; // Integer number of classes /* My member variables. */ private $courses; private $nPermutations = 0; // Integer number of real permutations private $possiblePermutations; // Integer number of possible permutations private $scheduleName; // String name of schedule private $storage; // Integer array of valid schedules /* The
' . PHP_EOL . ' Edit' . PHP_EOL . ' Print' . PHP_EOL . ' ' . PHP_EOL; if ($schedule_store !== NULL && $this->parent_get() !== NULL && ($parent_schedule = schedule_store_retrieve($schedule_store, $this->parent_get())) !== NULL) echo ' Parent' . PHP_EOL; echo ' Home' . PHP_EOL . '
'. PHP_EOL . 'Having problems? Let us know.
' . PHP_EOL . 'Keyboard Shortcut: Left and right arrow keys switch between schedules
' . PHP_EOL; } echo "\n"; if($this->nPermutations > 0) { /* * Figure out if we have to deal with Saturday and then deal * with it. * * Also, ensure that our $time array is big enough for all of * these courses. */ $max_day_plusone = 5; $have_saturday = FALSE; $max_time = (int)max($time); $min_time = (int)min($time); $sort_time = FALSE; foreach ($this->courses as $course) { for ($si = 0; $si < $course->getnsections(); $si ++) foreach ($course->getSection($si)->getMeetings() as $meeting) { /* Saturdayness */ if ($meeting->getDay(5)) { $max_day_plusone = 6; $have_saturday = TRUE; } /* very late / very early classes */ while ($meeting->getEndTime() > $max_time) { $max_time += 30; $time[] = $max_time; } while ($meeting->getStartTime() < $min_time) { $min_time -= 30; $time[] = $min_time; $sort_time = TRUE; } } } /* ensure that early times are actually first ;-) */ if ($sort_time) sort($time); echo 'Note: The registration information above corresponds to the sections displayed on the currently selected tab.
' . '| ' . ($i + 1) . " | \n" . "Monday | \n" . "Tuesday | \n" . "Wednesday | \n" . "Thursday | \n" . "Friday | \n"; if ($have_saturday) echo "Saturday | \n"; echo "
| " . $this->prettyTime($time[$r]) . " | \n"; /* currently, 0-5 = monday-saturday */ for($dayLoop = 0; $dayLoop < $max_day_plusone; $dayLoop++) { /* Makes sure there is not a class already in progress */ if($rowspan[$dayLoop] <= 0) { for($j = 0; $j < count($this->courses); $j++) { $course = $this->courses[$j]; $section_index = $this->storage[$i][$j]; $section = $course->getSection($section_index); /* iterate through all of a class's meeting times */ $meetings = $section->getMeetings(); /* find any meeting which are going on at this time */ $current_meeting = NULL; foreach ($meetings as $meeting) { if ($meeting->getDay($dayLoop) && $meeting->getStartTime() >= $time[$r] && $meeting->getStartTime() < $time[$r+1]) { $current_meeting = $meeting; } } if ($current_meeting) { /* calculate how many rows this section should span */ for ($my_r = $r; $my_r < (count($time)-1) && $current_meeting->getEndTime() > $time[$my_r]; $my_r ++) ; $rowspan[$dayLoop] = $my_r - $r; $single_multi = 'single'; if ($rowspan[$dayLoop] > 1) $single_multi = 'multi'; $title = $course->title_get(); if (empty($title)) $title = ''; else $title .= ' '; $carret = ' ' . htmlentities("' . '' . htmlentities($title) . '' . PHP_EOL . htmlentities($course->getName(), ENT_QUOTES) . '-' . htmlentities($section->getLetter(), ENT_QUOTES) . "\n" . '' . htmlentities($section->getProf(), ENT_QUOTES) . "\n" . '' . htmlentities($current_meeting->getLocation(), ENT_QUOTES) . "\n" . '' . htmlentities($section->getSynonym(), ENT_QUOTES) . "\n" . " | \n"; /* for the ``Registration Codes'' dialogue: */ if (empty($permutations_courses[$j])) { $singleton_course = new Course($course->getName(), $course->title_get()); $singleton_course->section_add($section); $permutation_courses[$j] = $singleton_course->to_json_array(); } $filled = TRUE; } } } if ($rowspan[$dayLoop] > 0) { $filled = TRUE; $rowspan[$dayLoop] --; } /* If the cell was not filled, fill it with an empty cell. */ if(!$filled) { echo "\n"; } $filled = FALSE; } // End of row echo " |
There are no possible schedules. Please try again.
'; } echo "There were a total of " . $this->possiblePermutations . " possible permutations. Only " . $this->nPermutations . " permutations had no class conflicts.
"; $outputPage->foot(); } //-------------------------------------------------- // Changes the title of the page. //-------------------------------------------------- function changeTitle($t) { $this->title = $t; } //-------------------------------------------------- // Make the time "pretty" //-------------------------------------------------- function prettyTime($t){ if($t > 1259) { $t = ($t-1200); return substr($t, 0, strlen($t)-2) . ":" . substr($t, strlen($t)-2, strlen($t)) . " PM"; } else { return substr($t, 0, strlen($t)-2) . ":" . substr($t, strlen($t)-2, strlen($t)) . " AM"; } } /** * \brief * fetch the number of classes */ function nclasses_get() { return count($this->courses); } /** * \brief * fetch a specified class by its key */ function class_get($class_key) { return $this->courses[$class_key]; } /** * \brief * Set my global ID. * * Only to be called by schedule_store_store(). */ function id_set($id) { $this->id = $id; } /* * \brief * Get my global ID. */ function id_get() { return $this->id; } /** * \brief * Write out a relative URL for a particular schedule. * * Takes into account the $clean_urls setting. * * \param $id * The ID of the schedule to link to. Defaults to the current schedule object. * \param $page * The page of the schedule to link to. Defaults to 0. * \return * A string, the URL used to access this schedule. Remember that * if this string is inserted into an XHTML document, * htmlentities() must be called on it. */ function url($id = NULL, $page = 0) { global $clean_urls; $url = ''; if (!$clean_urls) $url .= 'process.php?s='; if (!$id) $id = $this->id; $url .= (int)$id; if ($clean_urls) $url .= '?'; else $url .= '&'; if ($page) $url .= 'page=' . (int)$page . '&'; return $url; } /** * \brief * Get the ID of the schedule from which this schedule was * derived. */ public function parent_get() { return $this->parent_id; } /** * \brief * A magic function which tries to upgrade old serialized sections * to the new format. */ function __wakeup() { if ($this->nclasses == -1) /* this Schedule doesn't need to be upgraded from Classes to Course */ return; $this->courses = array(); foreach ($this->classStorage as $classes) { $this->courses[] = $classes->to_course(); } $this->nclasses = -1; if (empty($this->parent_id)) $this->parent_id = NULL; } }