From: Maxious Date: Sun, 22 Jan 2012 12:25:46 +0000 Subject: Fix trip/route view now that routeids are back to route numbers X-Git-Url: http://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=239218a5c07ab2ca9b74a59723dd55b02d0c0af6 --- Fix trip/route view now that routeids are back to route numbers --- --- a/include/common-request.inc.php +++ b/include/common-request.inc.php @@ -57,11 +57,14 @@ if (isset($_REQUEST['stopids'])) { $stopids = explode(",", filter_var($_REQUEST['stopids'], FILTER_SANITIZE_STRING)); } -if (isset($_REQUEST['routeids'])) { - $routeids = explode(",", filter_var($_REQUEST['routeids'], FILTER_SANITIZE_STRING)); -} if (isset($_REQUEST['tripid'])) { $tripid = filter_var($_REQUEST['tripid'], FILTER_SANITIZE_STRING); +} +if (isset($_REQUEST['routeid'])) { + $routeid = filter_var($_REQUEST['routeid'], FILTER_SANITIZE_STRING); +} +if (isset($_REQUEST['directionid'])) { + $directionid = filter_var($_REQUEST['directionid'], FILTER_SANITIZE_STRING); } if (isset($_REQUEST['stopid'])) { $stopid = filter_var($_REQUEST['stopid'], FILTER_SANITIZE_NUMBER_INT); --- a/include/common-session.inc.php +++ b/include/common-session.inc.php @@ -61,8 +61,10 @@ } //debug(print_r($_SESSION, true) , "session"); -function current_time() { - return ($_REQUEST['time'] ? $_REQUEST['time'] : date("H:i:s")); +function current_time($time = "") { + if ($_REQUEST['time']) return $_REQUEST['time']; + else if ($time != "") date("H:i:s",$time); + else return date("H:i:s"); } ?> --- a/include/db/route-dao.inc.php +++ b/include/db/route-dao.inc.php @@ -94,30 +94,6 @@ return $query->fetchAll(); } -function getRoutesByNumber($routeNumber = "", $directionID = "",$service_period = "") { - global $conn; - if ($routeNumber != "") { - $query = "Select distinct routes.route_id,routes.route_short_name,routes.route_long_name,service_id from routes join trips on trips.route_id = -routes.route_id join stop_times on stop_times.trip_id = trips.trip_id -where route_short_name = :routeNumber OR route_short_name LIKE :routeNumber2 order by route_short_name;"; - } else { - $query = "SELECT DISTINCT route_short_name from routes order by route_short_name"; - } - debug($query, "database"); - $query = $conn->prepare($query); - if ($routeNumber != "") { - $query->bindParam(":routeNumber", $routeNumber); - $routeNumber2 = "% " . $routeNumber; - $query->bindParam(":routeNumber2", $routeNumber2); - } - $query->execute(); - if (!$query) { - databaseError($conn->errorInfo()); - return Array(); - } - return $query->fetchAll(); -} - function getRoutesByNumberSeries($routeNumberSeries = "") { global $conn; if (strlen($routeNumberSeries) == 1) { @@ -141,16 +117,19 @@ return $query->fetchAll(); } -function getRouteNextTrip($routeID) { +function getRouteNextTrip($routeID, $directionID) { global $conn; $query = "select routes.route_id,direction_id,trips.trip_id,departure_time from routes join trips on trips.route_id = routes.route_id -join stop_times on stop_times.trip_id = trips.trip_id where arrival_time > :currentTime and routes.route_id = :routeID order by +join stop_times on stop_times.trip_id = trips.trip_id where arrival_time between :currentTime and :futureTime +and routes.route_id = :routeID and trips.direction_id = :directionID order by arrival_time limit 1"; debug($query, "database"); $query = $conn->prepare($query); $query->bindParam(":currentTime", current_time()); + $query->bindParam(":futureTime", current_time(strtotime(current_time() ." +2h"))); $query->bindParam(":routeID", $routeID); + $query->bindParam(":directionID", $directionID); $query->execute(); databaseError($conn->errorInfo()); if (!$query) { @@ -158,15 +137,21 @@ return Array(); } $r = $query->fetch(PDO :: FETCH_ASSOC); - - // past last trip of the day special case - if (sizeof($r) < 16) { - $query = "select * from routes join trips on trips.route_id = routes.route_id -join stop_times on stop_times.trip_id = trips.trip_id where routes.route_id = :routeID order by + return $r; +} + +function getRouteFirstTrip($routeID,$directionID) { + global $conn; + + $query = "select * from routes join trips on trips.route_id = routes.route_id +join stop_times on stop_times.trip_id = trips.trip_id where routes.route_id = :routeID +and trips.direction_id = :directionID order by arrival_time DESC limit 1"; debug($query, "database"); $query = $conn->prepare($query); $query->bindParam(":routeID", $routeID); + + $query->bindParam(":directionID", $directionID); $query->execute(); if (!$query) { databaseError($conn->errorInfo()); @@ -174,12 +159,11 @@ } $r = $query->fetch(PDO :: FETCH_ASSOC); - } - return $r; -} - -function getRouteAtStop($routeID, $stop_id) { - $nextTrip = getRouteNextTrip($routeID); + return $r; +} + +function getRouteAtStop($routeID, $directionID, $stop_id) { + $nextTrip = getRouteNextTrip($routeID, $directionID); if ($nextTrip['trip_id']) { foreach (getTripStopTimes($nextTrip['trip_id']) as $tripStop) { if ($tripStop['stop_id'] == $stop_id) @@ -189,7 +173,7 @@ return Array(); } -function getRoutesTrips($routeIDs, $directionID = "", $service_period = "") { +function getRouteTrips($routeID, $directionID = "", $service_period = "") { global $conn; if ($service_period == "") $service_period = service_period(); @@ -201,12 +185,11 @@ $directionSQL = " and direction_id = :directionID "; $query = "select routes.route_id,trips.trip_id,service_id,arrival_time, stop_id, stop_sequence from routes join trips on trips.route_id = routes.route_id join stop_times on stop_times.trip_id = trips.trip_id where (service_id=:service_periodA OR service_id=:service_periodB) -AND (routes.route_id = :routeIDA OR routes.route_id = :routeIDB) " . $directionSQL . " and stop_sequence = '1' order by +AND (routes.route_id = :routeID) " . $directionSQL . " and stop_sequence = '1' order by arrival_time "; debug($query, "database"); $query = $conn->prepare($query); - $query->bindParam(":routeIDA", $routeIDs[0]); - $query->bindParam(":routeIDB", $routeIDs[1]); + $query->bindParam(":routeID", $routeID); $query->bindParam(":service_periodA", $sidA); $query->bindParam(":service_periodB", $sidB); if ($directionSQL != "") --- a/index.php +++ b/index.php @@ -37,13 +37,9 @@
  • Routes By Suburb
  • Nearby Routes
  • + Busness R&D + MyWay Balance and Timeliness Survey Results Busness R&D'; - echo ' MyWay Balance and Timeliness Survey Results'; - include_footer(true) ?> --- a/routeList.php +++ b/routeList.php @@ -37,34 +37,18 @@ $filteredRoutes = Array(); foreach ($routes as $route) { foreach (getRouteHeadsigns($route['route_id']) as $headsign) { - $start = $headsign['stop_name']; - $serviceday = service_period_day($headsign['service_id']); - $key = $route['route_short_name'] . "." . $headsign['direction_id']; - if (isset($filteredRoutes[$key])) { - $filteredRoutes[$key]['route_ids'][] = $route['route_id']; - $filteredRoutes[$key]['route_ids'] = array_unique($filteredRoutes[$key]['route_ids']); - } else { - $filteredRoutes[$key]['route_short_name'] = $route['route_short_name']; - $filteredRoutes[$key]['route_long_name'] = "starting at " . $start; - $filteredRoutes[$key]['service_id'] = $serviceday; - $filteredRoutes[$key]['trip_headsign'] = $headsign['trip_headsign'].(strstr($headsign['trip_headsign'], "bound") ===false ?"bound":""); - $filteredRoutes[$key]['direction_id'] = $headsign['direction_id']; - if (isset($nearby)) { - $filteredRoutes[$key]['distance'] = $route['distance']; - } - } - } - } - foreach ($filteredRoutes as $key => $route) { - echo '
  • ' . $route['route_short_name'] . "

    + + //print_r($route); + echo '
  • ' . $route['route_short_name'] . "

    -

    " . $route['trip_headsign'].", ". $route['route_long_name'] . " (" . ucwords($route['service_id']) . ")

    "; +

    " . $headsign['trip_headsign'].(strstr($headsign['trip_headsign'], "bound") ===false ?"bound":"").", starting at " . $headsign['stop_name'] . " (" . ucwords($headsign['service_id']) . ")

    "; if (isset($nearby)) { - $time = getRouteAtStop($route['route_id'], $route['stop_id']); + $time = getRouteAtStop($route['route_id'], $headsign['direction_id'], $route['stop_id']); echo '' . ($time['arrival_time'] ? $time['arrival_time'] : "No more trips today") . "
    " . floor($route['distance']) . 'm away
    '; } echo"
  • \n"; } +} } if (isset($bysuburbs)) { --- a/trip.php +++ b/trip.php @@ -17,22 +17,16 @@ */ include ('include/common.inc.php'); $routetrips = Array(); -if (isset($routeids) && !isset($tripid)) { - foreach ($routeids as $routeid) { - $possibleTrip = getRouteNextTrip($routeid); - if (!isset($trip) || strtotime($possibleTrip['departure_time']) < strtotime($trip['departure_time'])) { - $trip = getRouteNextTrip($routeid); - } +if (isset($routeid) && !isset($tripid)) { + $trip = getRouteNextTrip($routeid,$directionid); + + if (!($trip)) { + $trip = getRouteFirstTrip($routeid,$directionid); } $tripid = $trip['trip_id']; } else { $trip = getTrip($tripid); - $similarRoutes = getRoutesByNumber($trip['route_short_name'], $trip['direction_id'], strtolower($trip["service_id"])); - $routeids = Array(); - foreach ($similarRoutes as $similarRoute) { - $routeids[] = $similarRoute['route_id']; - } - $routeids = array_unique($routeids); + $routeid = $trip['route_id']; } $directionid = $trip['direction_id']; $service_period = strtolower($trip["service_id"]); @@ -43,49 +37,30 @@ echo 'View Original Timetable/Map'; echo '

    Via:

    ' . viaPointNames($tripid) . ''; echo '

    Other Trips:

    '; -echo "getRoutesTrips(".print_r($routeids,true).", {$trip['direction_id']}, $service_period) $tripid"; -$routeTrips = getRoutesTrips($routeids, $trip['direction_id'], $service_period); +$routeTrips = getRouteTrips($routeid, $trip['direction_id'], $service_period); foreach ($routeTrips as $key => $othertrip) { - // if ($othertrip['trip_id'] != $tripid) { - echo '' . str_replace(" ", ":00", str_replace(":00", " ", $othertrip['arrival_time'])) . ' '; - // } else { - // skip this trip but look forward/back - if ($key - 1 > 0) - $prevTrip = $routeTrips[$key - 1]['trip_id']; - if ($key + 1 < sizeof($routeTrips)) - $nextTrip = $routeTrips[$key + 1]['trip_id']; - // } + // if ($othertrip['trip_id'] != $tripid) { + echo '' . str_replace(" ", ":00", str_replace(":00", " ", $othertrip['arrival_time'])) . ' '; + // } else { + // skip this trip but look forward/back + if ($key - 1 > 0) + $prevTrip = $routeTrips[$key - 1]['trip_id']; + if ($key + 1 < sizeof($routeTrips)) + $nextTrip = $routeTrips[$key + 1]['trip_id']; + // } } flush(); @ob_flush(); echo '

    Other directions/timing periods:

    '; $otherDir = 0; -$filteredRoutes = Array(); -foreach (getRoutesByNumber($trip['route_short_name']) as $row) { - foreach (getRouteHeadsigns($row['route_id']) as $headsign) { - if ( $headsign['direction_id'] != $directionid || strtolower($headsign['service_id']) != $service_period) { - echo "{$headsign['direction_id']} != $directionid || ".strtolower($headsign['service_id'])." != $service_period
    "; - $start = $headsign['stop_name']; + foreach (getRouteHeadsigns($routeid) as $headsign) { + if ($headsign['direction_id'] != $directionid || strtolower($headsign['service_id']) != $service_period) { - $serviceday = strtolower($headsign['service_id']); - $key = $row['route_short_name'] . "." . $headsign['direction_id']; - if (isset($filteredRoutes[$key])) { - $filteredRoutes[$key]['route_ids'][] = $row['route_id']; - $filteredRoutes[$key]['route_ids'] = array_unique($filteredRoutes[$key]['route_ids']); - } else { - $filteredRoutes[$key]['route_short_name'] = $row['route_short_name']; - $filteredRoutes[$key]['route_long_name'] = "Starting at " . $start; - $filteredRoutes[$key]['service_id'] = $serviceday; - $filteredRoutes[$key]['direction_id'] = $headsign['direction_id']; - } + echo ' Starting at ' . $headsign['stop_name'] . ' (' . $headsign['service_id'] . ') '; + $otherDir++; } } -} -foreach ($filteredRoutes as $key => $row) { - echo '' . $row['route_long_name'] . ' (' . ucwords($row['service_id']) . ') '; - $otherDir++; -} if ($otherDir == 0) { echo "None"; @@ -95,9 +70,9 @@ @ob_flush(); echo "
    "; if ($nextTrip) - echo 'Next Trip'; + echo 'Next Trip'; if ($prevTrip) - echo 'Previous Trip'; + echo 'Previous Trip'; echo "
    "; echo '