ratp-api-rest icon indicating copy to clipboard operation
ratp-api-rest copied to clipboard

Afficher les alertes de trafic

Open AymenFarrah opened this issue 3 years ago • 0 comments

Bonjour

Je voudrais bien faire une pull request mais j'ai pas réussi a en créer.

L'idée étant d'afficher l'alerte de trafic la plus récente pour être plus conforme à ce qu'affiche la RATP comme information.

Pour y arriver je propose ce code dans le service RatpTrafficService.php

// Collect specific errors : Travaux
if (isset($errors['Travaux'])) {
    array_push($events, current($errors['Travaux']));                         
} 
// Collect specific errors : Incident
if (isset($errors['Incidents techniques'])) {
    array_push($events, current($errors['Incidents techniques']));
} 
// Collect specific errors : Grève
if (isset($errors['Mouvement social'])) {
    array_push($events, current($errors['Mouvement social']));                        
} 
// If no specific errors ! Collect all available errors
if (empty($events)) {
    $events = current($errors);
}
// Sort events to get the recent event on top
usort($events, function ($event1, $event2) {
    return $event2['startDate'] <=> $event1['startDate'];
}
// Take the first event on the events list (the recent one)
$event = reset($events);
  • L' information donnée par la RATP en capture ici :
Capture d’écran 2021-11-15 à 21 10 28
  • La version d'API actuelle donne ça :
Capture d’écran 2021-11-15 à 21 02 23

- La version avec mon fix donne ça :

Capture d’écran 2021-11-15 à 21 02 31

Merci !

AymenFarrah avatar Nov 15 '21 20:11 AymenFarrah