pgrimaud / ratp-api-rest

This project turnkey is distributed as a middleware to expose RATP realtime data as REST resources
MIT License
85 stars 15 forks source link

Afficher les alertes de trafic #40

Open AymenFarrah opened 2 years ago

AymenFarrah commented 2 years ago

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);
Capture d’écran 2021-11-15 à 21 10 28 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 !