Changeset - 828706182e2f
[Not reviewed]
default
0 6 0
Nathan Brink (binki) - 15 years ago 2011-03-22 22:21:49
ohnobinki@ohnopublishing.net
Add support for entering, storing, and displaying a course title per bug 95.
6 files changed with 126 insertions and 54 deletions:
0 comments (0 inline, 0 general)
inc/class.course.inc
Show inline comments
 
@@ -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;
 
  }
 
}
inc/class.schedule.php
Show inline comments
 
@@ -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
 
               '<div id="show-box" class="show-buttons">
 
                  <form action="#"><p class="nospace">
 
                    <label><strong>Display:</strong></label>
 
                    <input id="show-course-title" name="show-course-title" type="checkbox" /><label for="show-course-title">Course Title</label>
 
                    <input id="show-prof" name="show-prof" type="checkbox" checked="checked" /><label for="show-prof">Professor</label>
 
                    <input id="show-location" name="show-location" type="checkbox" /><label for="show-location">Room</label>
 
                    <input id="show-synonym" name="show-synonym" type="checkbox" /><label for="show-synonym">Synonym</label>
 
@@ -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 '            <td rowspan="' . $rowspan[$dayLoop]
 
					. '" class="' . $single_multi . ' class' . $j
 
					. '" title="prof: ' . htmlentities($section->getProf(), ENT_QUOTES)
 
					. '" title="' . htmlentities($title, ENT_QUOTES)
 
					. 'prof: ' . htmlentities($section->getProf(), ENT_QUOTES)
 
					. ', room: ' . htmlentities($current_meeting->getLocation(), ENT_QUOTES)
 
					. ', type: ' . htmlentities($current_meeting->type_get(), ENT_QUOTES) . '">'
 
					. htmlentities($class->getName(), ENT_QUOTES) . '-'
 
					. '<span class="course-title block">' . htmlentities($title) . '</span>' . PHP_EOL
 
					. htmlentities($course->getName(), ENT_QUOTES) . '-'
 
					. htmlentities($section->getLetter(), ENT_QUOTES) . "\n"
 
					. '<span class="prof block">' . htmlentities($section->getProf(), ENT_QUOTES) . "</span>\n"
 
					. '<span class="location block">' . htmlentities($current_meeting->getLocation(), ENT_QUOTES) . "</span>\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 "          </tr>\n";
 
	      }
 

	
 
	    /* presort */
 
	    ksort($permutation_courses);
 
	    // End of table
 
	    echo "        </table>\n"
 
              . '         <span class="course-data">'.  htmlentities(json_encode($permutation_courses)) . "</span>\n"
input.php
Show inline comments
 
@@ -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)
 
	{
process.php
Show inline comments
 
@@ -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;
 
					  }
school.d/umich.crawl.inc
Show inline comments
 
@@ -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));
 

	
scripts/scheduleInput.js
Show inline comments
 
@@ -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('<tr id="tr-course-' + classNum + '" class="class class' + classNum + ' pclass' + classNum + '"><td class="nameTip"><input type="text" id="input-course-' + classNum + '" class="classRequired defText className'+classNum+' className" title="Class Name" name="postData[' + classNum + '][name]" value="' + name + '" /></td><td colspan="10"></td><td class="tdInput"><div class="deleteClass"><input type="button" value="Remove" class="gray" /></div></td><td class="none"><button type="button" class="addSection gray">+</button></td></tr>');
 
		jQuery('#jsrows').append('<tr id="tr-course-' + classNum + '" class="class class' + classNum + ' pclass' + classNum + '"><td class="nameTip"><input type="text" id="input-course-' + classNum + '" class="classRequired defText className'+classNum+' className" title="Class Name" name="postData[' + classNum + '][name]" value="' + course_id + '" /></td><td colspan="10"><label for="postData[' + classNum + '][title]">Course Title:</label><input type="text" name="postData[' + classNum + '][title]" class="course-title-entry" value="' + title + '" /></td><td class="tdInput"><div class="deleteClass"><input type="button" value="Remove" class="gray" /></div></td><td class="none"><button type="button" class="addSection gray">+</button></td></tr>');
 

	
 
		/* store classNum as course_i into the <tr />: */
 
		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;
 
}
 

	
0 comments (0 inline, 0 general)