URL parameter to filter stop trips display by route or another stop on the route
--- a/include/common-request.inc.php
+++ b/include/common-request.inc.php
@@ -57,6 +57,12 @@
if (isset($_REQUEST['stopids'])) {
$stopids = explode(",", filter_var($_REQUEST['stopids'], FILTER_SANITIZE_STRING));
}
+if (isset($_REQUEST['filterIncludeRoutes'])) {
+ $filterIncludeRoutes = explode(",", filter_var($_REQUEST['filterIncludeRoutes'], FILTER_SANITIZE_STRING));
+}
+if (isset($_REQUEST['filterHasStop'])) {
+ $filterHasStop = filter_var($_REQUEST['filterHasStop'], FILTER_SANITIZE_STRING);
+}
if (isset($_REQUEST['tripid'])) {
$tripid = filter_var($_REQUEST['tripid'], FILTER_SANITIZE_STRING);
}
--- a/include/db/trip-dao.inc.php
+++ b/include/db/trip-dao.inc.php
@@ -51,6 +51,25 @@
}
return $query->fetchAll();
}
+
+function getTripHasStop($tripID, $stopID) {
+ global $conn;
+ $query = "SELECT stop_id
+FROM stop_times
+join trips on trips.trip_id = stop_times.trip_id
+WHERE trips.trip_id = :tripID and stop_times.stop_id = :stopID";
+ debug($query, "database");
+ $query = $conn->prepare($query);
+ $query->bindParam(":tripID", $tripID);
+ $query->bindParam(":stopID", $stopID);
+ $query->execute();
+ if (!$query) {
+ databaseError($conn->errorInfo());
+ return Array();
+ }
+ return ($query->fetchColumn() > 0);
+}
+
function getTripShape($tripID) {
// todo, use shapes table if shape_id specified
global $conn;
--- a/stop.php
+++ b/stop.php
@@ -108,12 +108,12 @@
sktimesort($allStopsTrips, "arrival_time", true);
$trips = $allStopsTrips;
} else {
- $trips = getStopTripsWithTimes($stopid);
+ $trips = getStopTripsWithTimes($stopid,"","","",(isset($filterIncludeRoutes) || isset($filterHasStop)?"75":""));
}
echo "<div class='ui-header' style='overflow: visible; height: 2.5em'>";
// if we have too many trips, cut down to size.
-if (sizeof($trips) > 10) {
+if (!isset($filterIncludeRoutes) && !isset($filterHasStop) && sizeof($trips) > 10) {
$trips = array_splice($trips, 0,10);
}
@@ -141,6 +141,11 @@
echo "<li style='text-align: center;'>No trips in the near future.</li>";
} else {
foreach ($trips as $trip) {
+ if (
+ isset($filterHasStop) && (getTripHasStop($trip['trip_id'],$filterHasStop) == 1)
+ || (isset($filterIncludeRoutes) && in_array($trip["route_short_name"], $filterIncludeRoutes))
+ || (!isset($filterIncludeRoutes) && !isset($filterHasStop))
+ ) {
echo '<li>';
$destination = getTripDestination($trip['trip_id']);
@@ -164,6 +169,7 @@
echo '</a></li>';
flush();
@ob_flush();
+ }
}
}
echo '</ul>';