Example #1
0
/**
 * Gets first entry for given Station ID, destinantion Array (to filter for
 * trains going in a certian direction but terminating at an earlier station)
 *
 * @param string $station_id The Station ID (like "1310")
 * @param array $dest Array with all wanted destinantions like array("Mittersendling", "Pasing")
 * @param int $line The wanted line number
 * @return array A single departure array like shown in get_deps_for_station_id()
 */
function get_first_dept_for_station_id($station_id, $dest, $line)
{
    global $min_time_to_departure;
    $deps = get_deps_for_station_id($station_id);
    if (empty($deps)) {
        my_log("Empty array!", 1);
    }
    for ($i = 0; $i < count($deps); $i++) {
        // echo $i;
        $d = $deps[$i];
        if (in_array($d['destination'], $dest) && $d['departureTime'] / 1000 - time() > $min_time_to_departure && $d['label'] == $line) {
            return $deps[$i];
        }
    }
}
<?php

include "mvg.php";
include "module.conf.php";
$deps = get_deps_for_station_id($moduleconfig["stationid"]);
if ($deps === null) {
    echo "No more trains :'(";
} else {
    echo "<table>";
    foreach ($deps as $dept) {
        $next_secs = $dept['departureTime'] / 1000 - time();
        $next = round($next_secs / 60);
        $next .= " min";
        echo "<tr>";
        echo "<td>" . strtoupper($dept["product"]) . $dept["label"] . "</td>";
        echo "<td>" . $dept["destination"] . "</td>";
        echo "<td>" . $next . "</td>";
        echo "</tr>";
    }
}