Changeset - 758f11033eb1
[Not reviewed]
default
0 1 0
Nathan Brink (binki) - 14 years ago 2011-04-10 00:34:54
ohnobinki@ohnopublishing.net
When crawling, use `course' instead of `class' in the JSON output.
1 file changed with 7 insertions and 2 deletions:
0 comments (0 inline, 0 general)
inc/class.course.inc
Show inline comments
 
@@ -198,25 +198,25 @@ class Course implements IteratorAggregat
 
   *   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(array $recursion_trace = array())
 
  {
 
    if (!empty($recursion_trace[$this->getName()]))
 
      return NULL;
 
    $recursion_trace[$this->getName()] = TRUE;
 

	
 
    $json_array = array(
 
			'class' => $this->getName(),
 
			'course' => $this->getName(),
 
			'title' => $this->title_get(),
 
			'sections' => array(),
 
			'dependencies' => array(),
 
			);
 
    foreach ($this->sections as $section)
 
      {
 
	$section_json_arrays = $section->to_json_arrays();
 
	foreach ($section_json_arrays as $section_json_array)
 
	  $json_array['sections'][] = $section_json_array;
 
      }
 

	
 
    foreach ($this->dependencies as $dependency)
 
@@ -235,25 +235,30 @@ class Course implements IteratorAggregat
 
   *   the output of Course::to_json_array().
 
   *
 
   * \param $json
 
   *   The JSON array to parse.
 
   * \return
 
   *   A Course.
 
   */
 
  public static function from_json_array($json)
 
  {
 
    $title = NULL;
 
    if (!empty($json['title']))
 
      $title = $json['title'];
 
    $course = new Course($json['class'], $title);
 
    if (!empty($json['class']))
 
      {
 
	$json['course'] = $json['class'];
 
	unset($json['class']);
 
      }
 
    $course = new Course($json['course'], $title);
 

	
 
    if (!empty($json['sections']))
 
      $course->section_add(Section::from_json_arrays($json['sections']));
 
    
 
    if (!empty($json['dependencies']))
 
      foreach ($json['dependencies'] as $dependency)
 
	$course->dependency_add(Course::from_json_array($dependency));
 

	
 
    return $course;
 
  }
 

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