@@ -143,18 +143,19 @@ function school_cache($schools)
*/
usort($semesters, 'school_cache_semesters_sort');
foreach ($school['crawled_semesters'] as $semester)
{
$semesters[$semester->id()] = array(
'id' => $semester->id(),
'time_start' => $semester->time_start_get(),
'time_end' => $semester->time_end_get(),
'weight' => $semester_weights ++,
'name' => $semester->name_get(),
);
'popular_course_id' => $semester->popular_course_id_get(),
} /* foreach ( => $semester) */
/*
* Store/cache the semester metadata:
$semesters_file = fopen($cache_auto_school_dir_name . '-semesters', 'wb');
fwrite($semesters_file, serialize($semesters));
@@ -77,37 +77,46 @@ class Semester
if (strlen($year) != 4 || !is_numeric($year))
throw new ErrorException('Attempt to construct a Semester with an invalid year. The given year is `' . $year . '\'');
$this->year = $year;
$this->departments = array();
$this->department_names = array();
* For $this->popular_course_get().
$this->course_num_sections_map = array();
}
/**
* \brief
* Add a class to this Semester.
*
* \param $class
* The class/course to add.
public function class_add(Course $class)
public function class_add(Course $course)
$class_parts = Course::parse($class->getName());
if (!isset($class_parts['course']))
throw new ErrorException('I was given a class with an invalid name: `' . $class->getName() . '\'');
$course_parts = Course::parse($course->getName());
if (!isset($course_parts['course']))
throw new ErrorException('I was given a class with an invalid name: `' . $course->getName() . '\'');
foreach ($class as $course_slot)
foreach ($course as $course_slot)
foreach ($course_slot as $section)
foreach ($section as $meeting)
$this->time_set_section_meeting($meeting);
if (!isset($this->departments[$class_parts['department']]))
$this->departments[$class_parts['department']] = array();
$department =& $this->departments[$class_parts['department']];
$this->_section_count($course, $section);
$department[$class_parts['course']] = $class;
if (!isset($this->departments[$course_parts['department']]))
$this->departments[$course_parts['department']] = array();
$department =& $this->departments[$course_parts['department']];
$department[$course_parts['course']] = $course;
* Retrieve a class.
@@ -241,12 +250,14 @@ class Semester
else
$classobj = $this->departments[$dept][$class];
$classobj->section_add($section, $course_slot_id);
$this->_section_count($classobj, $section);
* Add a section_meeting, calling Semester::section_add() as
* necessary.
@@ -296,12 +307,52 @@ class Semester
$section_obj->meeting_add($section_meeting);
return;
* Account for the addition of a new section to this Semester.
* \param $course
* The course this section is a part of.
* \param $section
* The section.
private function _section_count(Course $course, Section $section)
$fully_qualified_course_id = $course->getName();
$this->course_num_sections_map += array($fully_qualified_course_id => 0);
$this->course_num_sections_map[$fully_qualified_course_id] ++;
* Get the most popular course.
* \return
* The fully-qualified course_id of the most popular course in
* this Semester.
public function popular_course_id_get()
if (count($this->course_num_sections_map))
arsort($this->course_num_sections_map, SORT_NUMERIC);
reset($this->course_num_sections_map);
$this->_popular_course = key($this->course_num_sections_map);
if (!isset($this->_popular_course))
/* The default popular course */
$this->_popular_course = 'ENGL-101';
return $this->_popular_course;
* Update the time_end.
* The time_end is a unix timestamp roughly estimating the time at
* which a semester starts. It is used when guessing what semester a
* user is interested in.
@@ -524,8 +575,17 @@ class Semester
* clearing out the pool in the time_ends array.
$this->time_end_get();
$this->time_ends = array();
$this->time_start_get();
$this->time_starts = array();
* A mapping which keeps track of how many sections any given
* course has, with course_id '-' section_id as the key and the
* count as the value. Used to calculate the most frequently-used
* course_id to use as the example course_id (bug #102).
$this->popular_course_id_get();
@@ -111,14 +111,16 @@ elseif (!empty($_REQUEST['e']))
* saved_schedule's school/semester.
$scripts = array('jQuery', 'jQueryUI', 'qTip2', 'schedInput');
$inputPage = page::page_create('Enter Courses', $scripts, $inputPage_options);
$school = $inputPage->get_school();
$semester = $inputPage->semester_get();
if (empty($semesters))
$semesters = school_semesters($school);
$my_hc = 'var slate_permutate_example_course_id = ' . json_encode(school_example_course_id($school)) . ';
$my_hc = 'var slate_permutate_example_course_id = ' . json_encode(empty($semester) || empty($semester['popular_course_id']) ? school_example_course_id($school) : $semester['popular_course_id']) . ';
jQuery(document).ready(
function()
var class_last = 0;
@@ -267,13 +269,13 @@ if (!empty($_REQUEST['selectsemester']))
<?php endif; ?>
<p>
Welcome to SlatePermutate<?php $inputPage->addressStudent(', ', '', FALSE); ?>!
<?php if (school_has_auto($inputPage->get_school())): ?>
To get started, enter in a course identifier (e.g., <em>
<?php echo school_example_course_id($inputPage->get_school()); ?></em>)
<?php echo empty($semester) || empty($semester['popular_course_id']) ? school_example_course_id($inputPage->get_school()) : $semester['popular_course_id']; ?></em>)
and click the autosuggestion to automatically load available sections
for each class.
<?php else: ?>
To get started, enter a course number and add some sections to it.
Then specify each section's letter/number and what times it meets,
add more courses, and click “Find a Schedule”.
Status change: