code = "liste_regions()"; return $p; } function liste_regions(){ $tab_regions=array( '3'=>"Auvergne-Rhône-Alpes", '5'=>"Bourgogne-Franche-Comté", '6'=>"Bretagne", '7'=>"Centre-Val de Loire", '9'=>"Corse", '1'=>"Grand Est", '23'=>"Guadeloupe", '24'=>"Guyane", '17'=>"Hauts-de-France", '12'=>"Île-de-France", '26'=>"La Réunion", '25'=>"Martinique", '28'=>"Mayotte", '4'=>"Normandie", '2'=>"Nouvelle-Aquitaine", '13'=>"Occitanie", '18'=>"Pays de la Loire", '21'=>"Provence-Alpes-Côte d'Azur", '27'=>"Autre pays" ); return $tab_regions; } /********************************** * Le préfixe MES identifie les éléments * défini dans ce fichier mes_fonctions.php ***********************************/ define("MES", "MES"); $GLOBALS[MES] = array("repartition" => false, "repartition2" => false); /************************************ * Balise récupérant les évènements répartis par région *************************************/ function balise_MES_REPARTITION($p) { $tag = ""; if (($v = interprete_argument_balise(1,$p))!==NULL){ $tag = $v; } $p->code = "mes_balise_Repartition($tag)"; return $p; } /************************************ * Balise récupérant les évènements répartis par pays et par région *************************************/ function balise_MES_REPARTITION2($p) { $tag = ""; if (($v = interprete_argument_balise(1,$p))!==NULL){ $tag = $v; } $p->code = "mes_balise_Repartition2($tag)"; return $p; } /************************************ * Récupération du JSON et traitement pour regrouper par région * Renvoie le tableau associatif repartition avec deux clés : * - total : le nombre total d'évènements * - regions : tableau associatif avec comme clé le nom de la région et comme valeur * le tableau des évènements *************************************/ function mes_balise_Repartition($tag) { if ($GLOBALS[MES]["repartition"] != false) { return $GLOBALS[MES]["repartition"]; } $url = 'http://www.agendadulibre.org/maps.json?future=false&tag='.$tag; $json = json_decode(file_get_contents($url), true); $evenementCount = count($json); $regionMap = array(); for($i = 0; $i < $evenementCount; $i++) { $evenement = $json[$i]; $region = "Autre"; if (array_key_exists("region", $evenement["properties"])) { $region = $evenement["properties"]["region"]; } if (array_key_exists($region, $regionMap)) { $regionMap[$region][] = $evenement; } else { $regionMap[$region] = array($evenement); } } uksort($regionMap, "mes_compare"); $repartition = array( "total" => $evenementCount, "regions" => $regionMap ); $GLOBALS[MES]["repartition"] = $repartition; return $repartition; } /************************************ * Travaille en deux étapes : * - récupère la liste des régions pour construire une arborescence pays par pays * - un pays * - récupère les évenements et les classes * Récupération du JSON et traitement pour regrouper par région * Renvoie le tableau associatif repartition avec deux clés : * - total : le nombre total d'évènements * - regions : tableau associatif avec comme clé le nom de la région et comme valeur * le tableau des évènements *************************************/ function mes_balise_Repartition2($tag) { if ($GLOBALS[MES]["repartition2"] != false) { return $GLOBALS[MES]["repartition2"]; } $url_regions = "http://www.agendadulibre.org/regions.json"; $total = 0; $json_regions = json_decode(file_get_contents($url_regions), true); $regionCount = count($json_regions); $paysArray = array(); for($i = 0; $i < $regionCount; $i++) { $region = $json_regions[$i]; if (strlen($region['code']) > 0) { $pays_id = $region['id']; $pays = array("name" => $region['name'], "code" => $region['code'], "sousregions" => array()); $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.'®ion='.$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; $total_pays += $total_region; $pays["sousregions"][] = $sousregion; } } } if ($total_pays > 0) { $paysArray[] = $pays; } } } $repartition = array( "total" => $total, "pays" => $paysArray ); $GLOBALS[MES]["repartition2"] = $repartition; return $repartition; } /************************************ * Fonction de comparaison tenant compte des accents *************************************/ function mes_compare($a, $b) { $coll = collator_create( 'fr_FR' ); return collator_compare($coll, $a, $b); }