Commit dd8e3ec8 authored by JonathanMM's avatar JonathanMM

Affichage des stations à proximité d'une station

parent 57545c23
...@@ -795,16 +795,17 @@ function getDataStation($codeStation) ...@@ -795,16 +795,17 @@ function getDataStation($codeStation)
$filtreDate = $hier->format('Y-m-d H:i:s'); $filtreDate = $hier->format('Y-m-d H:i:s');
//Stations //Stations
$requete = $pdo->query('SELECT c.date, s.nbBike, s.nbEBike, s.nbFreeEDock, s.nbEDock $requete = $pdo->query('SELECT c.id, c.date, s.nbBike, s.nbEBike, s.nbFreeEDock, s.nbEDock
FROM status s FROM status s
INNER JOIN statusConso c ON c.id = s.idConso INNER JOIN statusConso c ON c.id = s.idConso
WHERE s.code = '.$codeStation.' AND c.date >= "'.$filtreDate.'" WHERE s.code = '.$codeStation.' AND c.date >= "'.$filtreDate.'"
ORDER BY s.code ASC'); ORDER BY c.id ASC');
$statusStation = $requete->fetchAll(PDO::FETCH_ASSOC); $statusStation = $requete->fetchAll(PDO::FETCH_ASSOC);
$retour = []; $retour = [];
foreach($statusStation as $statut) foreach($statusStation as $statut)
{ {
$retour[] = array( $retour[] = array(
'idConso' => $statut['id'],
'date' => $statut['date'], 'date' => $statut['date'],
'nbBike' => $statut['nbBike'], 'nbBike' => $statut['nbBike'],
'nbEbike' => $statut['nbEBike'], 'nbEbike' => $statut['nbEBike'],
......
...@@ -30,7 +30,9 @@ $smarty->assign(array( ...@@ -30,7 +30,9 @@ $smarty->assign(array(
'stationCodeDisplay' => displayCodeStation($code), 'stationCodeDisplay' => displayCodeStation($code),
'stationNom' => $station['name'], 'stationNom' => $station['name'],
'stationDateOuverture' => (new DateTime($station['dateOuverture']))->format('d/m/Y'), 'stationDateOuverture' => (new DateTime($station['dateOuverture']))->format('d/m/Y'),
'stationAdresse' => $station['adresse'] 'stationAdresse' => $station['adresse'],
'stationLat' => $station['latitude'],
'stationLong' => $station['longitude']
)); ));
//Filtre semaine //Filtre semaine
......
...@@ -50,12 +50,26 @@ ...@@ -50,12 +50,26 @@
</tr> </tr>
</thead> </thead>
</table> </table>
<h2>Stations à proximité</h2>
<table id="stations">
<thead>
<tr>
<th>Code</th>
<th>Nom</th>
<th>Date d'ouverture</th>
<th>Statut</th>
<th>Vélos mécaniques dispo</th>
<th>Vélos électriques dispo</th>
<th>Bornes libres</th>
</tr>
</thead>
</table>
<script type="text/javascript"> <script type="text/javascript">
var codeStation = {$stationCode}; var codeStation = {$stationCode};
</script> </script>
<script type="application/javascript"> <script type="application/javascript">
$(document).ready( function () { $(document).ready( function () {
$('#stats').DataTable({ var dt = $('#stats').DataTable({
ajax: 'api.php?action=getDataStation&codeStation={$stationCode}', ajax: 'api.php?action=getDataStation&codeStation={$stationCode}',
columns: [{ columns: [{
data: 'date', data: 'date',
...@@ -75,9 +89,57 @@ ...@@ -75,9 +89,57 @@
return data+'/'+row.nbEDock; return data+'/'+row.nbEDock;
} }
}], }],
language: dtTraduction language: dtTraduction,
initComplete: function (settings, dataAjax)
{
var data = dataAjax['data'];
if(data.length > 0)
chargerListeStationProximite(data[data.length - 1]['idConso']);
}
}); });
} ); } );
function chargerListeStationProximite(idConso)
{
var dtStation = $('#stations').DataTable({
ajax: 'api.php?action=getDataConso&idConso='+idConso+'&lat={$stationLat}&long={$stationLong}',
columns: [{
data: 'codeStr',
render: function(data, type, row, meta)
{
return '<a href="station.php?code='+row.code+'">'+data+'</a>';
}
},{
data: 'name',
render: function(data, type, row, meta)
{
return '<a href="station.php?code='+row.code+'">'+data+'</a>';
}
},{
data: 'dateOuverture',
render: function(data, type, row, meta)
{
if(data == 'Non ouvert')
return data;
var date = new Date(data);
return putZero(date.getDate()) + '/' + putZero(date.getMonth()+1) + '/' + date.getFullYear();
}
},{
data: 'state'
},{
data: 'nbBike'
},{
data: 'nbEbike'
},{
data: 'nbFreeEDock',
render: function(data, type, row, meta)
{
return data+'/'+row.nbEDock;
}
}],
language: dtTraduction
});
}
</script> </script>
</div> </div>
{include file="footer.tpl"} {include file="footer.tpl"}
\ No newline at end of file
  • C'est quoi la définition de "station à proximité ?" c'est une question de distance (en km en °) ? En fonction de la commune ?

  • C'est en fonction de la latitude/longitude, cf api.php

                'stations.longitude >= '.($longitude - 0.015),       
                'stations.longitude <= '.($longitude + 0.015),       
                'stations.latitude >= '.($latitude - 0.01),       
                'stations.latitude <= '.($latitude + 0.01)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment