Files
        @ 6cb196f112d9
    
        
              Branch filter: 
        
    Location: SlatePermutate/inc/class.semester.inc - annotation
        
            
            6cb196f112d9
            4.5 KiB
            text/x-povray
        
        
    
    A school website-crawling infrastructure. Supports crawling Calvin's website and producing JSON for jqueryui's autocomplete functionality. Also creates a JSON description of the list sections for each course, awaiting JS-support for AJAX section autocreation.
    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176  | 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9 6cb196f112d9  | <?php
/*
 * Copyright 2010 Nathan Phillip Brink <ohnobinki@ohnopublishing.net>
 *
 * This file is a part of slate_permutate.
 *
 * slate_permutate is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * slate_permutate is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with slate_permutate.  If not, see <http://www.gnu.org/licenses/>.
 */
$root_dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR;
require_once($root_dir . 'class.class.php');
require_once($root_dir . 'class.section.php');
/**
 * \brief
 *   Identifies a school semester and acts as a container for courses
 *   offered in a semester.
 */
class Semester
{
  /**
   * \brief
   *   The Fall season.
   */
  const SEASON_FALL = 'fall';
  /**
   * \brief
   *   The Spring season.
   */
  const SEASON_SPRING = 'spring';
  /**
   * \brief
   *   Instantiate an empty Semester.
   *
   * \param $year
   *   The year of this semester. Must be four digits.
   * \param $season
   *   The season of this semester. Currently, only
   *   Semester::SEASON_SPRING and Semester::SEASON_FALL are valid.
   */
  function __construct($year, $season)
  {
    if (!in_array($season, array(self::SEASON_SPRING, self::SEASON_FALL)))
      throw new ErrorException('Attempt to construct a Semester with a $season which is neither Semester::SEASON_SPRING nor Semester::SEASON_FALL. `' . $season . '\' was given.');
    $this->season = $season;
    if (strlen($year) != 4)
      throw new ErrorException('Attempt to construct a Semester with an invalid year. The given year is `' . $year . '\'');
    $this->year = $year;
    $this->departments = array();
  }
  /**
   * \brief
   *   Add a class to this Semester.
   *
   * \param $class
   *   The class/course to add.
   */
  public function class_add(Classes $class)
  {
    $class_parts = Classes::parse($class->getName());
    if (!isset($class_parts['course']))
      throw ErrorException('I was given a class with an invalid name: `' . $class->getName() . '\'');
    if (!isset($this->departments[$class_parts['department']]))
      $this->departments[$class_parts['department']] = array();
    $department =& $this->departments[$class_parts['department']];
    $department[$class_parts['course']] = $class;
  }
  /**
   * \brief
   *   Retrieve a class.
   *
   * \param $dept
   *   The class's department. 'CS' for 'CS-262'.
   * \param $class
   *   The course/class number. '262' for 'cs-262'.
   * \return
   *   A Classes or NULL if not found.
   */
  public function class_get($dept, $class)
  {
    if (!isset($this->departments[$dept][$class]))
      return NULL;
    return $this->departments[$dept][$class];
  }
  /**
   * \brief
   *   Gets a list of departments available in this semester.
   */
  public function departments_get()
  {
    return array_keys($this->departments);
  }
  /**
   * \brief
   *   Gets a list of class/course numbers available for a particular
   *   department.
   */
  public function department_classes_get($dept)
  {
    if (!isset($this->departments[$dept]))
      throw new ErrorException('I was asked for a department I don\'t own: ' . $dept);
    return array_keys($this->departments[$dept]);
  }
  /**
   * \brief
   *   Utility function to add a section to the semester,
   *   automatically creating classes as necessary.
   *
   * \param $dept
   *   The department this section belongs to.
   * \param $class
   *   The class this section belongs to.
   * \param $section
   *   The section itself.
   */
  public function section_add($dept, $class, Section $section)
  {
    $dept = strtoupper($dept);
    $class = strtoupper($class);
    if (!isset($this->departments[$dept])
	|| !isset($this->departments[$dept][$class]))
      {
	$classobj = new Classes($dept . '-' . $class);
	$this->class_add($classobj);
      }
    else
      {
	$classobj = $this->departments[$dept][$class];
      }
    $classobj->section_add($section);
  }
  /**
   * \brief
   *   Get a semester's year.
   */
  public function year_get()
  {
    return $this->year;
  }
  /**
   * \brief
   *   Get a semester's season.
   */
  public function season_get()
  {
    return $this->season;
  }
}
 |