From: Maxious Date: Thu, 09 Feb 2012 10:03:29 +0000 Subject: Fix service alert display and include stop/route filters X-Git-Url: https://maxious.lambdacomplex.org/git/?p=busui.git&a=commitdiff&h=3413f1469b64b1ec8fe36aaf9ef35e5fe1b26fe9 --- Fix service alert display and include stop/route filters --- --- a/include/common-template.inc.php +++ b/include/common-template.inc.php @@ -42,7 +42,7 @@ } function include_header($pageTitle, $pageType, $opendiv = true, $geolocate = false, $datepicker = false) { - global $basePath, $GTFSREnabled; + global $basePath, $GTFSREnabled, $stopid, $routeid; echo ' @@ -59,14 +59,13 @@ $jqmcss = $basePath . "css/jquery.mobile-$jqmVersion.css"; $jqjs = $basePath . "js/jquery-1.6.4.min.js"; $jqmjs = $basePath . "js/jquery.mobile-$jqmVersion.js"; - + $jqmcss = $basePath . "css/jquery.mobile-b90eab4935.css"; $jqmjs = $basePath . "js/jquery.mobile-b90eab4935.js"; } else { $jqmcss = "//code.jquery.com/mobile/$jqmVersion/jquery.mobile-$jqmVersion.min.css"; $jqjs = "//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"; $jqmjs = "//code.jquery.com/mobile/$jqmVersion/jquery.mobile-$jqmVersion.min.js"; - } echo ' @@ -108,7 +107,7 @@ }'; echo ''; echo ''; - if (isIOSDevice()){ + if (isIOSDevice()) { echo ' @@ -174,19 +173,38 @@
'; if ($GTFSREnabled) { - $overrides = getServiceOverride(); - if (isset($overrides['service_id'])) { - if ($overrides['service_id'] == "noservice") { - echo '
Buses are not running today due to industrial action/public holiday. See Buses are not running today due to industrial action/public holiday. See http://www.action.act.gov.au for details.
'; - } else { - echo '
Buses are running on an altered timetable today due to industrial action/public holiday. See http://www.action.act.gov.au for details.
'; - } - } - $serviceAlerts = getServiceAlertsAsArray("agency", "0"); + } else { + echo '
Buses are running on an altered timetable today due to industrial action/public holiday. See http://www.action.act.gov.au for details.
'; + } + } + $serviceAlerts = Array(); + $globalAlerts = getServiceAlertsAsArray("agency", "0"); + if ($globalAlerts != nullarray) { + $serviceAlerts = array_merge($serviceAlerts, $globalAlerts); + } + if (isset($stopid)) { + $stopAlerts = getServiceAlertsAsArray("stop", $stopid); + if ($stopAlerts != nullarray) { + $serviceAlerts = array_merge($serviceAlerts, $stopAlerts); + } + } + if (isset($routeid)) { + $routeAlerts = getServiceAlertsAsArray("route", $routeid); + if ($routeAlerts != nullarray) { + $serviceAlerts = array_merge($serviceAlerts, $routeAlerts); + } + } if (isset($serviceAlerts['entity']) && sizeof($serviceAlerts['entity']) > 0) { foreach ($serviceAlerts['entity'] as $entity) { - echo "
" . date("F j, g:i a", strtotime($entity['alert']['active_period'][0]['start'])) . " to " . date("F j, g:i a", strtotime($entity['alert']['active_period'][0]['end'])) . "{$entity['alert']['header_text']['translation'][0]['text']}
Warning: {$entity['alert']['description_text']['translation'][0]['text']} + echo "
{$entity['alert']['header_text']['translation'][0]['text']} " + . date("F jS Y, g:i a", $entity['alert']['active_period'][0]['start']) . " to " + . date("F jS Y, g:i a", $entity['alert']['active_period'][0]['end']) . " +
Warning: {$entity['alert']['description_text']['translation'][0]['text']}
Source
"; } } @@ -212,9 +230,10 @@ } echo "\n
"; } + function timeSettings() { global $service_periods; -echo '
+ echo '

Change Time (' . (isset($_REQUEST['time']) ? $_REQUEST['time'] : "Current Time,") . ' ' . ucwords(service_period()) . ')...

