Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1796 → Rev 1797

/trunk/jrest/services/ImportXLS.php
770,6 → 770,18
}
 
 
/*
* 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;
778,14 → 790,17
if(!$identifiant_commune) {
$departement = trim($ligne[C_CE_ZONE_GEO]);
if(strpos($departement, "INSEE-C:", 0) === 0) {
$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
$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;
}
 
 
if(!is_numeric($departement)) {
$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $ligne[C_CE_ZONE_GEO];
return;
}
 
if(strlen($departement) == 4) $departement = "INSEE-C:0" . $departement;
794,8 → 809,7
 
$departement = trim($departement); // TODO
 
$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $ligne[C_CE_ZONE_GEO];
return;
}
 
802,12 → 816,21
 
$select = "SELECT DISTINCT nom, code FROM cel_zones_geo";
if (preg_match('/(.+) \((\d+)\)/', $identifiant_commune, $elements)) {
if (preg_match('/(.+) \((\d{1,5})\)/', $identifiant_commune, $elements)) {
// commune + departement : montpellier (34)
$nom_commune=$elements[1];
$code_commune=$elements[2];
$requete = sprintf("%s WHERE nom = %s AND code LIKE %s",
$select, self::quoteNonNull($nom_commune), self::quoteNonNull($code_commune.'%'));
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);
}
 
}
elseif (preg_match('/^(\d+|(2[ab]\d+))$/i', $identifiant_commune, $elements)) {
// Code insee seul
823,6 → 846,7
$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
831,7 → 855,8
$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] = $resultat_commune[0]['code'];
$localisation[C_CE_ZONE_GEO] = "INSEE-C:" . $resultat_commune[0]['code'];
return;
}
 
$departement = &$localisation[C_CE_ZONE_GEO];