From: maxious Date: Mon, 14 Nov 2011 08:50:56 +0000 Subject: Correctly identify direction of each trip by it's final stop X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=65c921b5fad1f16bcdfe2eeb382eb738dcaa3af3 --- Correctly identify direction of each trip by it's final stop --- --- a/include/db/trip-dao.inc.php +++ b/include/db/trip-dao.inc.php @@ -120,6 +120,23 @@ return $r['arrival_time']; } +function getTripDestination($tripID) { + global $conn; + $query = "SELECT stops.stop_id, stops.stop_name, stops.stop_desc + from stop_times inner join stops on stop_times.stop_id = stops.stop_id + WHERE trip_id = :tripID order by stop_sequence desc limit 1"; + debug($query, "database"); + $query = $conn->prepare($query); + $query->bindParam(":tripID", $tripID); + $query->execute(); + if (!$query) { + databaseError($conn->errorInfo()); + return Array(); + } + $r = $query->fetch(PDO :: FETCH_ASSOC); + return $r; +} + function getActiveTrips($time) { global $conn; if ($time == "") --- a/labs/stopBrowser.kml.php +++ b/labs/stopBrowser.kml.php @@ -41,7 +41,8 @@ if ($trips) { foreach ($trips as $key => $row) { if ($key < 3) { - $description .= $row['route_short_name'] . ' ' . $row['route_long_name'] . ' @ ' . $row['arrival_time'] . "
"; + $destination = getTripDestination($row['trip_id']); + $description .= $row['route_short_name'] . ' ' . $destination['stop_name'] . ' @ ' . $row['arrival_time'] . "
"; } } } else { --- a/layar_api.php +++ b/layar_api.php @@ -45,7 +45,8 @@ $trips = getStopTripsWithTimes($stop['stop_id'], "", "", "", 3); foreach ($trips as $key => $row) { if ($key < 3) { - $hotspot['line' . strval($key + 2)] = $row['route_short_name'] . ' ' . $row['route_long_name'] . ' @ ' . $row['arrival_time']; + $destination = getTripDestination($row['trip_id']); + $hotspot['line' . strval($key + 2)] = $row['route_short_name'] . ' ' . $destination['stop_name'] . ' @ ' . $row['arrival_time']; } } if (sizeof($trips) == 0) --- a/stop.php +++ b/stop.php @@ -133,7 +133,9 @@ } else { foreach ($trips as $trip) { echo '
  • '; - echo '

    ' . $trip['route_short_name'] . " " . $trip['route_long_name'] . "

    "; + + $destination = getTripDestination($trip['trip_id']); + echo '

    ' . $trip['route_short_name'] . " " . $destination['stop_name'] . "

    "; $viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']); if ($viaPoints != "") echo '
    Via: ' . $viaPoints . ''; --- a/trip.php +++ b/trip.php @@ -24,8 +24,10 @@ $trip = getTrip($tripid); $routeid = $trip["route_id"]; } -include_header("Stops on " . $trip['route_short_name'] . ' ' . $trip['route_long_name'], "trip"); -trackEvent("Route/Trip View", "View Route", $trip['route_short_name'] . ' ' . $trip['route_long_name'], $routeid); + + $destination = getTripDestination($trip['trip_id']); +include_header("Stops on " . $trip['route_short_name'] . ' ' . $destination['stop_name'], "trip"); +trackEvent("Route/Trip View", "View Route", $trip['route_short_name'] . ' ' . $destination['stop_name'], $routeid); echo ''; echo '
    View Original Timetable/Map'; echo '

    Via:

    ' . viaPointNames($tripid) . ''; @@ -66,7 +68,7 @@ echo '