Changeset - 90b29060c93e
[Not reviewed]
default
0 3 0
Nathan Brink (binki) - 15 years ago 2011-02-28 00:42:28
ohnobinki@ohnopublishing.net
Support a sort of course-level interdepdendencies packaged with support for automatically adding labs associated with Calvin courses. Closer to solving bug 50, at least the Calvin half of that bug ;-).
3 files changed with 77 insertions and 4 deletions:
0 comments (0 inline, 0 general)
inc/class.course.inc
Show inline comments
 
@@ -31,7 +31,14 @@ class Course
 
  private $name;	// String
 
  private $sections;	// Array of sections
 
  private $nsections;	// int
 
    
 
  /**
 
   * \brief
 
   *   Other courses that this course depends on.
 
   *
 
   * Example: Many calvin courses depend on lab courses.
 
   */
 
  private $dependencies;
 

	
 
  /**
 
   * \brief
 
   *    Creates a class with the given name.
 
@@ -43,6 +50,7 @@ class Course
 
    $this->sections = array();
 
    $this->name = $n;
 
    $this->nsections = 0;
 
    $this->dependencies = array();
 
  }
 
	
 
  /**
 
@@ -111,6 +119,18 @@ class Course
 

	
 
  /**
 
   * \brief
 
   *   Add a dependency on another course.
 
   *
 
   * \param $course
 
   *   The other course to depend on.
 
   */
 
  public function dependency_add(Course $course)
 
  {
 
    $this->dependencies[] = $course;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Split up a user-friendly course specification into components.
 
   *
 
   * This will only return the 'department' and 'course' components of
 
@@ -148,11 +168,21 @@ class Course
 
  /**
 
   * \brief
 
   *   Represent this class as an array of sections ready to be JSONized.
 
   *
 
   * \param $recursion_trace
 
   *   Only for internal use. Used to prevent infinite recursion.
 
   */
 
  public function to_json_array()
 
  public function to_json_array(array $recursion_trace = array())
 
  {
 
    $json_array = array('class' => $this->getName(),
 
			'sections' => array());
 
    if (!empty($recursion_trace[$this->getName()]))
 
      return NULL;
 
    $recursion_trace[$this->getName()] = TRUE;
 

	
 
    $json_array = array(
 
			'class' => $this->getName(),
 
			'sections' => array(),
 
			'dependencies' => array(),
 
			);
 
    foreach ($this->sections as $section)
 
      {
 
	$section_json_arrays = $section->to_json_arrays();
 
@@ -160,6 +190,23 @@ class Course
 
	  $json_array['sections'][] = $section_json_array;
 
      }
 

	
 
    foreach ($this->dependencies as $dependency)
 
      {
 
	$dependency_json = $dependency->to_json_array($recursion_trace);
 
	if (!empty($dependency_json))
 
	  $json_array['dependencies'][] = $dependency_json;
 
      }
 

	
 
    return $json_array;
 
  }
 

	
 
  /**
 
   * \brief
 
   *   Upgrade a course class to a newer version of that class.
 
   */
 
  public function __wakeup()
 
  {
 
    if (!isset($this->dependencies))
 
      $this->dependencies = array();
 
  }
 
}
school.d/calvin.crawl.inc
Show inline comments
 
@@ -394,6 +394,22 @@ function calvin_crawl(array &$semesters,
 
    $semester->time_end_set($semester_end_max);
 
    $semester->time_start_set($semester_start_min);
 

	
 
    /*
 
     * Calculate lab-based course dependencies.
 
     */
 
    foreach ($semester->departments_get() as $department)
 
      foreach ($semester->department_classes_get($department) as $course)
 
        {
 
	  $the_course = $semester->class_get($department, $course);
 
	  $lab_course = $semester->class_get($department, $course . 'L');
 
	  if (!empty($lab_course))
 
	    {
 
	      $the_course->dependency_add($lab_course);
 
	      school_crawl_logf($school_crawl_log, 8, "Adding dependency of %s-%s for %s-%s.",
 
				$department, $course . 'L', $department, $course);
 
	    }
 
	}
 

	
 
    $semesters[] = $semester;
 

	
 
    school_crawl_logf($school_crawl_log, 6, "");
scripts/scheduleInput.js
Show inline comments
 
@@ -276,6 +276,16 @@ function add_sections(cnum, data)
 
	    section = data.sections[i];
 
	    add_section_n(cnum, section.section, section.synonym, section.time_start, section.time_end, section.days, section.prof, section.location, section.type);
 
	}
 

	
 
    /*
 
     * Handle course-level interdependencies.
 
     */
 
    if (data.dependencies)
 
	jQuery.each(data.dependencies, function(i, dep)
 
		    {
 
			var new_course_num = add_class_n(dep.class);
 
			add_sections(new_course_num, dep);
 
		    });
 
}
 

	
 
	//--------------------------------------------------
0 comments (0 inline, 0 general)