Include network wide service alerts in page headers
--- a/include/common-template.inc.php
+++ b/include/common-template.inc.php
@@ -156,6 +156,11 @@
echo '<div id="servicewarning">Buses are running on an altered timetable today due to industrial action/public holiday. See <a href="http://www.action.act.gov.au">http://www.action.act.gov.au</a> for details.</div>';
}
}
+ $serviceAlerts = getServiceAlerts("network","network");
+ foreach ($serviceAlerts['entities'] as $entity) {
+ echo "<div id='servicewarning'> From ".date("F j, g:i a",strtotime($entity['alert']['active_period']['start']))." to ". date("F j, g:i a", strtotime($entity['alert']['active_period']['end']))."<br>Warning: {$entity['alert']['description']['translation']}
+ <br><a href='{$entity['alert']['url']['translation']}'>Source</a> </div>";
+ }
}
}
function include_footer()
--- a/include/common-transit.inc.php
+++ b/include/common-transit.inc.php
@@ -45,5 +45,62 @@
return "";
}
}
+function getServiceAlerts($filter_class, $filter_id) {
+/*
+
+ also need last modified epoch of client gtfs
+
+ - add,remove,patch,inform (null)
+ - stop
+ - trip
+ - network
+ - patterns (WHERE=)
+ - route (short_name or route_id)
+ - street
+ - stop
+ - trip */
+$return = Array();
+$return['header']['gtrtfs_version'] = "1";
+$return['header']['timestamp'] = time();
+$return['entities'] = Array();
+foreach(getCurrentAlerts() as $alert) {
+ $informedEntities = getInformedAlerts($alert['id'],$_REQUEST['filter_class'],$_REQUEST['filter_id']);
+ if (sizeof($informedEntities) >0) {
+ $entity = Array();
+ $entity['id'] = $alert['id'];
+ $entity['alert']['active_period']['start'] = $alert['start'];
+ $entity['alert']['active_period']['end'] = $alert['end'];
+ $entity['alert']['url']['translation'] = $alert['url'];
+ $entity['alert']['description']['translation'] = $alert['description'];
+
+ foreach ($informedEntities as $informedEntity) {
+ $informed = Array();
+ $informed[$informedEntity['informed_class']."_id"] = $informedEntity['informed_id'];
+ if ($informedEntity['informed_action'] != "") $informed["x-action"] = $informedEntity['informed_action'];
+ $informed[$informedEntity['class']."_type"] = $informedEntity['type'];
+ $entity['informed'][] = $informed;
+ }
+ $return['entities'][] = $entity;
+ }
+}
+return $return;
+}
+function getServiceAlertsByClass() {
+ $return = Array();
+ $alerts = getServiceAlerts("","");
+ foreach ($alerts['entities'] as $entity) {
+ foreach ($entity['informed'] as $informed) {
+ foreach($informed as $key => $value){
+ if (strpos("_id",$key) > 0) {
+ $parts = explode($key);
+ $class = $parts[0];
+ $id = $value;
+ }
+ }
+ $return[$class][$id]['entity'] = $entity;
+ $return[$class][$id]['action'] = $informed["x-action"];
+ }
+ }
+}
?>
--- a/include/db/servicealert-dao.inc.php
+++ b/include/db/servicealert-dao.inc.php
@@ -15,7 +15,7 @@
function getCurrentAlerts() {
global $conn;
- $query = "SELECT * from servicealerts_alerts";
+ $query = 'SELECT * from servicealerts_alerts where NOW() > start and NOW() < "end"';
//debug($query, "database");
$query = $conn->prepare($query);
//if ($stop_sequence != "") $query->bindParam(":stop_sequence", $stop_sequence);
@@ -31,14 +31,20 @@
global $conn;
$query = "SELECT * from servicealerts_informed where servicealert_id = :servicealert_id";
- if ($filter_class != "" && $filter_id != "") {
- $query .= " AND (informed_class = :informed_class OR informed_class = 'network') AND informed_id = :informed_id";
+ if ($filter_class != "" ) {
+ $query .= " AND informed_class = :informed_class ";
+
+ }
+ if ($filter_id != "") {
+ $query .= " AND informed_id = :informed_id ";
}
//debug($query, "database");
$query = $conn->prepare($query);
- if ($filter_class != "" && $filter_id != "") {
+ if ($filter_class != "" ) {
$query->bindParam(":informed_class", $filter_class);
+ }
+ if ($filter_id != "") {
$query->bindParam(":informed_id", $filter_id);
}
$query->bindParam(":servicealert_id", $id);
--- a/labs/myway_api.json.php
+++ b/labs/myway_api.json.php
@@ -126,7 +126,7 @@
if (sizeof($return) == 0) {
$return['error'][] = "No data extracted from MyWay website - API may be out of date";
}
-
+if (basename(__FILE__) == "myway_api.json.php") {
header('Content-Type: text/javascript; charset=utf8');
// header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/');
header('Access-Control-Max-Age: 3628800');
@@ -137,5 +137,6 @@
}
else echo json_encode($return);
+}
?>
--- a/servicealerts_api.php
+++ b/servicealerts_api.php
@@ -1,41 +1,8 @@
<?php
include ('include/common.inc.php');
-/*
- also need last modified epoch of client gtfs
-
- - add,remove,patch
- - stop
- - trip
- - network
- - patterns (WHERE=)
- - route (short_name or route_id)
- - street
- - stop
- - trip */
-$return = Array();
-$return['header']['gtrtfs_version'] = "1";
-$return['header']['timestamp'] = time();
-$return['entities'] = Array();
-foreach(getCurrentAlerts() as $alert) {
- $informedEntities = getInformedAlerts($alert['id'],$_REQUEST['filter_class'],$_REQUEST['filter_id']);
- if (sizeof($informedEntities) >0) {
- $entity = Array();
- $entity['id'] = $alert['id'];
- $entity['alert']['active_period']['start'] = $alert['start'];
- $entity['alert']['active_period']['start'] = $alert['end'];
- $entity['alert']['url']['translation'] = $alert['url'];
- $entity['alert']['description']['translation'] = $alert['description'];
-
- foreach ($informedEntities as $informedEntity) {
- $informed = Array();
- $informed[$informedEntity['informed_class']."_id"] = $informedEntity['informed_id'];
- if ($informedEntity['informed_action'] != "") $informed["x-action"] = $informedEntity['informed_action'];
- //$informed[$informedEntity['class']."_type"] = $informedEntity['type'];
- $entity['informed'][] = $informed;
- }
- $return['entities'][] = $entity;
- }
-}
+
+if (basename(__FILE__) == "servicealerts_api.php") {
+ $return = getServiceAlerts($_REQUEST['filter_class'],$_REQUEST['filter_id']);
header('Content-Type: text/javascript; charset=utf8');
// header('Access-Control-Allow-Origin: http://bus.lambdacomplex.org/');
header('Access-Control-Max-Age: 3628800');
@@ -45,5 +12,6 @@
//print_r($_GET['callback'] . $json); //callback is prepended for json-p
}
else echo json_encode($return);
+}
?>