Nouvelle répartition avec l'arborescence des régions

This commit is contained in:
root 2018-03-18 18:15:39 +01:00
parent b9b7f416df
commit d3f8ce3d14
3 changed files with 77 additions and 7 deletions

View File

@ -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.'&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;
$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
*************************************/

View File

@ -1,8 +1,10 @@
#SET{repartition, #MES_REPARTITION{#ENV{tag}}}
<BOUCLE_repartition(DATA){source tableau, #GET{repartition/regions}}>
<h4 class="spip">#CLE</h4>
#SET{repartition, #MES_REPARTITION2{#ENV{tag}}}
<BOUCLE_repartition(DATA){source tableau, #GET{repartition/pays}}>
<h3 class="spip">#VALEUR{name}</h3>
<BOUCLE_sousregions(DATA){source tableau, #VALEUR{sousregions}}>
<h4 class="spip">#VALEUR{name}</h4>
<ul>
<BOUCLE_evenements(DATA) {source tableau, #VALEUR}{par properties/start_time}>
<BOUCLE_evenements(DATA) {source tableau, #VALEUR{evenements}}{par properties/start_time}>
[(#SET{evt,#VALEUR|table_valeur{properties}})]
<li>[[(#GET{evt/start_time}|nom_jour)] (#GET{evt/start_time}|affdate_jourcourt)[ à (#GET{evt/start_time}|heures)][:(#GET{evt/start_time}|minutes)]]
<a href="http://www.agendadulibre.org/events/[(#GET{evt/id})]">[(#GET{evt/name})]</a>
@ -10,4 +12,5 @@
</li>
</BOUCLE_evenements>
</ul>
</BOUCLE_sousregions>
</BOUCLE_repartition>

View File

@ -1,2 +1,2 @@
#SET{repartition, #MES_REPARTITION{#ENV{tag}}}
#GET{repartition/total}
#SET{repartition, #MES_REPARTITION2{#ENV{tag}}}
#GET{repartition/total}