Пример #1
0
    $limit = 5;
    // default;
    $time = time();
    // show stuff just passed also just in case it turns out to be useful; 5 minutes
    if (date('H') < 5) {
        $time = mktime(23, 58, 0, date('m'), date('d') - 1, date('Y'));
    }
}
// full lists of stops in both directions
//$inbound_stop_ids = array(3148, 3149, 3150, 3151, 3152, 3153, 3154, 3631, 2780, 2515, 2781, 2782, 2783, 3620, 2785);
//$outbound_stop_ids = array(3621, 3619, 2673, 2674, 2675, 2676, 2515, 2677, 3589, 3155, 3156, 3157, 3158, 3159, 3160, 3161);
// truncated lists, skipping a few
$inbound_stop_ids = array(3148, 3149, 3150, 3151, 3152, 3153, 3154, 2515, 2781, 2782, 3620);
$outbound_stop_ids = array(3619, 2673, 2675, 2676, 2515, 2677, 3155, 3156, 3158, 3159, 3161);
$inbound_stops = Stop::CreateStopsFromList($inbound_stop_ids);
$outbound_stops = Stop::CreateStopsFromList($outbound_stop_ids);
$routes = array(new Route(12), new Route(29));
$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);