dl/includes/PTLine.php

80 lines
2 KiB
PHP
Raw Permalink Normal View History

2020-06-17 20:49:28 +02:00
<?php
class PTLine extends PTElement {
protected $entity;
protected $direction;
protected $lineType;
protected $publicRef;
protected $directionDesc;
public function __construct ($entity, $ref, $direction) {
parent::__construct($ref);
if (!is_int($entity)) {
throw new InvalidArgumentException('$entity must be an integer');
}
$this->entity = $entity;
if (!is_int($direction)) {
throw new InvalidArgumentException('$direction must be an integer');
}
$this->direction = $direction;
}
public function __toString () {
return 'PTLine[' . $this->entity . '/' . $this->ref . '/' . $this->direction . ']';
}
public function getRef () {
return $this->ref;
}
public function getPublicRef () {
if (!$this->infoFetched) $this->fetchInfo();
return $this->publicRef;
}
public function getLineType () {
if (!$this->infoFetched) $this->fetchInfo();
return $this->lineType;
}
public function getDirectionDesc () {
if (!$this->infoFetched) $this->fetchInfo();
return $this->directionDesc;
}
protected function fetchInfo () {
$apireq = new ApiCoreRequest('lijnen/titel/' . $this->entity . '/' . $this->ref . '/' . $this->direction);
$response = $apireq->exec();
$this->lineType = PTElement::lineTypeTextToConst($response['lijnType']);
$this->publicRef = $response['lijnNummerPubliek'];
$this->directionDesc = $response['lijnRichting'];
}
public function getTimetable () {
throw new NotImplementedException();
}
public function getTimetableAtStop (PTStop $stop) {
throw new NotImplementedException();
}
public static function htmlElement($bgColor, $bgBorder, $fgColor, $lineNumber, $class='') {
return '<span class="line-nr ' . $class . '" style="' .
'background:' . HTMLTools::makeSafe($bgColor) . ';' .
'border-color:' . HTMLTools::makeSafe($bgBorder) . ';' .
'color:' . HTMLTools::makeSafe($fgColor) . ';' .
'">' .$lineNumber . '</span>';
}
}
?>