Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 1688 Rev 1697
Line 704... Line 704...
704
							   $cel->proteger($nom),
704
							   $cel->proteger($nom),
705
							   $cel->proteger(str_replace(' ', '% ', $nom))));
705
							   $cel->proteger(str_replace(' ', '% ', $nom))));
706
		return $r;
706
		return $r;
707
	}
707
	}
Line -... Line 708...
-
 
708
 
-
 
709
 
-
 
710
	static function traiterLocalisation($ligne, Array &$localisation, $cel) {
-
 
711
	    $identifiant_commune = trim($ligne[C_ZONE_GEO]);
-
 
712
		if(!$identifiant_commune) {
-
 
713
			$departement = trim($ligne[C_CE_ZONE_GEO]);
-
 
714
			if(strpos($departement, "INSEE-C:", 0) === 0) {
-
 
715
				$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
-
 
716
				$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
-
 
717
			}
-
 
718
 
-
 
719
 
-
 
720
			if(!is_numeric($departement)) {
-
 
721
				$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
-
 
722
				$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
-
 
723
			}
-
 
724
 
-
 
725
			if(strlen($departement) == 4) $departement = "INSEE-C:0" . $departement;
-
 
726
			if(strlen($departement) == 5) $departement = "INSEE-C:" . $departement;
-
 
727
			// if(strlen($departement) <= 9) return "INSEE-C:0" . $departement; // ? ... TODO
-
 
728
 
-
 
729
			$departement = trim($departement); // TODO
-
 
730
 
-
 
731
			$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
-
 
732
			$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
-
 
733
 
-
 
734
		}
-
 
735
 
-
 
736
 
-
 
737
		$select = "SELECT DISTINCT nom, code  FROM cel_zones_geo";
-
 
738
	
-
 
739
		if (preg_match('/(.*) \((\d+)\)/', $identifiant_commune, $elements)) {
-
 
740
			// commune + departement : montpellier (34)
-
 
741
			$nom_commune=$elements[1];
-
 
742
			$code_commune=$elements[2];
-
 
743
	 	    $requete = sprintf("%s WHERE nom = %s AND code LIKE %s",
-
 
744
							   $select, $cel->quoteNonNull($nom_commune), $cel->quoteNonNull($code_commune.'%'));
-
 
745
		}
-
 
746
		elseif (preg_match('/^(\d+|(2[ab]\d+))$/i', $identifiant_commune, $elements)) {
-
 
747
			// Code insee seul  
-
 
748
			$code_insee_commune=$elements[1];
-
 
749
	 	    $requete = sprintf("%s WHERE code = %s", $select, $cel->quoteNonNull($code_insee_commune));
-
 
750
		}
-
 
751
		else {
-
 
752
			// Commune seule (le departement sera recupere dans la colonne departement si elle est presente)
-
 
753
			// on prend le risque ici de retourner une mauvaise Commune
-
 
754
			$nom_commune = str_replace(" ", "%", iconv('UTF-8', 'ASCII//TRANSLIT', $identifiant_commune));
-
 
755
	 	    $requete = sprintf("%s WHERE nom LIKE %s", $select, $cel->quoteNonNull($nom_commune.'%'));
-
 
756
		}
-
 
757
	
-
 
758
		$resultat_commune = $cel->requeter($requete);
-
 
759
		// TODO: levenstein sort ?
-
 
760
 
-
 
761
		// cas de la commune introuvable dans le référentiel
-
 
762
		// réinitialisation aux valeurs du fichier XLS
-
 
763
		if(! $resultat_commune) {
-
 
764
			$localisation[C_ZONE_GEO] = trim($ligne[C_ZONE_GEO]);
-
 
765
			$localisation[C_CE_ZONE_GEO] = trim($ligne[C_CE_ZONE_GEO]);
-
 
766
		} else {
-
 
767
			$localisation[C_ZONE_GEO] = $resultat_commune[0]['nom'];
-
 
768
			$localisation[C_CE_ZONE_GEO] = $resultat_commune[0]['code'];
-
 
769
		}
-
 
770
 
-
 
771
		$departement = &$localisation[C_CE_ZONE_GEO];
-
 
772
 
-
 
773
		if(strpos($departement, "INSEE-C:", 0) === 0) {
-
 
774
			$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
-
 
775
			$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
-
 
776
		}
-
 
777
 
-
 
778
 
-
 
779
		if(!is_numeric($departement)) {
-
 
780
			$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
-
 
781
			$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
-
 
782
		}
-
 
783
 
-
 
784
		if(strlen($departement) == 4) $departement = "INSEE-C:0" . $departement;
-
 
785
		if(strlen($departement) == 5) $departement = "INSEE-C:" . $departement;
-
 
786
		// if(strlen($departement) <= 9) return "INSEE-C:0" . $departement; // ? ... TODO
-
 
787
 
-
 
788
		$departement = trim($departement); // TODO
-
 
789
 
-
 
790
		$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
-
 
791
		$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
-
 
792
	}
-
 
793
 
708
 
794
	/*
709
	static function traiterLocalisation($ligne, Array &$localisation, $cel) {
795
	static function traiterLocalisation($ligne, Array &$localisation, $cel) {
710
	    $identifiant_commune = trim($ligne[C_ZONE_GEO]);
796
	    $identifiant_commune = trim($ligne[C_ZONE_GEO]);
711
		if(!$identifiant_commune) {
797
		if(!$identifiant_commune) {
712
			$departement = trim($ligne[C_CE_ZONE_GEO]);
798
			$departement = trim($ligne[C_CE_ZONE_GEO]);
Line 762... Line 848...
762
 
848
 
763
	protectloc:
849
	protectloc:
764
		$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
850
		$localisation[C_ZONE_GEO] = $localisation[C_ZONE_GEO];
765
		$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
851
		$localisation[C_CE_ZONE_GEO] = $localisation[C_CE_ZONE_GEO];
766
	}
852
	}
Line 767... Line 853...
767
 
853
*/
Line 768... Line 854...
768
 
854