Subversion Repositories eFlore/Applications.cel

Compare Revisions

Regard whitespace Rev 1928 → Rev 1929

/trunk/jrest/services/ImportXLS.php
152,6 → 152,8
// erreurs d'import
public $bilan = Array();
 
// cache (pour traiterLocalisation() pour l'instant)
static $cache = Array('geo' => array());
 
function ImportXLS($config) {
parent::__construct($config);
811,11 → 813,18
$identifiant_commune = trim($ligne[C_ZONE_GEO]);
if(!$identifiant_commune) {
$departement = trim($ligne[C_CE_ZONE_GEO]);
 
if(strpos($departement, "INSEE-C:", 0) === 0) {
$localisation[C_CE_ZONE_GEO] = trim($ligne[C_CE_ZONE_GEO]);
if(array_key_exists($localisation[C_CE_ZONE_GEO], self::$cache['geo'])) {
$localisation[C_ZONE_GEO] = self::$cache['geo'][$localisation[C_CE_ZONE_GEO]];
}
else {
$nom = Cel::db()->requeter(sprintf("SELECT nom FROM cel_zones_geo WHERE code = %s LIMIT 1",
self::quoteNonNull(substr($localisation[C_CE_ZONE_GEO], strlen("INSEE-C:")))));
if($nom) $localisation[C_ZONE_GEO] = $nom[0]['nom'];
self::$cache['geo'][$localisation[C_CE_ZONE_GEO]] = @$nom[0]['nom'];
}
return;
}
 
824,10 → 833,21
return;
}
 
if( ($resultat_commune = Cel::db()->requeter(sprintf("SELECT DISTINCT nom, CONCAT('INSEE-C:', code) AS code FROM cel_zones_geo WHERE code = %s LIMIT 1",
$cache_attempted = FALSE;
if(array_key_exists($departement, self::$cache['geo'])) {
$cache_attempted = TRUE;
if(self::$cache['geo'][$departement][0] && self::$cache['geo'][$departement][1]) {
$localisation[C_ZONE_GEO] = self::$cache['geo'][$departement][0];
$localisation[C_CE_ZONE_GEO] = self::$cache['geo'][$departement][1];
return;
}
}
 
if(! $cache_attempted && ($resultat_commune = Cel::db()->requeter(sprintf("SELECT DISTINCT nom, CONCAT('INSEE-C:', code) AS code FROM cel_zones_geo WHERE code = %s LIMIT 1",
self::quoteNonNull($departement)))) ) {
$localisation[C_ZONE_GEO] = $resultat_commune[0]['nom'];
$localisation[C_CE_ZONE_GEO] = $resultat_commune[0]['code'];
self::$cache['geo'][$departement] = array($resultat_commune[0]['nom'], $resultat_commune[0]['code']);
return;
}
;
871,7 → 891,14
$requete = sprintf("%s WHERE nom LIKE %s", $select, self::quoteNonNull($nom_commune.'%'));
}
 
if(array_key_exists($identifiant_commune, self::$cache['geo'])) {
$resultat_commune = self::$cache['geo'][$identifiant_commune];
}
else {
$resultat_commune = Cel::db()->requeter($requete);
self::$cache['geo'][$identifiant_commune] = $resultat_commune;
}
// TODO: levenstein sort ?
// TODO: count résultat !