Fix stop grouping logic for new GTFS feed
--- a/include/common.inc.php
+++ b/include/common.inc.php
@@ -55,6 +55,7 @@
$basePath = "../";
function isDebugServer() {
+
return php_sapi_name() == "cli" || isset($_SERVER['SERVER_NAME']) && ( $_SERVER['SERVER_NAME'] == "azusa" || $_SERVER['SERVER_NAME'] == "vanille"
|| $_SERVER['SERVER_NAME'] == "localhost" || $_SERVER['SERVER_NAME'] == "127.0.0.1");
}
@@ -71,7 +72,7 @@
function isAnalyticsOn() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
- return!isDebugServer() && !preg_match('/cloudkick/i', $user_agent) && !preg_match('/googlebot/i', $user_agent) &&
+ return !isDebugServer() && !preg_match('/cloudkick/i', $user_agent) && !preg_match('/googlebot/i', $user_agent) &&
!preg_match('/baidu/i', $user_agent);
}
@@ -133,10 +134,6 @@
return (strcmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0);
}
return (strcasecmp(substr($haystack, strlen($haystack) - strlen($needle)), $needle) === 0);
-}
-
-function bracketsMeanNewLine($input) {
- return str_replace(")", "</small>", str_replace("(", "<br><small>", $input));
}
function sksort(&$array, $subkey = "id", $sort_ascending = false) {
@@ -202,5 +199,6 @@
return implode($glue, $retVal);
}
+
?>
--- a/include/db/stop-dao.inc.php
+++ b/include/db/stop-dao.inc.php
@@ -30,11 +30,9 @@
return $query->fetch(PDO :: FETCH_ASSOC);
}
-function getStops($timingPointsOnly = false, $firstLetter = "", $startsWith = "") {
+function getStops($firstLetter = "", $startsWith = "") {
global $conn;
$conditions = Array();
- if ($timingPointsOnly)
- $conditions[] = "substr(stop_code,1,2) != 'Wj'";
if ($firstLetter != "")
$conditions[] = "substr(stop_name,1,1) = :firstLetter";
if ($startsWith != "")
@@ -48,6 +46,7 @@
}
}
$query .= " order by stop_name;";
+ debug($query,"database");
$query = $conn->prepare($query);
if ($firstLetter != "")
$query->bindParam(":firstLetter", $firstLetter);
--- a/include/db/trip-dao.inc.php
+++ b/include/db/trip-dao.inc.php
@@ -222,12 +222,12 @@
return $query->fetchAll();
}
-function viaPoints($tripID, $stop_sequence = "", $timing_points_only = true) {
+function viaPoints($tripID, $stop_sequence = "") {
global $conn;
$query = "SELECT stops.stop_id, stop_name, arrival_time
FROM stop_times join stops on stops.stop_id = stop_times.stop_id
WHERE stop_times.trip_id = :tripID
-" . ($stop_sequence != "" ? " AND stop_sequence > :stop_sequence " : "") . ($timing_points_only ? "AND substr(stop_code,1,2) != 'Wj' " : "") . " ORDER BY stop_sequence";
+" . ($stop_sequence != "" ? " AND stop_sequence > :stop_sequence " : "") ." ORDER BY stop_sequence";
debug($query, "database");
$query = $conn->prepare($query);
if ($stop_sequence != "")
--- a/stop.php
+++ b/stop.php
@@ -43,16 +43,12 @@
}
$stop = $stops[0];
$stopid = $stops[0]["stop_id"];
- $stopLinks.= "Individual stop pages: ";
+ $stopLinks.= "Individual stop pages: <br>";
foreach ($stops as $key => $sub_stop) {
- // $stopNames[$key] = $sub_stop[1] . ' Stop #' . ($key + 1);
- if (strpos($stop["stop_name"], "Station")) {
- $stopNames[$key] = 'Platform ' . ($key + 1);
- $stopLinks.= '<a href="stop.php?stopid=' . $sub_stop["stop_id"] . '&stopcode=' . $sub_stop["stop_code"] . '">' . $sub_stop["stop_name"] . '</a> ';
- } else {
- $stopNames[$key] = '#' . ($key + 1);
- $stopLinks.= '<a href="stop.php?stopid=' . $sub_stop["stop_id"] . '&stopcode=' . $sub_stop["stop_code"] . '">' . $sub_stop["stop_name"] . ' Stop #' . ($key + 1) . '</a> ';
- }
+
+ $stopNames[$key] = $sub_stop["stop_name"];
+ $stopLinks.= '<a href="stop.php?stopid=' . $sub_stop["stop_id"] . '&stopcode=' . $sub_stop["stop_code"] . '">' . $sub_stop["stop_name"] . '</a> ';
+
$stopPositions[$key] = Array(
$sub_stop["stop_lat"],
$sub_stop["stop_lon"]
@@ -143,8 +139,12 @@
echo '<br><span class="viaPoints">Via: ' . $viaPoints . '</span>';
if (sizeof($tripStopNumbers) > 0) {
echo '<br><small>Boarding At: ';
- foreach ($tripStopNumbers[$trip['trip_id']] as $key) {
- echo $stopNames[$key] . ' ';
+ if (sizeof($tripStopNumbers[$trip['trip_id']]) == sizeof($stopids)) {
+ echo "All Stops";
+ } else {
+ foreach ($tripStopNumbers[$trip['trip_id']] as $key) {
+ echo $stopNames[$key] . ', ';
+ }
}
echo '</small>';
}
--- a/stopList.php
+++ b/stopList.php
@@ -17,7 +17,17 @@
*/
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 /",$stopName)) {
+ $descParts = explode("<br>",$stopdesc);
+ return trim(str_replace("Street: ","",$descParts[0]));
+ } else {
+ return trim(preg_replace("/\(Platform.*/", "",$stopName));
+ }
+}
function navbar() {
echo '
<div data-role="navbar">
@@ -52,7 +62,7 @@
// Timing Points / All stops
if (isset($allstops)) {
$listType = 'allstops=yes';
- $stops = getStops();
+ $stops = getStops($firstLetter);
include_header("All Stops", "stopList");
navbar();
} else if (isset($nearby)) {
@@ -99,19 +109,19 @@
//var_dump($stops);
$stopsGrouped = Array();
foreach ($stops as $key => $stop) {
- if ((trim(preg_replace("/\(Platform.*/", "", $stops[$key]["stop_name"])) != trim(preg_replace("/\(Platform.*/", "", $stops[$key + 1]["stop_name"]))) || $key + 1 >= sizeof($stops)) {
+ if (stopCompare($stops[$key]["stop_name"])
+ != stopCompare($stops[$key + 1]["stop_name"])
+ || $key + 1 >= sizeof($stops)) {
if (sizeof($stopsGrouped) > 0) {
// print and empty grouped stops
// subsequent duplicates
$stopsGrouped["stop_ids"][] = $stop['stop_id'];
echo '<li>';
- if (!startsWith($stopsGrouped['stop_codes'][0], "Wj"))
- echo '<img src="css/images/time.png" alt="Timing Point: " class="ui-li-icon">';
echo '<a href="stop.php?stopids=' . implode(",", $stopsGrouped['stop_ids']) . '">';
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) {
echo '<span class="ui-li-count">' . distance($stop['stop_lat'], $stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>';
}
- echo bracketsMeanNewLine(trim(preg_replace("/\(Platform.*/", "", $stop['stop_name'])) . '(' . sizeof($stopsGrouped["stop_ids"]) . ' stops)');
+ echo stopGroupTitle($stop['stop_name'],$stop['stop_desc']) . '<br><small>' . sizeof($stopsGrouped["stop_ids"]) . ' stops</small>';
echo "</a></li>\n";
flush();
@ob_flush();
@@ -119,20 +129,18 @@
} else {
// just a normal stop
echo '<li>';
- if (!startsWith($stop['stop_code'], "Wj"))
- echo '<img src="css/images/time.png" alt="Timing Point" class="ui-li-icon">';
- echo '<a href="stop.php?stopid=' . $stop['stop_id'] . (startsWith($stop['stop_code'], "Wj") ? '&stopcode=' . $stop['stop_code'] : "") . '">';
+ echo '<a href="stop.php?stopid=' . $stop['stop_id'] . '&stopcode=' . $stop['stop_code'] . '">';
if (isset($_SESSION['lat']) && isset($_SESSION['lon'])) {
echo '<span class="ui-li-count">' . distance($stop['stop_lat'], $stop['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away</span>';
}
- echo bracketsMeanNewLine($stop['stop_name']);
+ echo $stop['stop_name'];
echo "</a></li>\n";
flush();
@ob_flush();
}
} else {
// this is a duplicated line item
- if ($key - 1 <= 0 || (trim(preg_replace("/\(Platform.*/", "", $stops[$key]['stop_name'])) != trim(preg_replace("/\(Platform.*/", "", $stops[$key - 1]['stop_name'])))) {
+ if ($key - 1 <= 0 || stopCompare($stops[$key]['stop_name']) != stopCompare($stops[$key - 1]['stop_name'])) {
// first duplicate
$stopsGrouped = Array(
"name" => trim(preg_replace("/\(Platform.*/", "", $stop['stop_name'])),
--- a/trip.php
+++ b/trip.php
@@ -71,8 +71,7 @@
foreach ($tripStopTimes as $key => $tripStopTime) {
if ($key + 1 > sizeof($tripStopTimes) || ($tripStopTimes[$key]["stop_name"] != $tripStopTimes[$key + 1]["stop_name"])) {
echo '<li>';
- if (!startsWith($tripStopTime['stop_code'], "Wj"))
- echo '<img src="css/images/time.png" alt="Timing Point" class="ui-li-icon">';
+
if (sizeof($stopsGrouped) > 0) {
// print and empty grouped stops
// subsequent duplicates
@@ -84,7 +83,7 @@
echo '<br>' . distance($tripStopTime['stop_lat'], $tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away';
}
echo '</p>';
- echo bracketsMeanNewLine($tripStopTime["stop_name"]);
+ echo $tripStopTime["stop_name"];
echo '</a></li>';
flush();
@ob_flush();
@@ -97,7 +96,7 @@
echo '<br>' . distance($tripStopTime['stop_lat'], $tripStopTime['stop_lon'], $_SESSION['lat'], $_SESSION['lon'], true) . 'm away';
}
echo '</p>';
- echo bracketsMeanNewLine($tripStopTime['stop_name']);
+ echo $tripStopTime['stop_name'];
echo '</a></li>';
flush();
@ob_flush();