From: Maxious Date: Thu, 10 Nov 2011 11:05:22 +0000 Subject: Restrict displayed via points to shops/schools etc. X-Git-Url: http://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=c93d5b250c082aec0baf77ffa4db0d64e524e633 --- Restrict displayed via points to shops/schools etc. --- --- a/include/common-request.inc.php +++ b/include/common-request.inc.php @@ -58,7 +58,7 @@ $stopids = explode(",", filter_var($_REQUEST['stopids'], FILTER_SANITIZE_STRING)); } if (isset($_REQUEST['tripid'])) { - $tripid = filter_var($_REQUEST['tripid'], FILTER_SANITIZE_NUMBER_INT); + $tripid = filter_var($_REQUEST['tripid'], FILTER_SANITIZE_STRING); } if (isset($_REQUEST['stopid'])) { $stopid = filter_var($_REQUEST['stopid'], FILTER_SANITIZE_NUMBER_INT); --- a/include/common-template.inc.php +++ b/include/common-template.inc.php @@ -241,5 +241,36 @@ } } +//stop list collapsing +function stopCompare($stopName) { + return substr(trim(preg_replace("/\(Platform.*/", "", $stopName)),0,9); +} +function stopGroupTitle($stopName,$stopdesc) { + if (preg_match("/Dr |Cct |Cir |Av |St |Cr |Parade |Way |Bank /",$stopName)) { + $descParts = explode("
",$stopdesc); + return trim(str_replace("Street: ","",$descParts[0])); + } else { + return trim(preg_replace("/\(Platform.*/", "",$stopName)); + } +} + +function viaPointNames($tripid, $stop_sequence = "") { + $viaPointNames = Array(); + foreach (viaPoints($tripid, $stop_sequence) as $point) { + if (strstr($point['stop_name'], "Station") + || strstr($point['stop_name'], "Shops") + || strstr($point['stop_name'], "CIT") + || strstr($point['stop_name'], "School") + || strstr($point['stop_name'], "University") + ) { + $viaPointNames[] = $point['stop_name']; + } + } + if (sizeof($viaPointNames) > 0) { + return r_implode(", ", $viaPointNames); + } else { + return ""; + } +} ?> --- a/include/db/trip-dao.inc.php +++ b/include/db/trip-dao.inc.php @@ -28,6 +28,7 @@ $query->execute(); if (!$query) { databaseError($conn->errorInfo()); + return Array(); } return $query->fetch(PDO :: FETCH_ASSOC); @@ -56,7 +57,8 @@ function getTripStopTimes($tripID) { global $conn; - $query = "SELECT stop_times.trip_id,trip_headsign,arrival_time,stop_times.stop_id,stop_lat,stop_lon,stop_name,stop_code, + $query = "SELECT stop_times.trip_id,trip_headsign,arrival_time,stop_times.stop_id + ,stop_lat,stop_lon,stop_name,stop_desc,stop_code, stop_sequence,service_id,trips.route_id,route_short_name,route_long_name FROM stop_times join trips on trips.trip_id = stop_times.trip_id @@ -83,6 +85,7 @@ } return Array(); } + function getTripStartTime($tripID) { global $conn; $query = "Select * from stop_times @@ -154,16 +157,5 @@ return $query->fetchAll(); } -function viaPointNames($tripid, $stop_sequence = "") { - $viaPointNames = Array(); - foreach (viaPoints($tripid, $stop_sequence) as $point) { - $viaPointNames[] = $point['stop_name']; - } - if (sizeof($viaPointNames) > 0) { - return r_implode(", ", $viaPointNames); - } else { - return ""; - } -} ?> --- a/stopList.php +++ b/stopList.php @@ -17,17 +17,7 @@ */ include ('include/common.inc.php'); $stops = Array(); -function stopCompare($stopName) { - return substr(trim(preg_replace("/\(Platform.*/", "", $stopName)),0,9); -} -function stopGroupTitle($stopName,$stopdesc) { - if (preg_match("/Dr |Cct |Cir |Av |St |Cr |Parade |Way |Bank /",$stopName)) { - $descParts = explode("
",$stopdesc); - return trim(str_replace("Street: ","",$descParts[0])); - } else { - return trim(preg_replace("/\(Platform.*/", "",$stopName)); - } -} + function navbar() { echo '
@@ -149,7 +139,7 @@ } else { // subsequent duplicates $stopsGrouped["stop_ids"][] = $stop['stop_id']; - ; + } } } --- a/trip.php +++ b/trip.php @@ -24,7 +24,6 @@ $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); echo ''; @@ -69,9 +68,9 @@ $tripStopTimes = getTripStopTimes($tripid); echo '
  • ' . $tripStopTimes[0]['arrival_time'] . ' to ' . $tripStopTimes[sizeof($tripStopTimes) - 1]['arrival_time'] . ' ' . $trip['route_long_name'] . ' (' . ucwords($tripStopTimes[0]['service_id']) . ')
  • '; foreach ($tripStopTimes as $key => $tripStopTime) { - if ($key + 1 > sizeof($tripStopTimes) || ($tripStopTimes[$key]["stop_name"] != $tripStopTimes[$key + 1]["stop_name"])) { + if ($key + 1 > sizeof($tripStopTimes) || stopCompare($tripStopTimes[$key]["stop_name"]) != stopCompare($tripStopTimes[$key + 1]["stop_name"])) { echo '
  • '; - + if (sizeof($stopsGrouped) > 0) { // print and empty grouped stops // subsequent duplicates @@ -83,7 +82,8 @@ echo '
    ' . distance($tripStopTime['stop_lat'], $tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away'; } echo '

    '; - echo $tripStopTime["stop_name"]; + echo stopGroupTitle($tripStopTime['stop_name'],$tripStopTime['stop_desc']) . '
    ' . sizeof($stopsGrouped["stop_ids"]) . ' stops'; + echo '
  • '; flush(); @ob_flush(); @@ -103,10 +103,10 @@ } } else { // this is a duplicated line item - if ($key - 1 <= 0 || ($tripStopTimes[$key]['stop_name'] != $tripStopTimes[$key - 1]['stop_name'])) { + if ($key - 1 <= 0 || stopCompare($tripStopTimes[$key]['stop_name']) != stopCompare($tripStopTimes[$key - 1]['stop_name'])) { // first duplicate $stopsGrouped = Array( - "name" => $tripStopTime['stop_name'], + "name" => trim(preg_replace("/\(Platform.*/", "", $stop['stop_name'])), "startTime" => $tripStopTime['arrival_time'], "stop_ids" => Array( $tripStopTime['stop_id']