diff --git a/mes_fonctions.php b/mes_fonctions.php
index d18f477..29a1035 100644
--- a/mes_fonctions.php
+++ b/mes_fonctions.php
@@ -36,4 +36,68 @@ function liste_regions(){
'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);
+
+/************************************
+* 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;
+}
+
+/************************************
+* 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;
+}
+
+/************************************
+* Fonction de comparaison tenant compte des accents
+*************************************/
+function mes_compare($a, $b) {
+ $coll = collator_create( 'fr_FR' );
+ return collator_compare($coll, $a, $b);
}
\ No newline at end of file
diff --git a/modeles/agenda.html b/modeles/agenda.html
index d919a79..a2bf21a 100644
--- a/modeles/agenda.html
+++ b/modeles/agenda.html
@@ -1,16 +1,13 @@
-
-
-[(#SET{url,#VAL{'http://www.agendadulibre.org/maps.json?tag='}|concat{#ENV{tag}}|concat{'&future=false®ion='}|concat{#CLE}})]
-
- #VALEUR
-
-
- [(#SET{evt,#VALEUR|table_valeur{properties}})]
- - [[(#GET{evt/start_time}|nom_jour)] (#GET{evt/start_time}|affdate)[ à (#GET{evt/start_time}|heures)][:(#GET{evt/start_time}|minutes)]]
- [(#GET{evt/name})]
- à [(#GET{evt/city})]
-
-
-
-
-
\ No newline at end of file
+#SET{repartition, #MES_REPARTITION{#ENV{tag}}}
+
+#CLE
+
+
+[(#SET{evt,#VALEUR|table_valeur{properties}})]
+ - [[(#GET{evt/start_time}|nom_jour)] (#GET{evt/start_time}|affdate_jourcourt)[ à (#GET{evt/start_time}|heures)][:(#GET{evt/start_time}|minutes)]]
+ [(#GET{evt/name})]
+ à [(#GET{evt/city})]
+
+
+
+
diff --git a/modeles/agenda_compteur.html b/modeles/agenda_compteur.html
index b86aea5..ee1a38a 100644
--- a/modeles/agenda_compteur.html
+++ b/modeles/agenda_compteur.html
@@ -1,7 +1,2 @@
-[(#SET{url,#VAL{'http://www.agendadulibre.org/maps.json?tag='}|concat{#ENV{tag}}|concat{'&future=false'}})]
-
-
-
-
-#TOTAL_BOUCLE
-
\ No newline at end of file
+#SET{repartition, #MES_REPARTITION{#ENV{tag}}}
+#GET{repartition/total}
\ No newline at end of file