function __construct($from, $to, $time, $date, $timeSel, $results = 6, $lang = "EN", $format = "xml", $typeOfTransport = "all") { parent::__construct($format, $lang); if ($from == "" || $to == "") { throw new Exception("No stations specified"); } //TODO: check on input $this->results = $results; $this->from = $from; $this->to = $to; $this->time = $time; $this->date = $date; $this->timeSel = $timeSel; $this->typeOfTransport = $typeOfTransport; //check for ID if (sizeof(explode(".", $from)) > 1) { $si = new StationsInput(); $station = $si->getStationFromId($from, $this); $this->from = $station->getName(); } if (sizeof(explode(".", $to)) > 1) { $si = new StationsInput(); $station = $si->getStationFromId($to, $this); $this->to = $station->getName(); } }
function __construct($station, $date, $time, $arrdep = "DEP", $lang = "EN", $format = "xml", $isId = false) { parent::__construct($format, $lang); if (!$isId) { $this->station = $station; } else { $stin = new StationsInput(); $this->station = $stin->getStationFromId($station, $this)->getName(); } $this->date = $date; $this->time = $time; $this->arrdep = $arrdep; }
function __construct() { $this->page = array("title" => "iRail.be", "subtitle" => "Mobile"); $stationsinput = new StationsInput(); $this->page["stationarray"] = $stationsinput->generate_js_array(parent::newRequestInstance()); $this->page["date"] = date("D d/m/Y H:i"); if (isset($_COOKIE["from"])) { $this->page["from"] = $_COOKIE["from"]; } else { $this->page["from"] = ""; } if (isset($_COOKIE["to"])) { $this->page["to"] = $_COOKIE["to"]; } else { $this->page["to"] = ""; } }
/** * This function will use approximate string matching to determine what station we're looking for * @param string $name */ protected function getStation($name1) { $name1 = str_ireplace("[b]", "", $name1); $name1 = str_ireplace("(nl)", "", $name1); $stationsinput = new StationsInput(); $stations = $stationsinput->execute($this->request); $name1 = strtoupper($name1); $max = 0; $match = ""; foreach ($stations as $station) { $name2 = $station->getName(); similar_text($name1, $name2, $score); if ($score > $max) { $max = $score; $match = $station; } } if ($match == "") { throw new Exception("Could not find a good station for the name given (getStation())", 3); } return $match; }
protected function transformData($serverData) { $inp = new StationsInput(); $stations = $inp->execute($this->request); $xml = new SimpleXMLElement($serverData); $connections = array(); $i = 0; //DEBUG: echo $serverData ; if (isset($xml->ConRes->ConnectionList->Connection)) { foreach ($xml->ConRes->ConnectionList->Connection as $conn) { $platform0 = trim($conn->Overview->Departure->BasicStop->Dep->Platform->Text); $unixtime0 = Input::transformTime($conn->Overview->Departure->BasicStop->Dep->Time, $conn->Overview->Date); $nameStation0 = $conn->Overview->Departure->BasicStop->Station['name']; $station0 = parent::getStation($nameStation0); $platform1 = trim($conn->Overview->Arrival->BasicStop->Arr->Platform->Text); $unixtime1 = Input::transformTime($conn->Overview->Arrival->BasicStop->Arr->Time, $conn->Overview->Date); $nameStation1 = $conn->Overview->Arrival->BasicStop->Station['name']; $station1 = parent::getStation($nameStation1); //Delay or other wrongish stuff $delay0 = 0; $delay1 = 0; $platformNormal0 = true; $platformNormal1 = true; if ($conn->RtStateList->RtState["value"] == "HAS_DELAYINFO") { $delay0 = Input::transformTime($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Time, $conn->Overview->Date) - $unixtime0; if ($delay0 < 0) { $delay0 = 0; } //echo "delay: " .$conn->Overview -> Departure -> BasicStop -> StopPrognosis -> Dep -> Time . "\n"; $delay1 = Input::transformTime($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Time, $conn->Overview->Date) - $unixtime1; if ($delay1 < 0) { $delay1 = 0; } if (isset($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text)) { $platform0 = trim($conn->Overview->Departure->BasicStop->StopPrognosis->Dep->Platform->Text); $platformNormal0 = false; } if (isset($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text)) { $platform1 = trim($conn->Overview->Arrival->BasicStop->StopPrognosis->Arr->Platform->Text); $platformNormal1 = false; } } $trains = array(); $vias = array(); $j = 0; $connectionindex = 0; //yay for spaghetti code. if (isset($conn->ConSectionList->ConSection)) { foreach ($conn->ConSectionList->ConSection as $connsection) { if (isset($connsection->Journey->JourneyAttributeList->JourneyAttribute)) { foreach ($connsection->Journey->JourneyAttributeList->JourneyAttribute as $att) { if ($att->Attribute["type"] == "NAME") { $trains[$j] = str_replace(" ", "", $att->Attribute->AttributeVariant->Text); $j++; break; } } if ($conn->Overview->Transfers > 0 && strcmp($connsection->Arrival->BasicStop->Station['name'], $conn->Overview->Arrival->BasicStop->Station['name']) != 0) { //current index for the train: j-1 $departDelay = 0; //Todo: NYImplemented $connarray = $conn->ConSectionList->ConSection; $departTime = Input::transformTime($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Time, $conn->Overview->Date); $departPlatform = trim($connarray[$connectionindex + 1]->Departure->BasicStop->Dep->Platform->Text); $arrivalTime = Input::transformTime($connsection->Arrival->BasicStop->Arr->Time, $conn->Overview->Date); $arrivalPlatform = trim($connsection->Arrival->BasicStop->Arr->Platform->Text); $arrivalDelay = 0; //Todo: NYImplemented $stationv = parent::getStation($connsection->Arrival->BasicStop->Station["name"]); $vehiclev = $this->newTrain($trains[$j - 1]); $vias[$connectionindex] = new Via($vehiclev, $stationv, $arrivalTime, $arrivalPlatform, $departTime, $departPlatform, $arrivalDelay, $departDelay); $connectionindex++; } } } } $vehicle0 = $this->newTrain($trains[0]); $vehicle1 = $this->newTrain($trains[sizeof($trains) - 1]); if ($platform0 == "") { $platform0 = "NA"; } if ($platform1 == "") { $platform1 = "NA"; } $depart = new TripNode($platform0, $delay0, $unixtime0, $station0, $vehicle0, $platformNormal0); $arrival = new TripNode($platform1, $delay1, $unixtime1, $station1, $vehicle1, $platformNormal1); $duration = Input::transformDuration($conn->Overview->Duration->Time); $connections[$i] = $i; $connections[$i] = new Connection($depart, $arrival, $vias, $duration); $i++; } } else { throw new Exception("We're sorry, we could not retrieve the correct data from our sources", 2); } return $connections; }