dl/includes/PTStop.php

64 lines
1.6 KiB
PHP
Raw Normal View History

2020-06-17 20:49:28 +02:00
<?php
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
class PTStop extends PTElement {
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
protected $exists;
protected $municipality;
protected $name;
protected $fullName;
protected $location;
2020-06-18 16:38:16 +02:00
public static function sanitizeName($name) {
return preg_replace("~(^| )'?T($| )~", '$1\'t$2', $name);
}
2020-06-17 20:49:28 +02:00
public function __toString () {
return 'PTStop[' . $this->ref . ']';
}
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
public function getExists () {
if (!$this->infoFetched) $this->fetchInfo();
return $this->exists;
}
public function getMunicipality () {
if (!$this->infoFetched) $this->fetchInfo();
return $this->municipality;
}
public function getName () {
if (!$this->infoFetched) $this->fetchInfo();
return $this->name;
}
public function getFullName () {
if (!$this->infoFetched) $this->fetchInfo();
return $this->fullName;
}
public function getLocation () {
if (!$this->infoFetched) $this->fetchInfo();
return $this->location;
}
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
protected function fetchInfo () {
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
$apireq = new ApiCoreRequest('haltes/titel/' . $this->ref);
$response = $apireq->exec();
$this->exists = !is_null($response);
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
$this->municipality = $response['omschrijvingGemeente'];
2020-06-18 16:38:16 +02:00
$this->name = static::sanitizeName($response['omschrijvingKort']);
$this->fullName = static::sanitizeName($response['omschrijvingLang']);
2020-06-17 20:49:28 +02:00
$this->location = array(floatval($response['coordinaat']['lt']), floatval($response['coordinaat']['ln']));
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
}
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
public function getImminentVehicles ($numberOfLines) {
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
$apireq = new ApiCoreRequest('haltes/doorkomstenditmoment/' . $this->ref . '/' . $numberOfLines);
return $apireq->exec();
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
}
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
}
2020-06-18 16:38:16 +02:00
2020-06-17 20:49:28 +02:00
?>