Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 1696 → Rev 1697

/trunk/jrest/services/ImportXLS.php
706,10 → 706,96
return $r;
}
 
 
static function traiterLocalisation($ligne, Array &$localisation, $cel) {
$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_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
}
 
 
if(!is_numeric($departement)) {
$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;
if(strlen($departement) == 5) $departement = "INSEE-C:" . $departement;
// if(strlen($departement) <= 9) return "INSEE-C:0" . $departement; // ? ... TODO
 
$departement = trim($departement); // TODO
 
$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
 
}
 
 
$select = "SELECT DISTINCT nom, code FROM cel_zones_geo";
if (preg_match('/(.*) \((\d+)\)/', $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, $cel->quoteNonNull($nom_commune), $cel->quoteNonNull($code_commune.'%'));
}
elseif (preg_match('/^(\d+|(2[ab]\d+))$/i', $identifiant_commune, $elements)) {
// Code insee seul
$code_insee_commune=$elements[1];
$requete = sprintf("%s WHERE code = %s", $select, $cel->quoteNonNull($code_insee_commune));
}
else {
// Commune seule (le departement sera recupere dans la colonne departement si elle est presente)
// on prend le risque ici de retourner une mauvaise Commune
$nom_commune = str_replace(" ", "%", iconv('UTF-8', 'ASCII//TRANSLIT', $identifiant_commune));
$requete = sprintf("%s WHERE nom LIKE %s", $select, $cel->quoteNonNull($nom_commune.'%'));
}
$resultat_commune = $cel->requeter($requete);
// TODO: levenstein sort ?
 
// cas de la commune introuvable dans le référentiel
// réinitialisation aux valeurs du fichier XLS
if(! $resultat_commune) {
$localisation[C_ZONE_GEO] = trim($ligne[C_ZONE_GEO]);
$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'];
}
 
$departement = &$localisation[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];
}
 
 
if(!is_numeric($departement)) {
$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;
if(strlen($departement) == 5) $departement = "INSEE-C:" . $departement;
// if(strlen($departement) <= 9) return "INSEE-C:0" . $departement; // ? ... TODO
 
$departement = trim($departement); // TODO
 
$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
}
 
/*
static function traiterLocalisation($ligne, Array &$localisation, $cel) {
$identifiant_commune = trim($ligne[C_ZONE_GEO]);
if(!$identifiant_commune) {
$departement = trim($ligne[C_CE_ZONE_GEO]);
goto testdepartement;
}
 
764,9 → 850,9
$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
}
*/
 
 
 
/* HELPERS */
 
// http://stackoverflow.com/questions/348410/sort-an-array-based-on-another-array