Commit 9c1030fa authored by JonathanMM's avatar JonathanMM

Extrait d'une fonction permettant d'avoir les données liés à une conso, avec filtre personnalisable

parent 6a11fb3d
......@@ -761,36 +761,18 @@ function getDataConsoBikeResume($filtre, $periode)
function getDataConso($idConso, $longitude = null, $latitude = null)
{
global $pdo;
$whereCoord = '';
$whereCoord = null;
if(!is_null($longitude) && !is_null($latitude))
{
$whereCoord = ' AND '.implode(' AND ', array(
$whereCoord = implode(' AND ', array(
'stations.longitude >= '.($longitude - 0.015),
'stations.longitude <= '.($longitude + 0.015),
'stations.latitude >= '.($latitude - 0.01),
'stations.latitude <= '.($latitude + 0.01)
));
}
$requete = $pdo->query('SELECT * FROM status inner join `stations` on stations.code = status.code WHERE idConso = '.$idConso.$whereCoord.' order by status.code asc');
$data = $requete->fetchAll(PDO::FETCH_ASSOC);
$retour = [];
foreach($data as $station)
{
$retour[] = array(
'code' => $station['code'],
'codeStr' => displayCodeStation($station['code']),
'name' => $station['name'],
'dateOuverture' => is_null($station['dateOuverture']) ? 'Non ouvert' : $station['dateOuverture'],
'state' => $station['state'],
'nbBike' => $station['nbBike'],
'nbEbike' => $station['nbEBike'],
'nbFreeEDock' => $station['nbFreeEDock'],
'nbEDock' => $station['nbEDock'],
'latitude' => $station['latitude'],
'longitude' => $station['longitude']
);
}
return array('data' => $retour);
return array('data' => getStatusByIdConso($idConso, $whereCoord));
}
function getDataStation($codeStation)
......
......@@ -20,4 +20,32 @@ function getCommuneStation($codeStation)
return $ligne['insee'];
}
function getStatusByIdConso($idConso, $filtreWhere = null)
{
global $pdo;
$requete = $pdo->query('SELECT * FROM status INNER JOIN `stations` ON stations.code = status.code WHERE idConso = '.$idConso.
(is_null($filtreWhere) ? '' : ' AND ('.$filtreWhere.')').' ORDER BY status.code ASC');
if($requete === false)
return null;
$data = $requete->fetchAll(PDO::FETCH_ASSOC);
$retour = [];
foreach($data as $station)
{
$retour[] = array(
'code' => $station['code'],
'codeStr' => displayCodeStation($station['code']),
'name' => $station['name'],
'dateOuverture' => is_null($station['dateOuverture']) ? 'Non ouvert' : $station['dateOuverture'],
'state' => $station['state'],
'nbBike' => $station['nbBike'],
'nbEbike' => $station['nbEBike'],
'nbFreeEDock' => $station['nbFreeEDock'],
'nbEDock' => $station['nbEDock'],
'latitude' => $station['latitude'],
'longitude' => $station['longitude']
);
}
return $retour;
}
?>
\ No newline at end of file
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