Files
@ 1cb6f6105b45
Branch filter:
Location: SlatePermutate/inc/class.section_meeting.inc
1cb6f6105b45
6.0 KiB
text/x-povray
Use the Affero General Public License, as agreed upon by Ethan Zonca, Nathan Gelderloos, and Nathan Phillip Brink (myself).
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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | <?php
/*
* Copyright 2010 Nathan Gelderloos, Ethan Zonca, Nathan Phillip Brink
*
* This file is part of SlatePermutate.
*
* SlatePermutate 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.
*
* SlatePermutate 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 SlatePermutate. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \brief
* Represent a time/location that a Section meets during/at.
*
* A Calvin student might ask ``Why is there a need for a
* SectionMeeting class? Doesn't every Section have a unique
* prof/time/location?'' A Cedarville student would retort ``Huh?
* Don't some of your classes have labs in addition to lecture? How do
* you know that you have to go to both a lecture and lab -- and how
* do you handle that some classes have different lecture times for
* different days of the week?''. A Calvin section _is_ a unique
* prof/time/location. At Cedarville, a Section refers to a prof and a
* _set_ of time/location pairs. The generalization is to make each
* Section support a list of meeting times/locations.
*/
class SectionMeeting
{
private $time_start;
private $time_end;
private $days;
private $location;
/**
* \brief
* Construct a SectionMeeting.
*
* \param $days
* A string of single-char day upon which a section meets. Monday
* is represented with 'm', Tuesday with 't', Wednesday with 'w',
* Thursday with 'h', and Friday with 'f'.
* \param $time_start
* The time of day when the section meeting starts.
* \param $time_end
* The time of day when the section meeting ends.
* \param $location
* Where the meeting occurs. Often a room number of some sort.
* \param $type
* The type of meeting this is. For lectures, please use
* 'lecture'. For labs, please use 'lab'. For others, use the
* school's notation.
*/
public function __construct($days, $time_start, $time_end, $location = NULL, $type = 'lecture')
{
$this->days_set($days);
$this->time_start = $time_start;
$this->time_end = $time_end;
$this->location = $location;
$this->type = $type;
}
/**
* \brief
* Take a days of week string and store it into our $days of week array.
*
* \param $days_str
* The days of the week in a string format. One char per
* day. Mon-Fri is represented with 'm', 't', 'w', 'h', 'f'.
*/
private function days_set($days_str)
{
$this->days = array(0 => FALSE, 1 => FALSE, 2 => FALSE, 3 => FALSE, 4 => FALSE);
$days_str_strlen = strlen($days_str);
for ($i = 0; $i < $days_str_strlen; $i ++)
$this->days[self::day_atoi($days_str[$i])] = TRUE;
}
/**
* \brief
* Convert a day letter to a day numeral.
*
* Works fine if you give the numeral as well.
*/
private static function day_atoi($day_c)
{
static $day_atoi = array('m' => 0, 't' => 1, 'w' => 2, 'h' => 3, 'f' => 4,
'M' => 0, 'T' => 1, 'W' => 2, 'H' => 3, 'F' => 4,
0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4);
return $day_atoi[$day_c];
}
/**
* \brief
* Determine whether or not this class meeting time meets on a
* specified day of the week or not.
*
* \param $day
* The letter or numeral of the day to retrieve.
* \return
* TRUE if this section meeting meets on that day. FALSE
* otherwise.
*/
public function getDay($day)
{
return $this->days[self::day_atoi($day)];
}
/**
* \return
* This SectionMeeting's location or NULL if none is defined.
*/
public function getLocation()
{
return $this->location;
}
/**
* \brief
* Get the start_time of this meeting in slate_permutate's internal format.
*/
public function getStartTime()
{
return $this->time_start;
}
public function getEndTime()
{
return $this->time_end;
}
/**
* \brief
* Check if this section conflicts with the given section.
*
* \param $that
* The other section for which I should check for conflicts.
* \return
* TRUE if there is a conflict, FALSE otherwise.
*/
public function conflictsWith(SectionMeeting $that)
{
/*
* The two sections meetings can't conflict if the start/end times
* don't overlap. Also, use >= or <= here so that one can say ``I
* have gym from 10 through 11 and then latin from 11 though 12''.
*/
if ($this->getStartTime() >= $that->getEndTime()
|| $this->getEndTime() <= $that->getStartTime())
{
return FALSE;
}
/*
* Now we know that the sections meetings overlap in start/end
* times. But if they don't both meet on the same day at least
* once, they don't conflict.
*/
for ($day = 0; $day < 5; $day ++)
{
if ($this->getDay($day) && $that->getDay($day))
return TRUE;
}
/*
* The sections meetings don't both share a day of the week.
*/
return FALSE;
}
/**
* \brief
* Return an array of JSON keys specific to this section meeting
* time.
*
* Currently, the AJAX UI doesn't recognize that a given section may
* have multiple meeting times. Thus, we simulate this by having
* multiple instances of the same section but just with different
* times in the UI.
*/
public function to_json_array()
{
static $daymap = array(0 => 'm', 1 => 't', 2 => 'w', 3 => 'h', 4 => 'f');
$json_array = array(
'time_start' => $this->time_start,
'time_end' => $this->time_end,
'days' => array(),
'location' => $this->location,
);
for ($day = 0; $day < 5; $day ++)
$json_array['days'][$daymap[$day]] = $this->getDay($day);
return $json_array;
}
}
|