Subversion Repositories eFlore/Applications.cel

Rev

Rev 1792 | Rev 1812 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1792 Rev 1797
Line 768... Line 768...
768
							   Cel::db()->proteger(str_replace(' ', '% ', $nom))));
768
							   Cel::db()->proteger(str_replace(' ', '% ', $nom))));
769
		return $r;
769
		return $r;
770
	}
770
	}
Line -... Line 771...
-
 
771
 
-
 
772
 
-
 
773
	/*
-
 
774
	 * TODO: analyse rigoureuse:
-
 
775
	 * == Identifiant Commune
-
 
776
	 * - INSEE-C:\d{5}
-
 
777
	 * - \d{5}
-
 
778
	 * - \d{2}
-
 
779
	 * == Commune
-
 
780
	 * - \w+ (\d{2})
-
 
781
	 * - \w+ (\d{5})
-
 
782
	 * - \w+
771
 
783
	 *
772
 
784
	*/
773
	static function traiterLocalisation($ligne, Array &$localisation) {
785
	static function traiterLocalisation($ligne, Array &$localisation) {
Line 774... Line 786...
774
		if(empty($ligne[C_ZONE_GEO])) $ligne[C_ZONE_GEO] = NULL;
786
		if(empty($ligne[C_ZONE_GEO])) $ligne[C_ZONE_GEO] = NULL;
775
		if(empty($ligne[C_CE_ZONE_GEO])) $ligne[C_CE_ZONE_GEO] = NULL;
787
		if(empty($ligne[C_CE_ZONE_GEO])) $ligne[C_CE_ZONE_GEO] = NULL;
776
 
788
 
777
	    $identifiant_commune = trim($ligne[C_ZONE_GEO]);
789
	    $identifiant_commune = trim($ligne[C_ZONE_GEO]);
778
		if(!$identifiant_commune) {
790
		if(!$identifiant_commune) {
-
 
791
			$departement = trim($ligne[C_CE_ZONE_GEO]);
-
 
792
			if(strpos($departement, "INSEE-C:", 0) === 0) {
779
			$departement = trim($ligne[C_CE_ZONE_GEO]);
793
				$localisation[C_CE_ZONE_GEO] = trim($ligne[C_CE_ZONE_GEO]);
-
 
794
				$nom = Cel::db()->requeter(sprintf("SELECT nom FROM cel_zones_geo WHERE code = %s LIMIT 1",
780
			if(strpos($departement, "INSEE-C:", 0) === 0) {
795
																		self::quoteNonNull(substr($localisation[C_CE_ZONE_GEO], strlen("INSEE-C:")))));
Line 781... Line 796...
781
				$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
796
				if($nom) $localisation[C_ZONE_GEO] = $nom[0]['nom'];
782
				$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
797
				return;
783
			}
798
			}
784
 
799
 
Line 785... Line 800...
785
 
800
 
786
			if(!is_numeric($departement)) {
801
			if(!is_numeric($departement)) {
787
				$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
802
				$localisation[C_CE_ZONE_GEO] = $ligne[C_CE_ZONE_GEO];
Line 788... Line 803...
788
				$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
803
				return;
Line 789... Line -...
789
			}
-
 
790
 
804
			}
791
			if(strlen($departement) == 4) $departement = "INSEE-C:0" . $departement;
805
 
792
			if(strlen($departement) == 5) $departement = "INSEE-C:" . $departement;
806
			if(strlen($departement) == 4) $departement = "INSEE-C:0" . $departement;
Line 793... Line 807...
793
			// if(strlen($departement) <= 9) return "INSEE-C:0" . $departement; // ? ... TODO
807
			if(strlen($departement) == 5) $departement = "INSEE-C:" . $departement;
Line 794... Line 808...
794
 
808
			// if(strlen($departement) <= 9) return "INSEE-C:0" . $departement; // ? ... TODO
795
			$departement = trim($departement); // TODO
809
 
796
 
810
			$departement = trim($departement); // TODO
797
			$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
811
 
-
 
812
			$localisation[C_CE_ZONE_GEO] = $ligne[C_CE_ZONE_GEO];
798
			$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
813
			return;
-
 
814
		}
-
 
815
 
-
 
816
 
-
 
817
		$select = "SELECT DISTINCT nom, code  FROM cel_zones_geo";
-
 
818
	
799
			return;
819
		if (preg_match('/(.+) \((\d{1,5})\)/', $identifiant_commune, $elements)) {
-
 
820
			// commune + departement : montpellier (34)
-
 
821
			$nom_commune=$elements[1];
-
 
822
			$code_commune=$elements[2];
800
		}
823
			if(strlen($code_commune) <= 2) {
801
 
824
				$requete = sprintf("%s WHERE nom = %s AND code LIKE %s",
802
 
825
								   $select, self::quoteNonNull($nom_commune),
803
		$select = "SELECT DISTINCT nom, code  FROM cel_zones_geo";
826
								   self::quoteNonNull($code_commune.'%'));
804
	
827
			}
Line 821... Line 844...
821
	 	    $requete = sprintf("%s WHERE nom LIKE %s", $select, self::quoteNonNull($nom_commune.'%'));
844
	 	    $requete = sprintf("%s WHERE nom LIKE %s", $select, self::quoteNonNull($nom_commune.'%'));
822
		}
845
		}
Line 823... Line 846...
823
	
846
	
824
		$resultat_commune = Cel::db()->requeter($requete);
847
		$resultat_commune = Cel::db()->requeter($requete);
-
 
848
		// TODO: levenstein sort ?
Line 825... Line 849...
825
		// TODO: levenstein sort ?
849
		// TODO: count résultat !
826
 
850
 
827
		// cas de la commune introuvable dans le référentiel
851
		// cas de la commune introuvable dans le référentiel
828
		// réinitialisation aux valeurs du fichier XLS
852
		// réinitialisation aux valeurs du fichier XLS
829
		if(! $resultat_commune) {
853
		if(! $resultat_commune) {
830
			$localisation[C_ZONE_GEO] = trim($ligne[C_ZONE_GEO]);
854
			$localisation[C_ZONE_GEO] = trim($ligne[C_ZONE_GEO]);
831
			$localisation[C_CE_ZONE_GEO] = trim($ligne[C_CE_ZONE_GEO]);
855
			$localisation[C_CE_ZONE_GEO] = trim($ligne[C_CE_ZONE_GEO]);
832
		} else {
856
		} else {
-
 
857
			$localisation[C_ZONE_GEO] = $resultat_commune[0]['nom'];
833
			$localisation[C_ZONE_GEO] = $resultat_commune[0]['nom'];
858
			$localisation[C_CE_ZONE_GEO] = "INSEE-C:" . $resultat_commune[0]['code'];
Line 834... Line 859...
834
			$localisation[C_CE_ZONE_GEO] = $resultat_commune[0]['code'];
859
			return;
Line 835... Line 860...
835
		}
860
		}