Modification du mode de récupération des régions pour ne plus être dépendant d'une liste fixe

This commit is contained in:
root 2018-02-01 22:47:46 +01:00
parent cb1cf8a3f9
commit bf697ab2de
3 changed files with 79 additions and 23 deletions

View File

@ -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);
}

View File

@ -1,16 +1,13 @@
<BOUCLE_region(DATA){source tableau,#LISTE_REGIONS}>
[(#SET{url,#VAL{'http://www.agendadulibre.org/maps.json?tag='}|concat{#ENV{tag}}|concat{'&future=false&region='}|concat{#CLE}})]
<B_agenda>
<h4 class="spip">#VALEUR </h4>
<ul>
<BOUCLE_agenda(DATA) {source json, #GET{url} }{par properties/start_time}>
[(#SET{evt,#VALEUR|table_valeur{properties}})]
<li>[[(#GET{evt/start_time}|nom_jour)] (#GET{evt/start_time}|affdate)[ à (#GET{evt/start_time}|heures)][:(#GET{evt/start_time}|minutes)]]
<a href="http://www.agendadulibre.org/events/[(#GET{evt/id})]">[(#GET{evt/name})]</a>
à [(#GET{evt/city})]
</li>
</BOUCLE_agenda>
</ul>
</B_agenda>
</BOUCLE_region>
#SET{repartition, #MES_REPARTITION{#ENV{tag}}}
<BOUCLE_repartition(DATA){source tableau, #GET{repartition/regions}}>
<h4 class="spip">#CLE</h4>
<ul>
<BOUCLE_evenements(DATA) {source tableau, #VALEUR}{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>
à [(#GET{evt/city})]
</li>
</BOUCLE_evenements>
</ul>
</BOUCLE_repartition>

View File

@ -1,7 +1,2 @@
[(#SET{url,#VAL{'http://www.agendadulibre.org/maps.json?tag='}|concat{#ENV{tag}}|concat{'&future=false'}})]
<BOUCLE_agenda(DATA) {source json, #GET{url} }>
</BOUCLE_agenda>
#TOTAL_BOUCLE
</B_agenda>
#SET{repartition, #MES_REPARTITION{#ENV{tag}}}
#GET{repartition/total}