Add support for timetable queries

This commit is contained in:
Klaus-Uwe Mitterer 2016-08-22 09:22:20 +02:00
parent e28946c535
commit fdbadea14a
1 changed files with 72 additions and 1 deletions

View File

@ -15,7 +15,7 @@ function prepare() {
global $output;
header("Content-type: application/" . $output . "; charset=utf-8");
if ($output == "xml") {
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<stations>\n");
print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
}
}
@ -46,12 +46,83 @@ if ($type == "validate") {
prepare();
print("<stations>");
foreach($api->validate(isset($_GET["name"]) ? $_GET["name"] : $_POST["name"]) as $station) {
print("<station><id>" . $station["id"] . "</id><name>" . $station["value"] . "</name></station>\n");
}
print("</stations>");
} else if ($type == "conn" || $type == "connection" || $type == "connections") {
if ((isset($_GET["from"]) && isset($_GET["to"])) || (isset($_POST["from"]) && isset($_POST["to"]))) {
prepare();
$from = (isset($_GET["from"]) && isset($_GET["to"]) ? $_GET["from"] : $_POST["from"]);
$to = (isset($_GET["from"]) && isset($_GET["to"]) ? $_GET["to"] : $_POST["to"]);
$count = (isset($_GET["count"]) ? $_GET["count"] : (isset($_POST["count"]) ? $_POST["count"] : 3));
$date = (isset($_GET["date"]) ? $_GET["date"] : (isset($_POST["date"]) ? $_POST["date"] : null));
$time = (isset($_GET["time"]) ? $_GET["time"] : (isset($_POST["time"]) ? $_POST["time"] : null));
$mode = (isset($_GET["mode"]) ? $_GET["mode"] : (isset($_POST["mode"]) ? $_POST["mode"] : null));
print("<connections>\n");
/* foreach ($api->get($from, $to, $count, $date, $time, $mode) as $conn) {
print("Connection");
var_dump($conn);
print("Details");
var_dump($api->getDetails($conn["id"]));
print("Coords");
var_dump($api->getCoords());
} */
foreach ($api->get($from, $to, $count, $date, $time, $mode) as $conn) {
print(" <connection id='" . $conn["id"] . "'>\n");
print(" <from><name>" . $conn["startStation"] . "</name><id>" . $api->validate($conn["startStation"])[0]["id"] . "</id></from>\n");
print(" <to><name>" . $conn["endStation"] . "</name><id>" . $api->validate($conn["endStation"])[0]["id"] . "</id></to>\n");
print(" <details>\n");
print(" <departure><date>" . $conn["startDate"] . "</date><time>" . $conn["startTime"] . "</time></departure>\n");
print(" <arrival><date>" . $conn["endDate"] . "</date><time>" . $conn["endTime"] . "</time></arrival>\n");
print(" <duration>" . $conn["duration"] . "</duration>\n");
print(" <changes>" . $conn["changes"] . "</changes>\n");
print(" <current><![CDATA[" . $conn["prognose"] . "]]></current>\n");
print(" </details>\n");
print(" <services>\n");
$order = 0;
foreach ($api->getDetails($conn["id"]) as $service) {
print(" <service id='" . $order . "'>\n");
print(" <name>" . $service["data"]["productName"] . "</name>\n");
print(" <departure>\n");
print(" <station><name>" . $service["start"]["station"] . "</name><id>" . $api->validate($service["start"]["station"])[0]["id"] . "</id></station>\n");
print(" <date>" . $service["start"]["date"] . "</date><time>" . $service["start"]["time"] . "</time>\n");
print(" <platform>" . $service["start"]["plattform"] . "</platform>\n");
print(" <current><![CDATA[" . $service["start"]["prognose"] . "]]></current>");
print(" </departure>\n");
print(" <arrival>\n");
print(" <station><name>" . $service["end"]["station"] . "</name><id>" . $api->validate($service["end"]["station"])[0]["id"] . "</id></station>\n");
print(" <date>" . $service["end"]["date"] . "</date><time>" . $service["end"]["time"] . "</time>\n");
print(" <platform>" . $service["end"]["plattform"] . "</platform>\n");
print(" <current><![CDATA[" . $service["end"]["prognose"] . "]]></current>\n");
print(" </arrival>\n");
print(" </service>\n");
$order++;
}
print(" </services>\n");
print(" </connection>\n");
}
print("</connections>\n");
} else {
error("Required 'from' and/or 'to' arguments missing.");
}
} else {
error("Unknown request type provided.");
}