From: Maxious Date: Thu, 10 Nov 2011 11:10:19 +0000 Subject: Fix stops by suburb X-Git-Url: http://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=f4086bf01b23076b7854e8b3841ce2dbac35a7ab --- Fix stops by suburb --- --- a/include/common-db.inc.php +++ b/include/common-db.inc.php @@ -15,7 +15,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -if (php_uname('n') == "actbus-www") { +if (strstr(php_uname('n'),"actbus")) { $conn = new PDO("pgsql:dbname=transitdata;user=transitdata;password=transitdata;host=bus-main.lambdacomplex.org"); } else if (isDebugServer()) { $conn = new PDO("pgsql:dbname=transitdata;user=postgres;password=snmc;host=localhost"); --- 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/common.inc.php +++ b/include/common.inc.php @@ -31,7 +31,7 @@ $cloudmadeAPIkey = "daa03470bb8740298d4b10e3f03d63e6"; $googleMapsAPIkey = "ABQIAAAA95XYXN0cki3Yj_Sb71CFvBTPaLd08ONybQDjcH_VdYtHHLgZvRTw2INzI_m17_IoOUqH3RNNmlTk1Q"; $otpAPIurl = 'http://localhost:8080/opentripplanner-api-webapp/'; -if (isDebug("awsotp") || php_uname('n') == "maxious.xen.prgmr.com") { +if (isDebug("awsotp") || php_uname('n') == "maxious.xen.prgmr.com" || strstr(php_uname('n'),"actbus")) { $otpAPIurl = 'http://bus-main.lambdacomplex.org:8080/opentripplanner-api-webapp/'; } if (isDebug("dotcloudotp") || php_uname('n') == "actbus-www") { @@ -56,7 +56,7 @@ function isDebugServer() { - return php_sapi_name() == "cli" || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "azusa" || $_SERVER['SERVER_NAME'] == "vanille" + return php_sapi_name() == "cli" || strstr(php_uname('n'),"actbus") || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "azusa" || $_SERVER['SERVER_NAME'] == "vanille" || $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1" || $_SERVER['SERVER_NAME'] == "192.168.1.8"); } --- a/include/db/stop-dao.inc.php +++ b/include/db/stop-dao.inc.php @@ -101,10 +101,10 @@ function getStopsBySuburb($suburb) { global $conn; - $query = "Select * from stops where zone_id LIKE :suburb order by stop_name;"; - debug($query, "database"); - $query = $conn->prepare($query); - $suburb = "%" . $suburb . ";%"; + $query = "Select * from stops where stop_desc LIKE :suburb order by stop_name;"; + debug($query, "database"); + $query = $conn->prepare($query); + $suburb = "%
Suburb: %" . $suburb . "%"; $query->bindParam(":suburb", $suburb); $query->execute(); if (!$query) { --- 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']