@@ -230,10 +249,10 @@
+ foreach ($service_periods as $service_period) { + echo "'; + } + echo '
@@ -241,8 +260,9 @@
'; } + function placeSettings() { - + $geoerror = false; $geoerror = !isset($_SESSION['lat']) || !isset($_SESSION['lat']) || $_SESSION['lat'] == "" || $_SESSION['lon'] == ""; @@ -275,14 +295,15 @@ //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])); + 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)); + return trim(preg_replace("/\(Platform.*/", "", $stopName)); } } --- a/include/common-transit.inc.php +++ b/include/common-transit.inc.php @@ -149,69 +149,96 @@ street inform: route inform, trip inform, stop inform route patch: trip remove */ - $fm = new transit_realtime\FeedMessage(); - $fh = new transit_realtime\FeedHeader(); - $fh->setGtfsRealtimeVersion(1); - $fh->setTimestamp(time()); - $fm->setHeader($fh); - foreach (getCurrentAlerts() as $alert) { - $fe = new transit_realtime\FeedEntity(); - $fe->setId($alert['id']); - $fe->setIsDeleted(false); - $alert = new transit_realtime\Alert(); - $tr = new transit_realtime\TimeRange(); - $tr->setStart($alert['start']); - $tr->setEnd($alert['end']); - $alert->addActivePeriod($tr); - $informedEntities = getInformedAlerts($alert['id'], $_REQUEST['filter_class'], $_REQUEST['filter_id']); - if (sizeof($informedEntities) > 0) { - $informed = Array(); - $es = new transit_realtime\EntitySelector(); - if ($informedEntity['informed_class'] == "agency") { - $es->setAgencyId($informedEntity['informed_id']); - } - if ($informedEntity['informed_class'] == "stop") { - $es->setStopId($informedEntity['informed_id']); - } - if ($informedEntity['informed_class'] == "route") { - $es->setRouteId($informedEntity['informed_id']); - } - if ($informedEntity['informed_class'] == "trip") { - $td = new transit_realtime\TripDescriptor(); - $td->setTripId($informedEntity['informed_id']); - $es->setTrip($td); - } - $alert->addInformedEntity($es); - } - $alert->setCause(constant("transit_realtime\Alert\Cause::" . $alert['cause'])); - $alert->setEffect(constant("transit_realtime\Alert\Effect::" . $alert['effect'])); - $tsUrl = new transit_realtime\TranslatedString(); - $tUrl = new transit_realtime\TranslatedString\Translation(); - $tUrl->setText($alert['url']); - $tUrl->setLanguage("en"); - $tsUrl->addTranslation($tUrl); - $alert->setUrl($tsUrl); - $tsHeaderText = new transit_realtime\TranslatedString(); - $tHeaderText = new transit_realtime\TranslatedString\Translation(); - $tHeaderText->setText($alert['header']); - $tHeaderText->setLanguage("en"); - $tsHeaderText->addTranslation($tHeaderText); - $alert->setHeaderText($tsHeaderText); - $tsDescriptionText = new transit_realtime\TranslatedString(); - $tDescriptionText = new transit_realtime\TranslatedString\Translation(); - $tDescriptionText->setText($alert['description']); - $tDescriptionText->setLanguage("en"); - $tsDescriptionText->addTranslation($tDescriptionText); - $alert->setDescriptionText($tsDescriptionText); - $fe->setAlert($alert); - $fm->addEntity($fe); + $current_alerts = getCurrentAlerts(); + $informed_count = 0; + if (sizeof($current_alerts) > 0) { + $fm = new transit_realtime\FeedMessage(); + $fh = new transit_realtime\FeedHeader(); + $fh->setGtfsRealtimeVersion(1); + $fh->setTimestamp(time()); + $fm->setHeader($fh); + foreach ($current_alerts as $current_alert) { + $fe = new transit_realtime\FeedEntity(); + $fe->setId($current_alert['id']); + $fe->setIsDeleted(false); + $alert = new transit_realtime\Alert(); + $tr = new transit_realtime\TimeRange(); + $tr->setStart($current_alert['start']); + $tr->setEnd($current_alert['end']); + $alert->addActivePeriod($tr); + $informedEntities = getInformedAlerts($current_alert['id'], $filter_class, $filter_id); + if (sizeof($informedEntities) > 0) { + $informed_count++; + $informed = Array(); + $es = new transit_realtime\EntitySelector(); + if ($informedEntity['informed_class'] == "agency") { + $es->setAgencyId($informedEntity['informed_id']); + } + if ($informedEntity['informed_class'] == "stop") { + $es->setStopId($informedEntity['informed_id']); + } + if ($informedEntity['informed_class'] == "route") { + $es->setRouteId($informedEntity['informed_id']); + } + if ($informedEntity['informed_class'] == "trip") { + $td = new transit_realtime\TripDescriptor(); + $td->setTripId($informedEntity['informed_id']); + $es->setTrip($td); + } + $alert->addInformedEntity($es); + } + if ($current_alert['cause'] != "") { + $alert->setCause(constant("transit_realtime\Alert\Cause::" . $current_alert['cause'])); + } + if ($current_alert['effect'] != "") { + $alert->setEffect(constant("transit_realtime\Alert\Effect::" . $current_alert['effect'])); + } + if ($current_alert['url'] != "") { + $tsUrl = new transit_realtime\TranslatedString(); + $tUrl = new transit_realtime\TranslatedString\Translation(); + $tUrl->setText($current_alert['url']); + $tUrl->setLanguage("en"); + $tsUrl->addTranslation($tUrl); + $alert->setUrl($tsUrl); + } + if ($current_alert['header'] != "") { + $tsHeaderText = new transit_realtime\TranslatedString(); + $tHeaderText = new transit_realtime\TranslatedString\Translation(); + $tHeaderText->setText($current_alert['header']); + $tHeaderText->setLanguage("en"); + $tsHeaderText->addTranslation($tHeaderText); + $alert->setHeaderText($tsHeaderText); + } + if ($current_alert['description'] != "") { + $tsDescriptionText = new transit_realtime\TranslatedString(); + $tDescriptionText = new transit_realtime\TranslatedString\Translation(); + $tDescriptionText->setText($current_alert['description']); + $tDescriptionText->setLanguage("en"); + $tsDescriptionText->addTranslation($tDescriptionText); + $alert->setDescriptionText($tsDescriptionText); + } + $fe->setAlert($alert); + $fm->addEntity($fe); + } + if ($informed_count > 0) { + return $fm; + } else { + return null; + } + } else + return null; + } + + function getServiceAlertsAsArray($filter_class = "", $filter_id = "") { + + $alerts = getServiceAlerts($filter_class, $filter_id); + if ($alerts != null) { + $codec = new DrSlump\Protobuf\Codec\PhpArray(); + + return $codec->encode($alerts); + } else { + return nullarray; } - return $fm; - } - - function getServiceAlertsAsArray($filter_class = "", $filter_id = "") { - $codec = new DrSlump\Protobuf\Codec\PhpArray(); - return $codec->encode(getServiceAlerts($filter_class, $filter_id)); } function getServiceAlertsAsBinary($filter_class = "", $filter_id = "") { --- a/include/db/route-dao.inc.php +++ b/include/db/route-dao.inc.php @@ -97,7 +97,7 @@ function getRoutesByNumberSeries($routeNumberSeries = "") { global $conn; if (strlen($routeNumberSeries) == 1) { - return getRoutesByNumber($routeNumberSeries); + return getRoute($routeNumberSeries); } $seriesMin = substr($routeNumberSeries, 0, -1) . "0"; $seriesMax = substr($routeNumberSeries, 0, -1) . "9"; --- a/servicealerts/servicealert_editor.php +++ b/servicealerts/servicealert_editor.php @@ -30,7 +30,7 @@ if ($_REQUEST['saveedit'] != "") updateServiceAlert($_REQUEST['saveedit'], $_REQUEST['startdate'], $_REQUEST['enddate'], $_REQUEST['header'], $_REQUEST['description'], $_REQUEST['url']); else - addServiceAlert($_REQUEST['startdate'], $_REQUEST['enddate'], $_REQUEST['description'], $_REQUEST['url']); + addServiceAlert($_REQUEST['startdate'], $_REQUEST['enddate'], $_REQUEST['header'], $_REQUEST['description'], $_REQUEST['url']); echo "Saved " . $_REQUEST['saveedit']; die(); } --- a/stop.php +++ b/stop.php @@ -74,10 +74,10 @@ } } if (sizeof($stops) > 0) { -$stopDescParts = explode("
",$stop['stop_desc']); -include_header(trim(str_replace("Street: ","",$stopDescParts[0])), "stop"); + $stopDescParts = explode("
", $stop['stop_desc']); + include_header(trim(str_replace("Street: ", "", $stopDescParts[0])), "stop"); } else { - include_header($stop['stop_name']); + include_header($stop['stop_name'], "stop"); } /* $serviceAlerts = json_decode(getPage(curPageURL() . "/servicealerts_api.php?filter_class=stop&filter_id=".$stopid) , true); @@ -108,15 +108,15 @@ sktimesort($allStopsTrips, "arrival_time", true); $trips = $allStopsTrips; } else { - $trips = getStopTripsWithTimes($stopid,"","","",(isset($filterIncludeRoutes) || isset($filterHasStop)?"75":"")); + $trips = getStopTripsWithTimes($stopid, "", "", "", (isset($filterIncludeRoutes) || isset($filterHasStop) ? "75" : "")); } echo "
"; // if we have too many trips, cut down to size. if (!isset($filterIncludeRoutes) && !isset($filterHasStop) && sizeof($trips) > 10) { - $trips = array_splice($trips, 0,10); + $trips = array_splice($trips, 0, 10); } - + // later/earlier button setup if (sizeof($trips) == 0) { $time = isset($_REQUEST['time']) ? strtotime($_REQUEST['time']) : time(); @@ -142,33 +142,33 @@ } else { foreach ($trips as $trip) { if ( - isset($filterHasStop) && (getTripHasStop($trip['trip_id'],$filterHasStop) == 1) + isset($filterHasStop) && (getTripHasStop($trip['trip_id'], $filterHasStop) == 1) || (isset($filterIncludeRoutes) && in_array($trip["route_short_name"], $filterIncludeRoutes)) || (!isset($filterIncludeRoutes) && !isset($filterHasStop)) - ) { - echo '
  • '; + ) { + echo '
  • '; - $destination = getTripDestination($trip['trip_id']); - echo '

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

    "; - $viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']); - if ($viaPoints != "") - echo '
    Via: ' . $viaPoints . ''; - if (sizeof($tripStopNumbers) > 0) { - echo '
    Boarding At: '; - if (sizeof($tripStopNumbers[$trip['trip_id']]) == sizeof($stopids)) { - echo "All Stops"; - } else { - foreach ($tripStopNumbers[$trip['trip_id']] as $key) { - echo $stopNames[$key] . ', '; + $destination = getTripDestination($trip['trip_id']); + echo '

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

    "; + $viaPoints = viaPointNames($trip['trip_id'], $trip['stop_sequence']); + if ($viaPoints != "") + echo '
    Via: ' . $viaPoints . ''; + if (sizeof($tripStopNumbers) > 0) { + echo '
    Boarding At: '; + if (sizeof($tripStopNumbers[$trip['trip_id']]) == sizeof($stopids)) { + echo "All Stops"; + } else { + foreach ($tripStopNumbers[$trip['trip_id']] as $key) { + echo $stopNames[$key] . ', '; + } } + echo ''; } - echo '
    '; - } - echo '

    '; - echo '

    ' . $trip['arrival_time'] . '

    '; - echo '
  • '; - flush(); - @ob_flush(); + echo '

    '; + echo '

    ' . $trip['arrival_time'] . '

    '; + echo ''; + flush(); + @ob_flush(); } } } --- a/trip.php +++ b/trip.php @@ -31,7 +31,7 @@ $directionid = $trip['direction_id']; $service_period = strtolower($trip["service_id"]); $destination = getTripDestination($trip['trip_id']); -include_header("Stops on " . $trip['route_short_name'] . ' ' . $destination['stop_name'], "trip"); +include_header("Route " . $trip['route_id'] . ' to ' . $destination['stop_name'], "trip"); trackEvent("Route/Trip View", "View Route", $trip['route_short_name'] . ' ' . $destination['stop_name'], $routeid); echo ''; echo 'View Original Timetable/Map ';