From bf697ab2de9b8c970c17d8ccd75de196ee07b9ff Mon Sep 17 00:00:00 2001 From: root Date: Thu, 1 Feb 2018 22:47:46 +0100 Subject: [PATCH] =?UTF-8?q?Modification=20du=20mode=20de=20r=C3=A9cup?= =?UTF-8?q?=C3=A9ration=20des=20r=C3=A9gions=20pour=20ne=20plus=20=C3=AAtr?= =?UTF-8?q?e=20d=C3=A9pendant=20d'une=20liste=20fixe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mes_fonctions.php | 64 ++++++++++++++++++++++++++++++++++++ modeles/agenda.html | 29 ++++++++-------- modeles/agenda_compteur.html | 9 ++--- 3 files changed, 79 insertions(+), 23 deletions(-) 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