2020-06-17 20:49:28 +02:00
< ? php
function compareDoorkomsten ( $d1 , $d2 ) {
$t1 = $d1 [ 'vertrekTheoretischeTijdstip' ];
if ( ! empty ( $d1 [ 'vertrekRealtimeTijdstip' ])) {
$t1 = $d1 [ 'vertrekRealtimeTijdstip' ];
}
$t2 = $d2 [ 'vertrekTheoretischeTijdstip' ];
if ( ! empty ( $d2 [ 'vertrekRealtimeTijdstip' ])) {
$t2 = $d2 [ 'vertrekRealtimeTijdstip' ];
}
return $t1 - $t2 ;
}
function formatDelay ( $delay ) {
$early = $delay < 0 ;
$totalSeconds = abs ( $delay );
$totalMinutes = round ( $totalSeconds / 60 );
$hours = intdiv ( $totalMinutes , 60 );
$minutes = $totalMinutes % 60 ;
$str = ( $hours !== 0 ? $hours . 'h' : '' ) . ( $minutes !== 0 ? $minutes . 'm' : '' );
//return ($delay > 0 ? '+' : '-') . $str;
return $str . ( $delay > 0 ? ' te laat' : ' te vroeg' );
}
class StopInfoboard extends Infoboard {
private $found = false ;
private $stop ;
private $numberOfLines ;
private $currentTime ;
private $lines ;
private $disturbed = false ;
private $allLinesDisturbed = false ;
private $disturbances = false ;
private $notServed = false ;
public function __construct ( $stopRef , $numberOfLines = 50 ) {
global $timezone ;
$this -> currentTime = new DateTime ( 'now' , $timezone );
$this -> stop = new PTStop ( intval ( $stopRef ));
$this -> numberOfLines = $numberOfLines ;
$result = $this -> stop -> getImminentVehicles ( $numberOfLines );
$this -> detours = $result [ 'halteOmleidingen' ];
$this -> disturbed = $result [ 'dienstRegelingVerstoord' ];
$this -> allLinesDisturbed = $result [ 'alleLijnenVerstoord' ];
$this -> disturbances = $result [ 'storingen' ];
$this -> notServed = $result [ 'nietBediend' ];
$this -> lines = $result [ 'lijnen' ];
}
public function title () {
$name = $this -> stop -> getFullName ();
if ( $name ) return $name ;
return 'Halte' ;
}
public function display () {
global $timezone ;
parent :: header ();
if ( ! $this -> stop -> getExists ()) {
echo '<div class="user-error">De halte met haltenummer ' . HTMLTools :: makeSafe ( $this -> stop -> getRef ()) . ' werd niet gevonden.</div>' ;
parent :: footer ();
return ;
}
echo '<h2>' . HTMLTools :: makeSafe ( $this -> stop -> getFullName ()) . '</h2>' ;
echo '<div class="info">' ;
echo '<div class="stopref">Haltenummer ' . HTMLTools :: makeSafe ( $this -> stop -> getRef ()) . '</div>' ;
echo '<div class="lastrefreshed">Info van ' . $this -> currentTime -> format ( 'H:i' ) . '<span class="seconds">:' . $this -> currentTime -> format ( 's' ) . '</span></div>' ;
echo '</div>' ;
if ( ! empty ( $this -> disturbances )) {
echo '<div class="disturbance"><h3>Storingen en mededelingen</h3><ul>' ;
foreach ( $this -> disturbances as $disturbance ) {
echo '<li>' . HTMLTools :: makeSafe ( $disturbance ) . '</li>' ;
}
echo '</ul></div>' ;
}
if ( ! empty ( $this -> detours )) {
echo '<div class="disturbance"><h3>Omleidingen</h3><ul>' ;
foreach ( $this -> detours as $detour ) {
$description = $detour [ 'omleidingen' ][ 0 ];
2020-06-18 13:30:46 +02:00
echo '<li><h4>' . HTMLTools :: makeSafe ( $description [ 'title' ]) . '</h4><p>' . str_replace ( " \n " , " </p><p> " , HTMLTools :: makeSafe ( $description [ 'omleiding' ])) . '</p>' ;
2020-06-17 20:49:28 +02:00
if ( ! empty ( $detour [ 'verstoordeLijnenSet' ])) {
echo '<p class="affectedLines">' ;
foreach ( $detour [ 'verstoordeLijnenSet' ] as $line ) {
echo PTLine :: htmlElement (
$line [ 'kleurAchterGrond' ],
$line [ 'kleurAchterGrondRand' ],
$line [ 'kleurVoorGrond' ],
$line [ 'lijnNummerPubliek' ]);
echo ' ' ;
}
echo '</p>' ;
}
echo '</li>' ;
}
echo '</ul></div>' ;
}
if ( $this -> notServed ) {
echo '<div class="disturbance">Deze halte wordt momenteel niet bediend.</div>' ;
} elseif ( $this -> allLinesDisturbed ) {
echo '<div class="disturbance">De dienstregeling van alle lijnen aan deze halte is verstoord.</div>' ;
} elseif ( $this -> disturbed ) {
echo '<div class="disturbance">De dienstregeling van sommige lijnen aan deze halte is verstoord.</div>' ;
}
if ( empty ( $this -> lines )) {
echo '<div class="stopInfoboard noLines">Geen doorkomsten in de nabije toekomst</div>' ;
} else {
$anyNotRealtime = false ;
echo '<table class="stopInfoboard" border="0">' ;
$evenrow = true ;
usort ( $this -> lines , compareDoorkomsten );
foreach ( $this -> lines as $line ) {
$scheduledTime = intdiv ( $line [ 'vertrekTheoretischeTijdstip' ], 1000 );
$realtimeTime = intdiv ( $line [ 'vertrekRealtimeTijdstip' ], 1000 );
if ( $realtimeTime == 0 ) $realtimeTime = null ;
$realtime = ! is_null ( $realtimeTime );
if ( ! $realtime ) $anyNotRealtime = true ;
$timeDT = new DateTime ( 'now' , $timezone );
if ( $realtime ) {
$timeDT -> setTimestamp ( $realtimeTime );
} else {
$timeDT -> setTimestamp ( $scheduledTime );
}
$delay = $realtime ? $realtimeTime - $scheduledTime : 0 ;
$canceled = in_array ( 'DELETED' , $line [ 'predictionStatussen' ]) || in_array ( 'CANCELLED' , $line [ 'predictionStatussen' ]);
echo '<tr class="line' . ( $evenrow ? ' even' : ' odd' ) . ( $canceled ? ' canceled' : '' ) . '">' ;
// Line number
echo '<td class="lineNumber">' . PTLine :: htmlElement (
$line [ 'kleurAchterGrond' ],
$line [ 'kleurAchterGrondRand' ],
$line [ 'kleurVoorGrond' ],
$line [ 'lijnNummerPubliek' ]) . '</td> ' ;
// Destination
echo '<td class="destination">' ;
if ( $canceled ) echo '<del>' ;
echo HTMLTools :: makeSafeAndWrapBetter ( $line [ 'bestemming' ]);
if ( $canceled ) echo '</del>' ;
echo '</td>' ;
// Delay
echo '<td class="delay ' . ( $delay < 0 ? 'early' : '' ) . '">' ;
if ( $canceled ) {
echo 'Rijdt niet' ;
} elseif ( abs ( $delay ) >= 60 ) {
echo formatDelay ( $delay ) . ':' ;
}
echo '</td>' ;
// Departure time
echo '<td class="departureH ' . ( $realtime ? 'rt' : 'th' ) . '">' ;
if ( ! $realtime ) {
echo static :: $theoreticalBefore ;
}
echo $timeDT -> format ( " H " );
echo '</td>' ;
echo '<td class="departureSep">:</td>' ;
echo '<td class="departureMS ' . ( $realtime ? 'rt' : 'th' ) . '">' ;
echo $timeDT -> format ( " i " );
if ( $realtime && intval ( $timeDT -> format ( 's' )) !== 0 ) {
echo '<span class="seconds">:' . $timeDT -> format ( 's' ) . '</span>' ;
}
if ( ! $realtime ) {
echo static :: $theoreticalAfter ;
}
echo '</td>' ;
echo '</tr>' ;
$evenrow = ! $evenrow ;
}
echo '</table>' ;
if ( $anyNotRealtime ) {
echo '<div class="footnote">' . static :: $theoreticalBefore . 'Theoretische vertrektijd' . static :: $theoreticalAfter . '</div>' ;
}
}
$coords = $this -> stop -> getLocation ();
echo '<a href="geo:' . $coords [ 0 ] . ',' . $coords [ 1 ] . '?z=17">Locatie van halte</a>' ;
parent :: footer ();
}
}
?>