Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2526 Rev 2527
Line 1... Line 1...
1
<?php
1
<?php
2
class Dao extends Bdd {
2
class Dao extends Bdd {
Line 3... Line 3...
3
 
3
 
Line 4... Line 4...
4
	private $temps_derniere_requete = 0;
4
	private $temps_derniere_requete = 0;
-
 
5
 
-
 
6
	public function rechercherCoordonnees($conditions = array()) {
-
 
7
		if(!empty($conditions)) {
-
 
8
			$where = 'WHERE '.implode(' AND ', $conditions);		
5
 
9
		}
6
	public function rechercherCoordonnees() {
10
		
-
 
11
		$requete = "SELECT longitude, latitude ".
7
		$requete = "SELECT longitude, latitude ".
12
			"FROM cel_obs ".
-
 
13
			$where.
8
			"FROM cel_obs ".
14
			"GROUP BY longitude , latitude ";
9
			"GROUP BY longitude , latitude ";
15
		
10
		$resultat = $this->recupererTous($requete);
16
		$resultat = $this->recupererTous($requete);
11
		$this->reinitialiserTempsDerniereRequete();
17
		$this->reinitialiserTempsDerniereRequete();
Line 12... Line 18...
12
		return $resultat;
18
		return $resultat;
13
	}
-
 
14
 
19
	}
15
	public function rechercherCoordonneesSansCorrespondances() {
20
 
16
		$requete = 'SELECT longitude, latitude '.
21
	public function rechercherCoordonneesSansCorrespondances() {	
17
			'FROM cel_obs '.
22
		$conditions = array(
18
			"WHERE code_insee_calcule = '' ".
23
						$this->getConditionCoordonneesValides(),
-
 
24
						$this->getConditionInfosGeoIncompletes(),
-
 
25
						$this->getConditionlimiteeALaFrance(),
19
			'	AND DATE_ADD(date_modification, INTERVAL 25 HOUR) >= CURDATE() '.
26
						$this->getConditionModifObsRecente()
20
			'GROUP BY longitude , latitude ';
-
 
21
		$resultat = $this->recupererTous($requete);
27
					);
Line 22... Line 28...
22
		$this->reinitialiserTempsDerniereRequete();
28
		
-
 
29
		return $this->rechercherCoordonnees($conditions);
-
 
30
	}
-
 
31
	
23
		return $resultat;
32
	public function rechercherCoordonneesSansCorrespondanceDepuisLeDebut() {
-
 
33
		$conditions = array(
-
 
34
						$this->getConditionCoordonneesValides(),
-
 
35
						$this->getConditionInfosGeoIncompletes(),
-
 
36
						$this->getConditionlimiteeALaFrance()
-
 
37
					);
-
 
38
		
-
 
39
		return $this->rechercherCoordonnees($conditions);
-
 
40
	}
-
 
41
	
-
 
42
	
-
 
43
	private function getConditionModifObsRecente() {
-
 
44
		$condition = 'DATE_ADD(date_modification, INTERVAL 25 HOUR) >= CURDATE() ';
24
	}
45
		return $condition;
25
	
46
	}
26
	public function rechercherCoordonneesSansCorrespondanceDepuisLeDebut() {
47
	
-
 
48
	private function getConditionInfosGeoIncompletes() {
-
 
49
		$condition = '('.
-
 
50
						'(ce_zone_geo IS NULL OR ce_zone_geo = "") AND '.
-
 
51
						'(zone_geo IS NULL OR zone_geo = "") '.
27
		$requete = 'SELECT longitude, latitude '.
52
					 ') ';
-
 
53
		return $condition;
-
 
54
	}
-
 
55
	
-
 
56
	private function getConditionlimiteeALaFrance() {
-
 
57
		$condition = '('.
-
 
58
						'(latitude <= 51.071667 AND latitude >= 41.316667) AND '.
-
 
59
					 	'(longitude <= 9.513333 AND longitude >= -5.140278) '.
28
				'FROM cel_obs '.
60
					 ') ';
-
 
61
		return $condition;
29
				"WHERE code_insee_calcule = '' ".
62
	}
30
				'GROUP BY longitude , latitude ';
63
	
31
		// TODO faire une requete plus pertinente
64
	private function getConditionCoordonneesValides() {
32
		// Limitée à la france ? uniquement les coordonnées valides ? etc.. etc...
65
		$condition = '(latitude IS NOT NULL AND longitude IS NOT NULL '.
Line 33... Line 66...
33
		$resultat = $this->recupererTous($requete);
66
					 ' AND latitude != 0 AND latitude != "" '.
34
		$this->reinitialiserTempsDerniereRequete();
67
					 ' AND longitude != 0 AND longitude != "" ) ';	
35
		return $resultat;
68
		return $condition;
Line 42... Line 75...
42
		$this->reinitialiserTempsDerniereRequete();
75
		$this->reinitialiserTempsDerniereRequete();
43
	}
76
	}
Line 44... Line 77...
44
 
77
 
45
	public function ajouterCodeInseeCalcule($latitude, $longitude, $code_insee) {
78
	public function ajouterCodeInseeCalcule($latitude, $longitude, $code_insee) {
-
 
79
		$insert = 'UPDATE cel_obs '.
46
		$insert = 'UPDATE cel_obs '.
80
			"SET ".
47
			"SET code_insee_calcule = ".$this->proteger($code_insee)." ".
81
			"code_insee_calcule = ".$this->proteger($code_insee)." ".
48
			"WHERE latitude = ".$this->proteger($latitude)." ".
82
			"WHERE latitude = ".$this->proteger($latitude)." ".
49
			"	AND longitude = ".$this->proteger($longitude)." ";
83
			"	AND longitude = ".$this->proteger($longitude)." ";
50
		$this->requeter($insert);
84
		$this->requeter($insert);
51
		$this->reinitialiserTempsDerniereRequete();
85
		$this->reinitialiserTempsDerniereRequete();
Line 52... Line 86...
52
	}
86
	}
53
 
87
 
-
 
88
	public function modifierCodeInseeEtZoneGeo($coordonnees) {
-
 
89
		$update = "UPDATE cel_obs ".
54
	public function modifierCodeInseeEtZoneGeo($coordonnees) {
90
			"SET ".
55
		$update = "UPDATE cel_obs ".
91
				"code_insee_calcule = ".$this->proteger($coordonnees['code_insee']).", ".
56
			"SET ce_zone_geo = CONCAT('INSEE-C:' , code_insee_calcule), ".
92
				"ce_zone_geo = ".$this->proteger('INSEE-C:'.$coordonnees['code_insee']).", ".
57
		    	"zone_geo = ".$this->proteger($coordonnees['nom'])." ".
93
		    	"zone_geo = ".$this->proteger($coordonnees['nom'])." ".
58
			"WHERE ce_zone_geo = '' AND zone_geo = '' ".
94
			"WHERE ".
59
			"	AND latitude = ".$this->proteger($coordonnees['latitude'])." ".
95
			" latitude = ".$this->proteger($coordonnees['latitude'])." ".
60
			"	AND longitude = ".$this->proteger($coordonnees['longitude'])." ";
96
			" AND longitude = ".$this->proteger($coordonnees['longitude'])." ";
61
		$this->requeter($update);
97
		$this->requeter($update);
Line 62... Line 98...
62
		$this->reinitialiserTempsDerniereRequete();
98
		$this->reinitialiserTempsDerniereRequete();