Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1797 → Rev 1796

/trunk/jrest/services/ImportXLS.php
770,18 → 770,6
}
 
 
/*
* TODO: analyse rigoureuse:
* == Identifiant Commune
* - INSEE-C:\d{5}
* - \d{5}
* - \d{2}
* == Commune
* - \w+ (\d{2})
* - \w+ (\d{5})
* - \w+
*
*/
static function traiterLocalisation($ligne, Array &$localisation) {
if(empty($ligne[C_ZONE_GEO])) $ligne[C_ZONE_GEO] = NULL;
if(empty($ligne[C_CE_ZONE_GEO])) $ligne[C_CE_ZONE_GEO] = NULL;
790,17 → 778,14
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]);
$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'];
return;
$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
}
 
 
if(!is_numeric($departement)) {
$localisation[C_CE_ZONE_GEO] = $ligne[C_CE_ZONE_GEO];
return;
$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
}
 
if(strlen($departement) == 4) $departement = "INSEE-C:0" . $departement;
809,7 → 794,8
 
$departement = trim($departement); // TODO
 
$localisation[C_CE_ZONE_GEO] = $ligne[C_CE_ZONE_GEO];
$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
return;
}
 
816,21 → 802,12
 
$select = "SELECT DISTINCT nom, code FROM cel_zones_geo";
if (preg_match('/(.+) \((\d{1,5})\)/', $identifiant_commune, $elements)) {
if (preg_match('/(.+) \((\d+)\)/', $identifiant_commune, $elements)) {
// commune + departement : montpellier (34)
$nom_commune=$elements[1];
$code_commune=$elements[2];
if(strlen($code_commune) <= 2) {
$requete = sprintf("%s WHERE nom = %s AND code LIKE %s",
$select, self::quoteNonNull($nom_commune),
self::quoteNonNull($code_commune.'%'));
}
else {
$requete = sprintf("%s WHERE nom = %s AND code = %d",
$select, self::quoteNonNull($nom_commune),
$code_commune);
}
 
$requete = sprintf("%s WHERE nom = %s AND code LIKE %s",
$select, self::quoteNonNull($nom_commune), self::quoteNonNull($code_commune.'%'));
}
elseif (preg_match('/^(\d+|(2[ab]\d+))$/i', $identifiant_commune, $elements)) {
// Code insee seul
846,7 → 823,6
$resultat_commune = Cel::db()->requeter($requete);
// TODO: levenstein sort ?
// TODO: count résultat !
 
// cas de la commune introuvable dans le référentiel
// réinitialisation aux valeurs du fichier XLS
855,8 → 831,7
$localisation[C_CE_ZONE_GEO] = trim($ligne[C_CE_ZONE_GEO]);
} else {
$localisation[C_ZONE_GEO] = $resultat_commune[0]['nom'];
$localisation[C_CE_ZONE_GEO] = "INSEE-C:" . $resultat_commune[0]['code'];
return;
$localisation[C_CE_ZONE_GEO] = $resultat_commune[0]['code'];
}
 
$departement = &$localisation[C_CE_ZONE_GEO];