Un seul appel aux évènements

This commit is contained in:
root 2018-03-18 18:51:53 +01:00
parent d3f8ce3d14
commit e4d009ed5f

View File

@ -122,6 +122,22 @@ function mes_balise_Repartition2($tag) {
if ($GLOBALS[MES]["repartition2"] != false) {
return $GLOBALS[MES]["repartition2"];
}
$url_evenements = 'http://www.agendadulibre.org/maps.json?future=false&tag='.$tag;
$evenementArray = json_decode(file_get_contents($url_evenements), true);
$evenementCount = count($evenementArray);
$evenementParRegionMap = array();
for($i = 0; $i < $evenementCount; $i++) {
$evenement = $evenementArray[$i];
$region_id = 0;
if (array_key_exists("region", $evenement["properties"])) {
$region_id = $evenement["properties"]["region_id"];
}
if (array_key_exists("id_".$region_id, $evenementParRegionMap)) {
$evenementParRegionMap["id_".$region_id][] = $evenement;
} else {
$evenementParRegionMap["id_".$region_id] = array($evenement);
}
}
$url_regions = "http://www.agendadulibre.org/regions.json";
$total = 0;
$json_regions = json_decode(file_get_contents($url_regions), true);
@ -135,14 +151,14 @@ function mes_balise_Repartition2($tag) {
$total_pays = 0;
for($j = 0; $j < $regionCount; $j++) {
$sousregion = $json_regions[$j];
if ($sousregion["region_id"] == $pays_id) {
$url_evenements = 'http://www.agendadulibre.org/maps.json?future=false&tag='.$tag.'&region='.$sousregion["id"];
$evenementArray = json_decode(file_get_contents($url_evenements), true);
$sousregion["evenements"] = $evenementArray;
$total_region = count($evenementArray);
if ($total_region > 0) {
$total += $total_region;
if ($sousregion["region_id"] == $pays_id) {
$region_id = $sousregion["id"];
if (array_key_exists("id_".$region_id, $evenementParRegionMap)) {
$evenementParRegionArray = $evenementParRegionMap["id_".$region_id];
$total_region = count($evenementParRegionArray);
$sousregion["evenements"] = $evenementParRegionArray;
$total_pays += $total_region;
$total += $total_region;
$pays["sousregions"][] = $sousregion;
}
}