diff --git a/inc/class.course.inc b/inc/class.course.inc --- a/inc/class.course.inc +++ b/inc/class.course.inc @@ -29,6 +29,7 @@ include_once 'class.section.php'; class Course implements IteratorAggregate { private $name; // String + private $title; private $sections; // Array of sections private $nsections; // int /** @@ -42,13 +43,18 @@ class Course implements IteratorAggregat /** * \brief * Creates a class with the given name. - * \param $n - * The name of the class. + * \param $course_id + * The identifier of the class. Ex., MATH-101 in + * MATH-101-A. Retrieved with Course::getName(). + * \param $title + * The human-friendly course title, such as 'Introduction to + * Algebra', or NULL. */ - function __construct($n) + function __construct($course_id, $title = NULL) { $this->sections = array(); - $this->name = $n; + $this->name = $course_id; + $this->title = $title; $this->nsections = 0; $this->dependencies = array(); } @@ -128,6 +134,19 @@ class Course implements IteratorAggregat /** * \brief + * Retrieve the human-friendly course title. + * + * \return + * A string, the human-friendly course title, or NULL if there is + * no title. + */ + public function title_get() + { + return $this->title; + } + + /** + * \brief * Add a dependency on another course. * * \param $course @@ -189,6 +208,7 @@ class Course implements IteratorAggregat $json_array = array( 'class' => $this->getName(), + 'title' => $this->title_get(), 'sections' => array(), 'dependencies' => array(), ); @@ -221,7 +241,10 @@ class Course implements IteratorAggregat */ public static function from_json_array($json) { - $course = new Course($json['class']); + $title = NULL; + if (!empty($json['title'])) + $title = $json['title']; + $course = new Course($json['class'], $title); if (!empty($json['sections'])) $course->section_add(Section::from_json_arrays($json['sections'])); @@ -241,5 +264,8 @@ class Course implements IteratorAggregat { if (!isset($this->dependencies)) $this->dependencies = array(); + + if (!isset($this->title)) + $this->title = NULL; } } diff --git a/inc/class.schedule.php b/inc/class.schedule.php --- a/inc/class.schedule.php +++ b/inc/class.schedule.php @@ -100,12 +100,13 @@ class Schedule return $this->scheduleName; } - //-------------------------------------------------- - // Adds a new class to the schedule. - //-------------------------------------------------- - function addCourse($n) + /** + * \brief + * Adds a new class to the schedule. + */ + function addCourse($course_id, $title) { - $this->courses[] = new Course($n); + $this->courses[] = new Course($course_id, $title); } /** @@ -413,6 +414,7 @@ class Schedule '

+ @@ -486,9 +488,9 @@ class Schedule { for($j = 0; $j < count($this->courses); $j++) { - $class = $this->courses[$j]; + $course = $this->courses[$j]; $section_index = $this->storage[$i][$j]; - $section = $class->getSection($section_index); + $section = $course->getSection($section_index); /* iterate through all of a class's meeting times */ $meetings = $section->getMeetings(); @@ -517,12 +519,19 @@ class Schedule if ($rowspan[$dayLoop] > 1) $single_multi = 'multi'; + $title = $course->title_get(); + if (empty($title)) + $title = ''; + else + $title .= ' '; echo ' ' - . htmlentities($class->getName(), ENT_QUOTES) . '-' + . '' . 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" @@ -532,7 +541,7 @@ class Schedule /* for the ``Registration Codes'' dialogue: */ if (empty($permutations_courses[$j])) { - $singleton_course = new Course($course->getName()); + $singleton_course = new Course($course->getName(), $course->title_get()); $singleton_course->section_add($section); $permutation_courses[$j] = $singleton_course->to_json_array(); } @@ -560,8 +569,6 @@ class Schedule echo " \n"; } - /* presort */ - ksort($permutation_courses); // End of table echo " \n" . ' '. htmlentities(json_encode($permutation_courses)) . "\n" diff --git a/input.php b/input.php --- a/input.php +++ b/input.php @@ -71,10 +71,13 @@ elseif ($errors_fix) foreach ($_POST['postData'] as $course) if (is_array($course)) { + $title = ''; + if (!empty($course['title'])) + $title = $course['title']; if (empty($course['name'])) $my_hc .= ' class_last = add_class();' . PHP_EOL; else - $my_hc .= ' class_last = add_class_n(\'' . htmlentities($course['name'], ENT_QUOTES) . '\');' . PHP_EOL; + $my_hc .= ' class_last = add_class_n(\'' . htmlentities($course['name'], ENT_QUOTES) . '\', \'' . htmlentities($title, ENT_QUOTES) . '\');' . PHP_EOL; foreach ($course as $section) if (is_array($section)) $my_hc .= ' add_section_n(class_last, \'' . htmlentities($section['letter'], ENT_QUOTES) . '\', \'' @@ -245,14 +248,18 @@ if (!empty($_REQUEST['selectsemester'])) $inputPage->showSchoolInstructions(); $inputPage->foot(); -function input_class_js(Course $class, $whitespace = ' ') +function input_class_js(Course $course, $whitespace = ' ') { - $js = $whitespace . 'class_last = add_class_n(\'' . htmlentities($class->getName(), ENT_QUOTES) . "');\n"; + $title = $course->title_get(); + if (empty($title)) + $title = ''; + $js = $whitespace . 'class_last = add_class_n(\'' . htmlentities($course->getName(), ENT_QUOTES) . '\', \'' + . htmlentities($title, ENT_QUOTES) . "');\n"; - $nsections = $class->getnsections(); + $nsections = $course->getnsections(); for ($section_key = $nsections - 1; $section_key >= 0; $section_key --) { - $section = $class->getSection($section_key); + $section = $course->getSection($section_key); $meetings = $section->getMeetings(); foreach ($meetings as $meeting) { diff --git a/process.php b/process.php --- a/process.php +++ b/process.php @@ -162,23 +162,26 @@ if(!$DEBUG) $allClasses = new Schedule($name, $parent_schedule_id); $errors = array(); - foreach($_POST['postData'] as $class) - { - /* - * Only add classes if the user added at least one - * section to the class. We know that $class['name'] - * is not a section, so count() needs to be > 1 and - * we need to skip over 'name' in our loop. - */ - if(is_array($class) && count($class) > 1) - { - $allClasses->addCourse($class['name']); - - foreach($class as $section) + foreach($_POST['postData'] as $course) + { + /* + * Only add classes if the user added at least one + * section to the class. We know that $course['name'] + * is not a section, so count() needs to be > 1 and + * we need to skip over 'name' in our loop. + */ + if(is_array($course) && count($course) > 1) + { + if (empty($course['title'])) + $course['title'] = ''; + + $allClasses->addCourse($course['name'], $course['title']); + + foreach($course as $section) /* Skip the section name, which isn't a section */ if(is_array($section)) { - $error_string = $allClasses->addSection($class['name'], $section['letter'], $section['start'], $section['end'], arrayToDays(empty($section['days']) ? array() : $section['days'], 'alpha'), $section['synonym'], $section['professor'], $section['location'], $section['type']); + $error_string = $allClasses->addSection($course['name'], $section['letter'], $section['start'], $section['end'], arrayToDays(empty($section['days']) ? array() : $section['days'], 'alpha'), $section['synonym'], $section['professor'], $section['location'], $section['type']); if ($error_string !== NULL) $errors[] = $error_string; } diff --git a/school.d/umich.crawl.inc b/school.d/umich.crawl.inc --- a/school.d/umich.crawl.inc +++ b/school.d/umich.crawl.inc @@ -20,17 +20,17 @@ /** Filter out whitepace items */ -function umich_arrayfilter_callback($item){ - if(ltrim($item) == ''){ - return false; - } - else{ - return true; - } +function umich_arrayfilter_callback($item) +{ + if(ltrim($item) == '') + return TRUE; + else + return TRUE; } /** Parse html at URL into array, first row is row headers */ -function umich_table_parse($url) { +function umich_table_parse($url) +{ $arr = array(); $dom = new DOMDocument; $html = file_get_contents($url); @@ -64,9 +64,26 @@ function umich_table_parse($url) { return $arr; } -/** Crawls uMich course listings. $season is "f" or "s", year is 2-digit year */ -function umich_crawl($semester) +/** + * \brief + * Crawls University of Michigan's schedule. + * + * \param $semesters + * An array to be filled with semesters. + * \param $school_crawl_log + * The school_crawl_log handle. + * \return + * 1 on failure, 0 on success. + */ +function umich_crawl(array &$semesters, $school_crawl_log) { + $url = 'http://lsa.umich.edu/cg/cg_advsearch.aspx'; + $cookies = array(); + + /* determine list of semesters: */ + $semesters_dom = new DOMDocument(); + $semesters_dom->loadHTML(school_crawl_geturi($url, $cookies, $school_crawl_log)); + $year = substr($semester->year_get(), 2); $season = strtolower(substr($semester->season_get(), 0, 1)); diff --git a/scripts/scheduleInput.js b/scripts/scheduleInput.js --- a/scripts/scheduleInput.js +++ b/scripts/scheduleInput.js @@ -215,6 +215,10 @@ function add_section(cnum) function add_sections(cnum, data) { var i; + + if (data.title) + jQuery('.pclass' + cnum + ' .course-title-entry').val(data.title); + if (!data.sections) return; /* @@ -234,25 +238,33 @@ function add_sections(cnum, data) if (data.dependencies) jQuery.each(data.dependencies, function(i, dep) { - var new_course_num = add_class_n(dep['class']); + var new_course_num = add_class_n(dep['class'], dep['title'] ? dep['title'] : ''); add_sections(new_course_num, dep); }); } - //-------------------------------------------------- - // Adds a new class to the input. - //-------------------------------------------------- - function add_class_n(name) +/** + * \brief + * Adds a new class to the input. + * + * \param course_id + * The course_id. + * \param title + * The human-friendly course title. + * \return + * The javascript-local course entry identifying number. + */ +function add_class_n(course_id, title) { /* * If we're adding a course entry form with preadded * content, first remove the empty course. */ - if (name.length && slate_permutate_course_free != -1) + if (course_id.length && slate_permutate_course_free != -1) course_remove(slate_permutate_course_free); sectionsOfClass[classNum] = 0; // Initialize at 0 - jQuery('#jsrows').append('

'); + jQuery('#jsrows').append('
'); /* store classNum as course_i into the : */ jQuery('#tr-course-' + classNum).data({course_i: classNum}); @@ -343,7 +355,7 @@ function add_class() * one. Otherwise, set this new class to be the ``hot'' one. */ if (slate_permutate_course_free == -1) - slate_permutate_course_free = add_class_n(''); + slate_permutate_course_free = add_class_n('', ''); return slate_permutate_course_free; }