Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 944 Rev 954
Line 59... Line 59...
59
	/**
59
	/**
60
	 * Les stations de la carte par défaut
60
	 * Les stations de la carte par défaut
61
	 */
61
	 */
62
	public function getStations($params) {
62
	public function getStations($params) {
63
		$json = null;
63
		$json = null;
64
		$requete =  'SELECT sector, x_utm, y_utm, wgs84_latitude AS coord_x, wgs84_longitude AS coord_y '.
64
		$requete =  'SELECT sector, x_utm, y_utm, wgs84_latitude AS commune_latitude, wgs84_longitude AS commune_longitude, '.
-
 
65
					'	coord_x AS point_latitude, coord_y  AS point_longitude '.
65
                    'FROM cel_inventory AS i '.
66
                    'FROM cel_inventory AS i '.
66
                    '   LEFT JOIN locations AS l '.
67
                    '   LEFT JOIN locations AS l '.
67
                    '       ON (l.name = i.location AND l.code = i.id_location) '.
68
                    '       ON (l.name = i.location AND l.code = i.id_location) '.
68
                    "WHERE transmission = '1' ".
69
                    "WHERE transmission = '1' ".
69
					$this->construireWhereDept().
70
					$this->construireWhereDept().
Line 77... Line 78...
77
					$this->construireWhereTag();
78
					$this->construireWhereTag();
78
		//die($requete);
79
		//die($requete);
79
		$resultats = $this->requeter($requete);
80
		$resultats = $this->requeter($requete);
Line 80... Line 81...
80
		
81
		
81
		// Traitement des résultats
-
 
82
		$obs_nbre = $this->traiterNbreObs($resultats);
82
		// Traitement des résultats
Line 83... Line 83...
83
		$stations = $this->traiterStations($resultats);
83
		$json['donnees'] = $this->traiterStations($resultats);
84
		
-
 
85
		// Création des infos du widget
-
 
86
		$json['donnees']['points'] = $stations;
-
 
87
		$json['donnees']['stats']['communes'] = count($stations);
-
 
88
		$json['donnees']['stats']['observations'] = $obs_nbre;
84
		
89
		
85
		// Création des infos du widget
Line 90... Line 86...
90
		$json['type'] = (isset($this->formatRetour)) ? $this->formatRetour : 'jsonVar';
86
		$json['type'] = (isset($this->formatRetour)) ? $this->formatRetour : 'jsonVar';
91
		$json['variable_js'] = 'stations';
87
		$json['variable_js'] = 'stations';
Line 100... Line 96...
100
		}
96
		}
101
		return $obs_nbre;
97
		return $obs_nbre;
102
	}
98
	}
Line 103... Line 99...
103
	
99
	
104
	private function traiterStations($resultats) {
100
	private function traiterStations($resultats) {
-
 
101
		$stations = array(
-
 
102
			'stats' => array('stations' => 0, 'communes' => 0, 'observations' => 0),
-
 
103
			'points' => null
-
 
104
		);
-
 
105
		$stations['stats']['observations'] = $this->traiterNbreObs($resultats);
-
 
106
		
105
		$stations = array();
107
		$points = array();
106
		if ($resultats !== false) {
108
		if ($resultats !== false) {
107
			foreach ($resultats as $enrg) {
109
			foreach ($resultats as $enrg) {
108
				if ($enrg['coord_x'] != null && $enrg['coord_y'] != null) {
110
				if (!$this->etreNull($enrg['point_latitude'])&& !$this->etreNull($enrg['point_longitude'])) {
109
					$id = $enrg['coord_x'].'-'.$enrg['coord_y'];
111
					$lat = $enrg['point_latitude'];
110
					if (!isset($stations[$id])) {
112
					$lng = $enrg['point_longitude'];
111
						$enrg['id'] = 'UTM:'.$enrg['x_utm'].'-'.$enrg['y_utm'].'-'.$enrg['sector'];
113
					$id = $lat.'-'.$lng;
112
						unset($enrg['x_utm']);
114
					if (!isset($points[$id])) {
113
						unset($enrg['y_utm']);
115
						$points[$id]['id'] = "POINT:$lat-$lng";
114
						unset($enrg['sector']);
116
						$points[$id]['lat'] = round($lat, 5);
115
						$stations[$id] = $enrg;
117
						$points[$id]['lng'] = round($lng, 5);
-
 
118
						$points[$id]['nbre'] = 1;
116
						$stations[$id]['nbre'] = 1;
119
						$stations['stats']['stations']++;
117
					} else {
120
					} else {
118
						$stations[$id]['nbre']++;
121
						$points[$id]['nbre']++;
-
 
122
					}
-
 
123
				} else if (!$this->etreNull($enrg['commune_latitude'])&& !$this->etreNull($enrg['commune_longitude'])) {
-
 
124
					$lat = $enrg['commune_latitude'];
-
 
125
					$lng = $enrg['commune_longitude'];
-
 
126
					$id = $lat.'-'.$lng;
-
 
127
					if (!isset($points[$id])) {
-
 
128
						$points[$id]['id'] = "COMMUNE:$lat-$lng";
-
 
129
						$points[$id]['lat'] = round($lat, 5);
-
 
130
						$points[$id]['lng'] = round($lng, 5);
-
 
131
						$points[$id]['nbre'] = 1;
-
 
132
						$stations['stats']['communes']++;
-
 
133
					} else {
-
 
134
						$points[$id]['nbre']++;
119
					}
135
					}
120
				}
136
				} 
121
			}
137
			}
122
			$stations = array_values($stations);
138
			$stations['points'] = array_values($points);
123
		}
139
		}
124
		return $stations;
140
		return $stations;
Line 125... Line 141...
125
	}
141
	}
