<?php |
<?php |
$service_periods = Array( |
$service_periods = Array( |
'sunday', |
'sunday', |
'saturday', |
'saturday', |
'weekday' |
'weekday' |
); |
); |
|
|
function service_period($date = "") |
function service_period($date = "") |
{ |
{ |
|
|
if (isset($_SESSION['service_period'])) return $_SESSION['service_period']; |
if (isset($_SESSION['service_period'])) return $_SESSION['service_period']; |
$override = getServiceOverride($date); |
$override = getServiceOverride($date); |
if ($override['service_id']){ |
if ($override['service_id']){ |
return $override['service_id']; |
return $override['service_id']; |
} |
} |
|
|
switch (date('w',($date != "" ? $date : time()))) { |
switch (date('w',($date != "" ? $date : time()))) { |
case 0: |
case 0: |
return 'sunday'; |
return 'sunday'; |
case 6: |
case 6: |
return 'saturday'; |
return 'saturday'; |
default: |
default: |
return 'weekday'; |
return 'weekday'; |
} |
} |
} |
} |
function midnight_seconds($time = "") |
function midnight_seconds($time = "") |
{ |
{ |
// from http://www.perturb.org/display/Perlfunc__Seconds_Since_Midnight.html |
// from http://www.perturb.org/display/Perlfunc__Seconds_Since_Midnight.html |
if ($time != "") { |
if ($time != "") { |
return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time); |
return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time); |
} |
} |
if (isset($_SESSION['time'])) { |
if (isset($_SESSION['time'])) { |
$time = strtotime($_SESSION['time']); |
$time = strtotime($_SESSION['time']); |
return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time); |
return (date("G", $time) * 3600) + (date("i", $time) * 60) + date("s", $time); |
} |
} |
return (date("G") * 3600) + (date("i") * 60) + date("s"); |
return (date("G") * 3600) + (date("i") * 60) + date("s"); |
} |
} |
function midnight_seconds_to_time($seconds) |
function midnight_seconds_to_time($seconds) |
{ |
{ |
if ($seconds > 0) { |
if ($seconds > 0) { |
$midnight = mktime(0, 0, 0, date("n") , date("j") , date("Y")); |
$midnight = mktime(0, 0, 0, date("n") , date("j") , date("Y")); |
return date("h:ia", $midnight + $seconds); |
return date("h:ia", $midnight + $seconds); |
} |
} |
else { |
else { |
return ""; |
return ""; |
} |
} |
} |
} |
function getServiceAlerts($filter_class, $filter_id) { |
function getServiceAlerts($filter_class, $filter_id) { |
/* |
/* |
|
|
also need last modified epoch of client gtfs |
also need last modified epoch of client gtfs |
|
|
- add,remove,patch,inform (null) |
- add,remove,patch,inform (null) |
- stop |
- stop |
- trip |
- trip |
- network |
- network |
- patterns (WHERE=) |
- classes (WHERE=) |
- route (short_name or route_id) |
- route (short_name or route_id) |
- street |
- street |
- stop |
- stop |
- trip */ |
- trip |
|
Currently support: |
|
network inform |
|
trip patch: stop remove |
|
street inform: route inform, trip inform, stop inform |
|
route patch: trip remove |
|
*/ |
$return = Array(); |
$return = Array(); |
$return['header']['gtrtfs_version'] = "1"; |
$return['header']['gtrtfs_version'] = "1"; |
$return['header']['timestamp'] = time(); |
$return['header']['timestamp'] = time(); |
$return['entities'] = Array(); |
$return['entities'] = Array(); |
foreach(getCurrentAlerts() as $alert) { |
foreach(getCurrentAlerts() as $alert) { |
$informedEntities = getInformedAlerts($alert['id'],$_REQUEST['filter_class'],$_REQUEST['filter_id']); |
$informedEntities = getInformedAlerts($alert['id'],$_REQUEST['filter_class'],$_REQUEST['filter_id']); |
if (sizeof($informedEntities) >0) { |
if (sizeof($informedEntities) >0) { |
$entity = Array(); |
$entity = Array(); |
$entity['id'] = $alert['id']; |
$entity['id'] = $alert['id']; |
$entity['alert']['active_period']['start'] = $alert['start']; |
$entity['alert']['active_period']['start'] = $alert['start']; |
$entity['alert']['active_period']['end'] = $alert['end']; |
$entity['alert']['active_period']['end'] = $alert['end']; |
$entity['alert']['url']['translation'] = $alert['url']; |
$entity['alert']['url']['translation'] = $alert['url']; |
$entity['alert']['description']['translation'] = $alert['description']; |
$entity['alert']['description']['translation'] = $alert['description']; |
|
|
foreach ($informedEntities as $informedEntity) { |
foreach ($informedEntities as $informedEntity) { |
$informed = Array(); |
$informed = Array(); |
$informed[$informedEntity['informed_class']."_id"] = $informedEntity['informed_id']; |
$informed[$informedEntity['informed_class']."_id"] = $informedEntity['informed_id']; |
if ($informedEntity['informed_action'] != "") $informed["x-action"] = $informedEntity['informed_action']; |
if ($informedEntity['informed_action'] != "") $informed["x-action"] = $informedEntity['informed_action']; |
$informed[$informedEntity['class']."_type"] = $informedEntity['type']; |
$informed[$informedEntity['class']."_type"] = $informedEntity['type']; |
$entity['informed'][] = $informed; |
$entity['informed'][] = $informed; |
} |
} |
$return['entities'][] = $entity; |
$return['entities'][] = $entity; |
} |
} |
} |
} |
return $return; |
return $return; |
} |
} |
function getServiceAlertsByClass() { |
function getServiceAlertsByClass() { |
$return = Array(); |
$return = Array(); |
$alerts = getServiceAlerts("",""); |
$alerts = getServiceAlerts("",""); |
foreach ($alerts['entities'] as $entity) { |
foreach ($alerts['entities'] as $entity) { |
foreach ($entity['informed'] as $informed) { |
foreach ($entity['informed'] as $informed) { |
foreach($informed as $key => $value){ |
foreach($informed as $key => $value){ |
if (strpos("_id",$key) > 0) { |
if (strpos("_id",$key) > 0) { |
$parts = explode($key); |
$parts = explode($key); |
$class = $parts[0]; |
$class = $parts[0]; |
$id = $value; |
$id = $value; |
} |
} |
} |
} |
$return[$class][$id]['entity'] = $entity; |
$return[$class][$id][]['entity'] = $entity; |
$return[$class][$id]['action'] = $informed["x-action"]; |
$return[$class][$id][]['action'] = $informed["x-action"]; |
} |
} |
} |
} |
} |
} |
?> |
?> |
|
|