diff --git a/class.class.php b/class.class.php --- a/class.class.php +++ b/class.class.php @@ -31,7 +31,17 @@ class Classes $this->sections[$this->nsections] = new Section($l, $p, $s, $e, $d); $this->nsections++; } - + + /** + * \brief + * Adds an already-instantiated section to this class. + */ + public function section_add(Section $section) + { + $this->sections[$this->nsections] = $section; + $this->nsections ++; + } + //-------------------------------------------------- // Returns the number of sections in the class. //-------------------------------------------------- @@ -84,4 +94,55 @@ class Classes return $out; } + + /** + * \brief + * Split up a user-friendly course specification into components. + * + * This will only return the 'department' and 'course' components of + * the given course identifier. Otherwise, it acts the same as + * Section::parse. + * + * \see Section::parse() + * + * \param $course_spec + * A course specifier to parse, such as 'cs262' or 'MATH-156'. + * \return + * An array with normalized output having keys of 'department' and + * 'course'. If the user's input has less than these two keys of + * information, the returned array may have zero or one elements. + */ + public static function parse($course_spec) + { + $section_parts = Section::parse($course_spec); + if (isset($section_parts['section'])) + unset($section_parts['section']); + + return $section_parts; + } + + /** + * \brief + * Represent this class as a string. + */ + public function __toString() + { + return $this->getName(); + } + + /** + * \brief + * Represent this class as an array of sections ready to be JSONized. + */ + public function to_json_array() + { + $json_array = array('class' => $this->getName(), + 'sections' => array()); + foreach ($this->sections as $section) + { + $json_array['sections'][] = $section->to_json_array(); + } + + return $json_array; + } }