From d3f8ce3d142cc2e8cee79d8a54af4728d0e99b6a Mon Sep 17 00:00:00 2001 From: root Date: Sun, 18 Mar 2018 18:15:39 +0100 Subject: [PATCH] =?UTF-8?q?Nouvelle=20r=C3=A9partition=20avec=20l'arboresc?= =?UTF-8?q?ence=20des=20r=C3=A9gions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mes_fonctions.php | 69 +++++++++++++++++++++++++++++++++++- modeles/agenda.html | 11 +++--- modeles/agenda_compteur.html | 4 +-- 3 files changed, 77 insertions(+), 7 deletions(-) diff --git a/mes_fonctions.php b/mes_fonctions.php index 29a1035..c9bb955 100644 --- a/mes_fonctions.php +++ b/mes_fonctions.php @@ -44,7 +44,7 @@ function liste_regions(){ * défini dans ce fichier mes_fonctions.php ***********************************/ define("MES", "MES"); -$GLOBALS[MES] = array("repartition" => false); +$GLOBALS[MES] = array("repartition" => false, "repartition2" => false); /************************************ * Balise récupérant les évènements répartis par région @@ -58,6 +58,18 @@ function balise_MES_REPARTITION($p) { 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 : @@ -94,6 +106,61 @@ function mes_balise_Repartition($tag) { 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 *************************************/ diff --git a/modeles/agenda.html b/modeles/agenda.html index a2bf21a..409680e 100644 --- a/modeles/agenda.html +++ b/modeles/agenda.html @@ -1,8 +1,10 @@ -#SET{repartition, #MES_REPARTITION{#ENV{tag}}} - -

#CLE

+#SET{repartition, #MES_REPARTITION2{#ENV{tag}}} + +

#VALEUR{name}

+ +

#VALEUR{name}

    - + [(#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})] @@ -10,4 +12,5 @@
+ diff --git a/modeles/agenda_compteur.html b/modeles/agenda_compteur.html index ee1a38a..8db4e83 100644 --- a/modeles/agenda_compteur.html +++ b/modeles/agenda_compteur.html @@ -1,2 +1,2 @@ -#SET{repartition, #MES_REPARTITION{#ENV{tag}}} -#GET{repartition/total} \ No newline at end of file +#SET{repartition, #MES_REPARTITION2{#ENV{tag}}} +#GET{repartition/total}