Example #1
0
 static function IsShowingCurrentServicePeriod($date = false)
 {
     $requested = Page::GetRequestedServicePeriod($date);
     $current = ServicePeriod::GetServicePeriod();
     if (empty($requested) || empty($current)) {
         return false;
     } else {
         return Page::GetRequestedServicePeriod($date)->GetID() == ServicePeriod::GetServicePeriod()->GetID();
     }
 }
Example #2
0
 static function GetTrips($routes, $stops, $direction, $numberOfTrips = false, $startTime = false, $endTime = false)
 {
     // TODO: handling of $endTime in different service period than $startTime
     // TODO: actually decide /how/ before implementing...
     global $Database;
     if (is_array($routes) === false) {
         $routes = array($routes);
     }
     if (is_array($stops) === false) {
         $stops = array($stops);
     }
     if ($numberOfTrips !== false && is_int($numberOfTrips) === false) {
         throw new InvalidArgumentException('$numberOfTrips must be false or an integer');
     }
     if ($startTime !== false && is_numeric($startTime) === false) {
         throw new InvalidArgumentException('$startTime must be false or an integer, value provided: ' . $startTime);
     }
     if ($endTime !== false && is_int($endTime) === false) {
         throw new InvalidArgumentException('$endTime must be false or an integer, value provided: ' . $endTime);
     }
     $query = 'SELECT *, Trip.id AS id FROM Trip INNER JOIN StopTime ON (StopTime.trip_id = Trip.id) ' . ' INNER JOIN Stop ON (StopTime.stop_id = Stop.code) ' . ' INNER JOIN Service ON (Trip.service_id = Service.id) ' . ' INNER JOIN Route ON (Trip.route_id = Route.id) ' . ' WHERE Trip.direction = ? ';
     $sql_params[] = $direction;
     foreach ($routes as $route) {
         $sql_route_param_placeholders[] = '?';
         if (is_int($route) === true) {
             $sql_params[] = $route;
         } else {
             if (get_clasS($route) === "Route") {
                 $sql_params[] = $route->GetID();
             } else {
                 throw new InvalidArgumentException('Invalid argument in $routes: ' . $route);
             }
         }
     }
     $query .= ' AND Route.id IN (' . implode(',', $sql_route_param_placeholders) . ') ';
     foreach ($stops as $stop) {
         $sql_stop_param_placeholders[] = '?';
         if (is_int($stop) === true) {
             $sql_params[] = $stop;
         } else {
             if (get_clasS($stop) === "Stop") {
                 $sql_params[] = $stop->GetID();
             } else {
                 throw new InvalidArgumentException('Invalid argument in $stops: ' . $stop);
             }
         }
     }
     $query .= ' AND Stop.code IN (' . implode(',', $sql_stop_param_placeholders) . ') ';
     //		$servicePeriod = ServicePeriod::GetServicePeriod($startTime);
     //		if ($servicePeriod !== false)
     //		{
     $query .= ' AND Service.id = ? ';
     $sql_params[] = Page::GetRequestedServicePeriod()->GetID();
     //			if (empty($_GET['serviceperiod']) === false)
     //			{
     //				$sql_params[] = ((int) $_GET['serviceperiod']);
     //			}
     //			else
     //			{
     //				$sql_params[] = $servicePeriod->GetID();
     //			}
     //		}
     if ($startTime !== false) {
         $query .= ' AND StopTime.time > ? ';
         $sql_params[] = date('H:i:s', $startTime);
     }
     $query .= ' GROUP BY Trip.id ORDER BY StopTime.time ASC ';
     if ($numberOfTrips !== false) {
         $query .= ' LIMIT ?';
         $sql_params[] = $numberOfTrips;
     }
     $res = $Database->Select($query, $sql_params);
     // if we don't have enough trips, try to select the first few from next service period
     //if ($numberOfTrips !== false)
     if (false) {
         if (count($res) < $numberOfTrips) {
             $i = count($sql_params);
             $sql_params[$i - 1] = $numberOfTrips - count($res);
             if ($startTime !== false) {
                 $sql_params[$i - 2] = '00:00:00';
                 $spParamIndex = $i - 3;
             } else {
                 $spParamIndex = $i - 2;
             }
             $sp = Page::GetRequestedServicePeriod();
             if ($sp !== false) {
                 $sql_params[$spParamIndex] = $sp->NextID();
             }
             $extraRes = $Database->Select($query, $sql_params);
             if (count($extraRes) > 0) {
                 $res = array_merge($res, $extraRes);
             }
         }
     }
     if (count($res) > 0) {
         foreach ($res as $tripdata) {
             $trips[] = new Trip($tripdata);
         }
     } else {
         $trips = array();
     }
     return $trips;
 }
Example #3
0
$inbound_trips = Trip::GetTrips($routes, $inbound_stops, '0', $limit, $time);
$inbound_times = Trip::GetStopTimesForTrips($inbound_trips, $inbound_stops);
uasort($inbound_times, 'TripTimeComparer');
// TODO: when we are displaying a day's last trip + some morning trips, we want to treat the 24:48:00 differently than we
// treat a day's list with the last trip wrapping over. Currently the last trip(s) are sorting to the end, which is highly
// undesired. We do however need the sort for merging the two routes' schedules during weekdays.
// Some thoughts: 1) other than the route merge, sorting seems to be handled by the database. This may however be implicit
// by trip_id, which is not the safest. See if we can sort in SQL. (Still a problem since evening+morning come from two separate
// SQL queries, but we can just sort inside GetTrips in that case.) 2) if not, incorporate some sort of day/timestamp identity
// to each stoptime returned. This is somewhat absurd, as we'd probably need full timestamp to avoid problems wrapping
// over ends of service periods, months, years, etc.
// Currently leaving unsolved -- ~qviri, 2009.02.22
$outbound_trips = Trip::GetTrips($routes, $outbound_stops, '1', $limit, $time);
$outbound_times = Trip::GetStopTimesForTrips($outbound_trips, $outbound_stops);
uasort($outbound_times, 'TripTimeComparer');
$schedule = Page::GetRequestedServicePeriod($time);
echo '<p style="margin-bottom: -1.5em;">viewing ';
if (Page::IsShowingFullSchedule() === false) {
    echo $schedule->name . ' schedule upcoming trips';
    echo ' &#183; view full schedule: ';
    // TODO: there is a GetAllServicePeriods() but it also includes 'All week' and foreach leaves dangling commas... meh
    echo ' <a href="?serviceperiod=2">weekday</a>, ';
    echo ' <a href="?serviceperiod=3">Saturday</a>, ';
    echo ' <a href="?serviceperiod=4">Sunday</a>';
} else {
    echo 'full ' . $schedule->name . ' schedule';
    echo ' &#183; <a href="/keats/">view upcoming trips</a>';
}
echo '</p>' . "\n\n";
echo '<h2>to universities</h2>';
PrintStopList($inbound_stops, $inbound_times);