Subversion Repositories eFlore/Applications.cel

Rev

Rev 1927 | Rev 1933 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1927 Rev 1929
Line 150... Line 150...
150
	public $id_utilisateur = NULL;
150
    public $id_utilisateur = NULL;
Line 151... Line 151...
151
 
151
 
152
	// erreurs d'import
152
    // erreurs d'import
Line -... Line 153...
-
 
153
    public $bilan = Array();
-
 
154
 
Line 153... Line 155...
153
	public $bilan = Array();
155
    // cache (pour traiterLocalisation() pour l'instant)
154
 
156
    static $cache = Array('geo' => array());
155
 
157
 
Line 809... Line 811...
809
		if(empty($ligne[C_CE_ZONE_GEO])) $ligne[C_CE_ZONE_GEO] = NULL;
811
	if(empty($ligne[C_CE_ZONE_GEO])) $ligne[C_CE_ZONE_GEO] = NULL;
Line 810... Line 812...
810
 
812
 
811
	    $identifiant_commune = trim($ligne[C_ZONE_GEO]);
813
	$identifiant_commune = trim($ligne[C_ZONE_GEO]);
812
		if(!$identifiant_commune) {
814
	if(!$identifiant_commune) {
-
 
815
	    $departement = trim($ligne[C_CE_ZONE_GEO]);
813
			$departement = trim($ligne[C_CE_ZONE_GEO]);
816
 
814
			if(strpos($departement, "INSEE-C:", 0) === 0) {
817
	    if(strpos($departement, "INSEE-C:", 0) === 0) {
-
 
818
		$localisation[C_CE_ZONE_GEO] = trim($ligne[C_CE_ZONE_GEO]);
-
 
819
		if(array_key_exists($localisation[C_CE_ZONE_GEO], self::$cache['geo'])) {
-
 
820
		    $localisation[C_ZONE_GEO] = self::$cache['geo'][$localisation[C_CE_ZONE_GEO]];
-
 
821
		}
815
				$localisation[C_CE_ZONE_GEO] = trim($ligne[C_CE_ZONE_GEO]);
822
		else {
816
				$nom = Cel::db()->requeter(sprintf("SELECT nom FROM cel_zones_geo WHERE code = %s LIMIT 1",
823
		    $nom = Cel::db()->requeter(sprintf("SELECT nom FROM cel_zones_geo WHERE code = %s LIMIT 1",
817
																		self::quoteNonNull(substr($localisation[C_CE_ZONE_GEO], strlen("INSEE-C:")))));
824
						       self::quoteNonNull(substr($localisation[C_CE_ZONE_GEO], strlen("INSEE-C:")))));
-
 
825
		    if($nom) $localisation[C_ZONE_GEO] = $nom[0]['nom'];
-
 
826
		    self::$cache['geo'][$localisation[C_CE_ZONE_GEO]] = @$nom[0]['nom'];
818
				if($nom) $localisation[C_ZONE_GEO] = $nom[0]['nom'];
827
		}
819
				return;
828
		return;
Line 820... Line 829...
820
			}
829
	    }
821
 
830
 
822
			if(!is_numeric($departement)) {
831
	    if(!is_numeric($departement)) {
823
				$localisation[C_CE_ZONE_GEO] = $ligne[C_CE_ZONE_GEO];
832
		$localisation[C_CE_ZONE_GEO] = $ligne[C_CE_ZONE_GEO];
Line -... Line 833...
-
 
833
		return;
-
 
834
	    }
-
 
835
 
-
 
836
	    $cache_attempted = FALSE;
-
 
837
	    if(array_key_exists($departement, self::$cache['geo'])) {
-
 
838
		$cache_attempted = TRUE;
-
 
839
		if(self::$cache['geo'][$departement][0] && self::$cache['geo'][$departement][1]) {
-
 
840
		    $localisation[C_ZONE_GEO] = self::$cache['geo'][$departement][0];
-
 
841
		    $localisation[C_CE_ZONE_GEO] = self::$cache['geo'][$departement][1];
-
 
842
		    return;
824
				return;
843
		}
825
			}
844
	    }
826
 
845
 
827
			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",
846
	    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",
-
 
847
										      self::quoteNonNull($departement)))) ) {
828
																 self::quoteNonNull($departement)))) ) {
848
		$localisation[C_ZONE_GEO] = $resultat_commune[0]['nom'];
829
				$localisation[C_ZONE_GEO] = $resultat_commune[0]['nom'];
849
		$localisation[C_CE_ZONE_GEO] = $resultat_commune[0]['code'];
830
				$localisation[C_CE_ZONE_GEO] = $resultat_commune[0]['code'];
850
		self::$cache['geo'][$departement] = array($resultat_commune[0]['nom'], $resultat_commune[0]['code']);
831
				return;
851
		return;
832
			}
852
	    }
Line 869... Line 889...
869
			// on prend le risque ici de retourner une mauvaise Commune
889
	    // on prend le risque ici de retourner une mauvaise Commune
870
			$nom_commune = str_replace(" ", "%", iconv('UTF-8', 'ASCII//TRANSLIT', $identifiant_commune));
890
	    $nom_commune = str_replace(" ", "%", iconv('UTF-8', 'ASCII//TRANSLIT', $identifiant_commune));
871
	 	    $requete = sprintf("%s WHERE nom LIKE %s", $select, self::quoteNonNull($nom_commune.'%'));
891
	    $requete = sprintf("%s WHERE nom LIKE %s", $select, self::quoteNonNull($nom_commune.'%'));
872
		}
892
	}
Line -... Line 893...
-
 
893
 
-
 
894
 
-
 
895
	if(array_key_exists($identifiant_commune, self::$cache['geo'])) {
-
 
896
	    $resultat_commune = self::$cache['geo'][$identifiant_commune];
-
 
897
	}
873
	
898
	else {
-
 
899
	    $resultat_commune = Cel::db()->requeter($requete);
-
 
900
	    self::$cache['geo'][$identifiant_commune] = $resultat_commune;
874
		$resultat_commune = Cel::db()->requeter($requete);
901
	}
875
		// TODO: levenstein sort ?
902
	// TODO: levenstein sort ?
Line 876... Line 903...
876
		// TODO: count résultat !
903
	// TODO: count résultat !
877
 
904