Line 326... Line 342...
326
	private function construireWhereCoordonnees() {
342
	private function construireWhereCoordonnees() {
327
		$sql = '';
343
		$sql = '';
328
		// Récupération des coordonnées depuis l'id station
344
		// Récupération des coordonnées depuis l'id station
329
		extract($this->decomposerParametreStation());
345
		extract($this->decomposerParametreStation());
330
		if (isset($type)) {
346
		if (isset($type)) {
331
			if ($type == 'UTM') {
347
			if ($type == 'COMMUNE') {
332
				$secteur = $this->proteger($secteur);
-
 
333
				$x_utm = $this->proteger($x_utm);
348
				$lat = $this->proteger($lat);
334
				$y_utm = $this->proteger($y_utm);
349
				$lng = $this->proteger($lng);
335
				
-
 
336
				$sql = " AND (sector = $secteur AND x_utm = $x_utm AND y_utm = $y_utm ) ";
350
				$sql = " AND (wgs84_latitude = $lat AND wgs84_longitude = $lng) ";
337
			}  else if ($type == 'LngLat') {
351
			}  else if ($type == 'POINT') {
338
				$coord_x = $this->proteger($coord_x);
352
				$lat = $this->proteger($lat);
339
				$coord_y = $this->proteger($coord_y);
353
				$lng = $this->proteger($lng);
340
				
-
 
341
				$sql = " AND (coord_x = $coord_x AND coord_y = $coord_y ) ";
354
				$sql = " AND (coord_x = $lat AND coord_y = $lng) ";
342
			}
355
			}
343
		}		
356
		}		
344
		return $sql;
357
		return $sql;
345
	}
358
	}
Line 816... Line 829...
816
		$station_infos = array();
829
		$station_infos = array();
817
		if (isset($this->parametres['station'])) {
830
		if (isset($this->parametres['station'])) {
818
			$station = $this->parametres['station'];
831
			$station = $this->parametres['station'];
819
			$this->debug[] = $station;
832
			$this->debug[] = $station;
820
			list($type, $coord) = explode(':', $station);
833
			list($type, $coord) = explode(':', $station);
-
 
834
			list($lat, $lng) = explode('-', $coord);
Line 821... Line -...
821
			
-
 
822
			if ($type == 'UTM') {
-
 
823
				list($x_utm, $y_utm, $secteur) = explode('-', $coord);
835
			
824
				$station_infos = array('x_utm' => $x_utm, 'y_utm' => $y_utm, 'secteur' => $secteur);
-
 
825
			} else if ($type == 'LngLat') {
-
 
826
				list($coord_y, $coord_x) = explode('-', $coord);
-
 
827
				$station_infos = array('coord_y' => $coord_y, 'coord_x' => $coord_x);
-
 
828
			}
-
 
829
			$station_infos['type'] = $type;
836
			$station_infos = array('type' => $type, 'lat' => $lat, 'lng' => $lng);
830
		}
837
		}
831
		return $station_infos;
838
		return $station_infos;
Line 832... Line 839...
832
	}
839
	}