Line 20... |
Line 20... |
20 |
* - recupererObservations : va rechercher dans la base de donnees les donnees sur des observations
|
20 |
* - recupererObservations : va rechercher dans la base de donnees les donnees sur des observations
|
21 |
* a partir des coordonnees longitude et latitude d'une station (+ des parametres additionnels)
|
21 |
* a partir des coordonnees longitude et latitude d'une station (+ des parametres additionnels)
|
22 |
*
|
22 |
*
|
23 |
* Les donnees seront renvoyees au format JSON
|
23 |
* Les donnees seront renvoyees au format JSON
|
24 |
*
|
24 |
*
|
25 |
* @package framework-0.3
|
25 |
* @package framework-0.4
|
26 |
* @author Alexandre GALIBERT <alexandre.galibert@tela-botanica.org>
|
26 |
* @author Alexandre GALIBERT <alexandre.galibert@tela-botanica.org>
|
27 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
27 |
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
|
28 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
28 |
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
|
29 |
* @version $Id$
|
29 |
* @version $Id$
|
30 |
* @copyright 2013 Tela Botanica (accueil@tela-botanica.org)
|
30 |
* @copyright 2013 Tela Botanica (accueil@tela-botanica.org)
|
31 |
*
|
31 |
*
|
32 |
*/
|
32 |
*/
|
Line 33... |
Line 33... |
33 |
|
33 |
|
Line 34... |
Line -... |
34 |
|
- |
|
35 |
class FloradataFormateur {
|
- |
|
36 |
|
- |
|
37 |
private $criteresRecherche;
|
- |
|
38 |
private $bdd;
|
- |
|
39 |
|
- |
|
40 |
|
- |
|
41 |
public function __construct($criteresRecherche) {
|
- |
|
42 |
$this->criteresRecherche = $criteresRecherche;
|
- |
|
43 |
}
|
- |
|
44 |
|
- |
|
45 |
public function recupererStations() {
|
- |
|
46 |
$requeteSql = $this->construireRequeteStations();
|
- |
|
47 |
$stations = $this->getBdd()->recupererTous($requeteSql);
|
- |
|
48 |
$zoomMaxMaillage = Config::get('zoom_maximal_maillage');
|
- |
|
49 |
$seuilMaillage = Config::get('seuil_maillage');
|
- |
|
50 |
$zoom = $this->criteresRecherche->zoom;
|
- |
|
51 |
$bbox = $this->criteresRecherche->bbox;
|
- |
|
52 |
// TODO: gérer une notion d'échelle plutot que de zoom (pour les clients SIG)
|
- |
|
53 |
if (count($stations) > $seuilMaillage && intval($zoom)<= $zoomMaxMaillage) {
|
- |
|
54 |
$maillage = new Maillage($bbox, $zoom);
|
- |
|
55 |
$maillage->genererMaillesVides();
|
- |
|
56 |
$maillage->ajouterPoints($stations);
|
- |
|
57 |
$stations = $maillage->formaterSortie();
|
- |
|
58 |
}
|
- |
|
59 |
$formateurJSON = new FormateurJson('floradata');
|
- |
|
60 |
$donneesFormatees = $formateurJSON->formaterStations($stations);
|
- |
|
61 |
return $donneesFormatees;
|
- |
|
62 |
}
|
- |
|
63 |
|
- |
|
64 |
public function recupererObservations() {
|
- |
|
65 |
$requeteSql = $this->construireRequeteObservations();
|
- |
|
66 |
$observations = $this->getBdd()->recupererTous($requeteSql);
|
- |
|
67 |
$nomSite = $this->obtenirNomStation();
|
- |
|
68 |
$formateurJSON = new FormateurJson('floradata');
|
- |
|
69 |
$donneesFormatees = $formateurJSON->formaterObservations($observations, $nomSite);
|
- |
|
70 |
return $donneesFormatees;
|
- |
|
71 |
}
|
- |
|
72 |
|
- |
|
73 |
|
- |
|
74 |
|
- |
|
75 |
// ------------------------------------------------------------------------ //
|
- |
|
76 |
// Fonctions de construction des criteres de recherches pour la requete SQL //
|
- |
|
77 |
// ------------------------------------------------------------------------ //
|
- |
|
78 |
|
- |
|
79 |
private function getBdd() {
|
- |
|
80 |
if (!isset($this->bdd)) {
|
- |
|
81 |
$this->bdd = new Bdd();
|
- |
|
82 |
}
|
- |
|
83 |
$this->bdd->requeter("USE ".Config::get('bdd_nom'));
|
- |
|
84 |
return $this->bdd;
|
34 |
|
85 |
}
|
- |
|
86 |
|
- |
|
87 |
private function construireRequeteStations() {
|
- |
|
88 |
$bbox = $this->criteresRecherche->bbox;
|
35 |
final class FloradataFormateur extends Formateur {
|
89 |
$selectTypeSite =
|
- |
|
90 |
"IF(".
|
36 |
|
91 |
"(longitude IS NULL OR latitude IS NULL) ".
|
- |
|
92 |
"OR (longitude=0 AND latitude=0) ".
|
- |
|
93 |
"OR (mots_cles_texte LIKE '%sensible%') ".
|
- |
|
94 |
"OR NOT (".
|
- |
|
95 |
"longitude BETWEEN ".$bbox['ouest']." AND ".$bbox['est']." ".
|
- |
|
96 |
"AND latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord'].
|
- |
|
97 |
")".
|
37 |
final protected function construireRequeteStations() {
|
98 |
", 'COMMUNE', 'STATION'".
|
38 |
$condition = "(longitude IS NULL OR latitude IS NULL OR (longitude=0 AND latitude=0) ".
|
99 |
")";
|
39 |
"OR longitude>180 OR latitude>90 OR mots_cles_texte LIKE '%sensible%')";
|
100 |
$requete =
|
40 |
$requete =
|
101 |
"SELECT COUNT(id_observation) AS observations, ce_zone_geo, zone_geo, station, ".
|
41 |
"SELECT COUNT(id_observation) AS observations, ce_zone_geo, zone_geo, station, ".
|
102 |
"longitude, latitude, nom AS nom_commune,wgs84_longitude AS lng_commune, ".
|
42 |
"IF({$condition}, wgs84_latitude, latitude) AS latitude, IF({$condition}, wgs84_longitude, longitude) ".
|
103 |
"wgs84_latitude AS lat_commune, ".$selectTypeSite." AS type_site ".
|
43 |
"AS longitude, IF({$condition}, 'COMMUNE', 'STATION') AS type_site, 'floradata' AS source ".
|
104 |
"FROM cel_obs LEFT JOIN cel_zones_geo cz ON ce_zone_geo=id_zone_geo ".
|
44 |
"FROM cel_obs LEFT JOIN cel_zones_geo cz ON ce_zone_geo=id_zone_geo ".
|
105 |
"WHERE transmission=1 ".
|
45 |
"WHERE transmission=1 ".
|
106 |
$this->construireWhereDepartement().' '.
|
46 |
$this->construireWhereDepartement().' '.
|
107 |
$this->construireWhereAuteur().' '.
|
47 |
$this->construireWhereAuteur().' '.
|
108 |
$this->construireWhereDate().' '.
|
48 |
$this->construireWhereDate().' '.
|
109 |
$this->construireWhereReferentiel().' '.
|
49 |
$this->construireWhereReferentiel().' '.
|
110 |
$this->construireWhereTaxon().' '.
|
50 |
$this->construireWhereTaxon().' '.
|
111 |
$this->construireWhereCoordonneesBbox().' '.
|
51 |
$this->construireWhereCoordonneesBbox().' '.
|
Line 112... |
Line 52... |
112 |
"GROUP BY longitude, latitude, wgs84_longitude, wgs84_latitude";
|
52 |
"GROUP BY IF({$condition},wgs84_longitude,longitude), IF({$condition},wgs84_latitude,latitude)";
|
113 |
return $requete;
|
53 |
return $requete;
|
114 |
}
|
54 |
}
|
115 |
|
55 |
|
116 |
private function construireRequeteObservations() {
|
56 |
final protected function construireRequeteObservations() {
|
- |
|
57 |
$requete =
|
117 |
$requete =
|
58 |
"SELECT id_observation AS id_obs, nom_sel_nn AS nn, nom_referentiel, lieudit, milieu, ".
|
118 |
"SELECT id_observation AS id_obs, nom_ret_nn AS nn, nom_ret AS nomSci, ".
|
59 |
"(DATE(IF(date_observation != '0000-00-00 00:00:00', date_observation, date_transmission))) AS date, ".
|
119 |
"Date(date_observation) AS date, milieu AS lieu, nom_referentiel, ".
|
60 |
"CONCAT(prenom_utilisateur, ' ', nom_utilisateur) AS observateur, ce_utilisateur AS observateurId, ".
|
120 |
"Concat(prenom_utilisateur, ' ', nom_utilisateur) AS observateur, ce_utilisateur AS observateurId ".
|
61 |
"IF(nom_sel IS NULL, 'A identifier',nom_sel) AS nomSci, 'floradata' AS projet ".
|
121 |
"FROM cel_obs WHERE transmission=1 ".
|
62 |
"FROM cel_obs WHERE transmission=1 ".
|
122 |
$this->construireWhereAuteur().' '.
|
63 |
$this->construireWhereAuteur().' '.
|
123 |
$this->construireWhereReferentiel().' '.
|
64 |
$this->construireWhereReferentiel().' '.
|
124 |
$this->construireWhereDate().' '.
|
65 |
$this->construireWhereDate().' '.
|
125 |
$this->construireWhereTaxon().' '.
|
66 |
$this->construireWhereTaxon().' '.
|
Line -... |
Line 67... |
- |
|
67 |
$this->construireWhereCoordonneesPoint().' '.
|
- |
|
68 |
"ORDER BY IF(nom_sel IS NULL, 'A identifier',nom_sel), date, observateur";
|
- |
|
69 |
return $requete;
|
- |
|
70 |
}
|
- |
|
71 |
|
- |
|
72 |
final protected function construireRequeteWfs() {
|
- |
|
73 |
$condition = "(longitude IS NULL OR latitude IS NULL OR (longitude=0 AND latitude=0) ".
|
- |
|
74 |
"OR longitude>180 OR latitude>90 OR mots_cles_texte LIKE '%sensible%')";
|
- |
|
75 |
$requete =
|
- |
|
76 |
"SELECT nom_sel AS taxon, ce_zone_geo, zone_geo, station, 'floradata' AS source, ".
|
- |
|
77 |
"IF({$condition}, wgs84_latitude, latitude) AS latitude, IF({$condition}, wgs84_longitude, longitude) ".
|
- |
|
78 |
"AS longitude, IF({$condition}, 'COMMUNE', 'STATION') AS type_site ".
|
- |
|
79 |
"FROM cel_obs LEFT JOIN cel_zones_geo cz ON ce_zone_geo=id_zone_geo ".
|
- |
|
80 |
"WHERE transmission=1 ".
|
- |
|
81 |
$this->construireWhereCoordonneesBbox().' '.
|
126 |
$this->construireWhereCoordonneesPoint().' '.
|
82 |
$this->construireWhereNomScientifique().' '.
|
127 |
"ORDER BY nom_ret, date, observateur";
|
83 |
"ORDER BY IF({$condition},wgs84_longitude,longitude), IF({$condition},wgs84_latitude,latitude)";
|
128 |
return $requete;
|
84 |
return $requete;
|
129 |
}
|
85 |
}
|
130 |
|
86 |
|
131 |
protected function construireWhereTaxon() {
|
87 |
private function construireWhereTaxon() {
|
132 |
$sql = '';
|
- |
|
133 |
if (isset($this->criteresRecherche->taxon)) {
|
88 |
$sql = '';
|
134 |
$taxons = $this->criteresRecherche->taxon;
|
89 |
if (isset($this->criteresRecherche->taxon)) {
|
- |
|
90 |
$taxons = $this->criteresRecherche->taxon;
|
- |
|
91 |
$criteres = array();
|
135 |
$criteres = array();
|
92 |
foreach ($taxons as $taxon) {
|
136 |
foreach ($taxons as $taxon) {
|
93 |
if ($taxon['rang'] == Config::get('rang.famille')) {
|
137 |
$nomRang = $this->getNomRang($taxon);
|
- |
|
138 |
if ($nomRang == 'genre') {
|
94 |
$criteres[] = "famille=".$this->getBdd()->proteger($taxon['nom']);
|
139 |
$criteres[] = "famille=".$this->getBdd()->proteger($taxon['nom']);
|
- |
|
140 |
} else {
|
95 |
} elseif ($taxon['rang'] == Config::get('rang.genre')) {
|
141 |
$criteres[] = "nom_ret LIKE ".$this->getBdd()->proteger($taxon['nom']."%");
|
96 |
$criteres[] = "nom_sel LIKE ".$this->getBdd()->proteger($taxon['nom']." %");
|
142 |
if ($nomRang == 'espece') {
|
97 |
} else {
|
143 |
$criteres = array_merge($criteres, $this->concatenerTaxonsSousEspeces($taxon));
|
98 |
$sousTaxons = $this->concatenerSynonymesEtSousEspeces($taxon);
|
144 |
}
|
99 |
$criteres[] = "nt IN (".implode(',', $sousTaxons).")";
|
145 |
}
|
100 |
}
|
146 |
}
|
101 |
}
|
147 |
$sql = "AND (".implode(' OR ',array_unique($criteres)).")";
|
- |
|
148 |
}
|
- |
|
149 |
return $sql;
|
- |
|
150 |
}
|
- |
|
151 |
|
- |
|
152 |
protected function getNomRang($taxon) {
|
- |
|
153 |
$nomsRangs = array('famille', 'genre', 'espece', 'sous_espece');
|
- |
|
154 |
for ($index = 0; $index < count($nomsRangs)
|
- |
|
155 |
&& Config::get("rang.".$nomsRangs[$index]) != $taxon['rang']; $index ++);
|
102 |
$sql = "AND (".implode(' OR ',array_unique($criteres)).")";
|
156 |
$position = $index == count($nomsRangs) ? count($nomsRangs)-1 : $index;
|
- |
|
157 |
return $nomsRangs[$position];
|
- |
|
158 |
}
|
- |
|
159 |
|
- |
|
160 |
protected function concatenerTaxonsSousEspeces($taxon) {
|
- |
|
161 |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $taxon);
|
- |
|
162 |
$sousTaxons = $referentiel->recupererTaxonsSousEspeces();
|
- |
|
163 |
$criteres = array();
|
- |
|
164 |
foreach ($sousTaxons as $sousTaxon) {
|
- |
|
165 |
$criteres[] = "nom_ret LIKE ".$this->getBdd()->proteger($sousTaxon['nom']."%");
|
- |
|
166 |
}
|
103 |
}
|
167 |
return $criteres;
|
104 |
return $sql;
|
168 |
}
|
105 |
}
|
169 |
|
106 |
|
170 |
protected function concatenerTaxonsFamilles($taxon) {
|
107 |
private function concatenerSynonymesEtSousEspeces($taxon) {
|
171 |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $taxon);
|
108 |
$referentiel = new Referentiel($this->criteresRecherche->referentiel, $taxon);
|
172 |
$sousTaxons = $referentiel->recupererTaxonsFamilles();
|
109 |
$sousTaxons = $referentiel->recupererSynonymesEtSousEspeces();
|
173 |
$criteres = array();
|
110 |
$criteres = array();
|
Line 174... |
Line 111... |
174 |
foreach ($sousTaxons as $sousTaxon) {
|
111 |
foreach ($sousTaxons as $sousTaxon) {
|
175 |
$criteres[] = "nom_ret LIKE ".$this->getBdd()->proteger($sousTaxon['nom']."%");
|
112 |
$criteres[] = "nt=".$sousTaxon['nt'];
|
176 |
}
|
113 |
}
|
Line 210... |
Line 147... |
210 |
|
147 |
|
211 |
private function construireWhereDate() {
|
148 |
private function construireWhereDate() {
|
212 |
$sql = '';
|
149 |
$sql = '';
|
213 |
if (isset($this->criteresRecherche->nbJours)) {
|
150 |
if (isset($this->criteresRecherche->nbJours)) {
|
214 |
$nbJours = $this->criteresRecherche->nbJours;
|
151 |
$nbJours = $this->criteresRecherche->nbJours;
|
215 |
$sql = "AND (Datediff(Curdate(), date_creation)<={$nbJours})";
|
152 |
$sql = "AND (Datediff(Curdate(), date_transmission)<={$nbJours})";
|
216 |
} else {
|
153 |
} else {
|
217 |
$sql = $this->construireWhereDateDebutEtFin();
|
154 |
$sql = $this->construireWhereDateDebutEtFin();
|
218 |
}
|
155 |
}
|
219 |
return $sql;
|
156 |
return $sql;
|
Line 225... |
Line 162... |
225 |
$dateFin = isset($this->criteresRecherche->dateFin) ? $this->criteresRecherche->dateFin : null;
|
162 |
$dateFin = isset($this->criteresRecherche->dateFin) ? $this->criteresRecherche->dateFin : null;
|
226 |
if (!is_null($dateDebut) || !is_null($dateFin)) {
|
163 |
if (!is_null($dateDebut) || !is_null($dateFin)) {
|
227 |
$dateFin = !is_null($dateFin) ? $dateFin : date('Y-m-d');
|
164 |
$dateFin = !is_null($dateFin) ? $dateFin : date('Y-m-d');
|
228 |
$condition = '';
|
165 |
$condition = '';
|
229 |
if ($dateDebut == $dateFin) {
|
166 |
if ($dateDebut == $dateFin) {
|
230 |
$condition = "Date(date_observation)=".$this->getBdd()->proteger($dateDebut);
|
167 |
$condition = "DATE(date_observation)=".$this->getBdd()->proteger($dateDebut);
|
231 |
} elseif (is_null($dateFin)) {
|
168 |
} elseif (is_null($dateFin)) {
|
232 |
$condition = "Date(date_observation)>=".$this->getBdd()->proteger($dateDebut);
|
169 |
$condition = "DATE(date_observation)>=".$this->getBdd()->proteger($dateDebut);
|
233 |
} elseif (is_null($dateDebut)) {
|
170 |
} elseif (is_null($dateDebut)) {
|
234 |
$condition = "Date(date_observation)<=".$this->getBdd()->proteger($dateFin);
|
171 |
$condition = "DATE(date_observation)<=".$this->getBdd()->proteger($dateFin);
|
235 |
} else {
|
172 |
} else {
|
236 |
$condition = "Date(date_observation) BETWEEN ".$this->getBdd()->proteger($dateDebut)." ".
|
173 |
$condition = "DATE(date_observation) BETWEEN ".$this->getBdd()->proteger($dateDebut)." ".
|
237 |
"AND ".$this->getBdd()->proteger($dateFin);
|
174 |
"AND ".$this->getBdd()->proteger($dateFin);
|
238 |
}
|
175 |
}
|
239 |
$sql = "AND ($condition)";
|
176 |
$sql = "AND ($condition)";
|
240 |
}
|
177 |
}
|
241 |
return $sql;
|
178 |
return $sql;
|
242 |
}
|
179 |
}
|
Line 243... |
Line 180... |
243 |
|
180 |
|
- |
|
181 |
private function construireWhereCoordonneesBbox() {
|
244 |
private function construireWhereCoordonneesBbox() {
|
182 |
$sql = '';
|
245 |
$bbox = $this->criteresRecherche->bbox;
|
- |
|
246 |
$sql =
|
183 |
if (isset($this->criteresRecherche->bbox)) {
|
247 |
"AND (".
|
- |
|
248 |
"(".
|
184 |
$sql = "AND (".
|
249 |
"latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord']." ".
|
- |
|
250 |
"AND longitude BETWEEN ".$bbox['ouest']." AND ".$bbox['est'].
|
- |
|
251 |
") OR (".
|
185 |
"(".$this->genererCritereWhereBbox('').") OR (".
|
252 |
"((longitude IS NULL OR latitude IS NULL) OR (longitude=0 AND latitude=0) ".
|
186 |
"(longitude IS NULL OR latitude IS NULL OR (longitude=0 AND latitude=0) ".
|
253 |
"OR (longitude>180 AND latitude>90)) AND ".
|
- |
|
254 |
"wgs84_longitude BETWEEN ".$bbox['ouest']." AND ". $bbox['est']." ".
|
187 |
"OR longitude>180 OR latitude>90 OR mots_cles_texte LIKE '%sensible%') AND ".
|
255 |
"AND wgs84_latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord'].
|
188 |
$this->genererCritereWhereBbox('wgs84_').
|
256 |
")".
|
189 |
")".
|
- |
|
190 |
")";
|
- |
|
191 |
}
|
- |
|
192 |
return $sql;
|
- |
|
193 |
}
|
- |
|
194 |
|
- |
|
195 |
private function genererCritereWhereBbox($suffixe) {
|
- |
|
196 |
$bboxRecherche = $this->criteresRecherche->bbox;
|
- |
|
197 |
$conditions = array();
|
- |
|
198 |
$sql = '';
|
- |
|
199 |
foreach ($bboxRecherche as $bbox) {
|
- |
|
200 |
$conditions[] = "({$suffixe}latitude BETWEEN ".$bbox['sud']." AND ".$bbox['nord']." ".
|
- |
|
201 |
"AND {$suffixe}longitude BETWEEN ".$bbox['ouest']." AND ".$bbox['est'].")";
|
- |
|
202 |
}
|
- |
|
203 |
if (count($conditions) > 0) {
|
- |
|
204 |
$sql = '('.implode(' OR ', $conditions).')';
|
- |
|
205 |
}
|
- |
|
206 |
return $sql;
|
- |
|
207 |
}
|
- |
|
208 |
|
- |
|
209 |
private function construireWhereNomScientifique() {
|
- |
|
210 |
$sql = '';
|
- |
|
211 |
if (isset($this->criteresRecherche->filtre)) {
|
- |
|
212 |
$filtre = $this->criteresRecherche->filtre;
|
- |
|
213 |
$valeur = "'{$filtre['valeur']}".($filtre['operateur'] == 'LIKE' ? "%" : "")."'";
|
- |
|
214 |
switch ($filtre['champ']) {
|
- |
|
215 |
case "taxon" : $sql = "AND nom_sel {$filtre['operateur']} {$valeur}"; break;
|
- |
|
216 |
}
|
257 |
")";
|
217 |
}
|
258 |
return $sql;
|
218 |
return $sql;
|
Line 259... |
Line 219... |
259 |
}
|
219 |
}
|
- |
|
220 |
|
- |
|
221 |
private function construireWhereCoordonneesPoint() {
|
260 |
|
222 |
$sql = '';
|
- |
|
223 |
$conditions = array();
|
- |
|
224 |
foreach ($this->criteresRecherche->stations as $station) {
|
261 |
private function construireWhereCoordonneesPoint() {
|
225 |
if ($station[0] == $this->nomSource) {
|
- |
|
226 |
$longitude = str_replace(",", ".", strval($station[3]));
|
262 |
$longitude = $this->criteresRecherche->longitude;
|
227 |
$latitude = str_replace(",", ".", strval($station[2]));
|
263 |
$latitude = $this->criteresRecherche->latitude;
|
228 |
if ($station[1] == 'station') {
|
264 |
$condition = "(longitude=".$longitude." AND latitude=".$latitude." ".
|
229 |
$conditions[] = "(longitude=".$longitude." AND latitude=".$latitude." ".
|
265 |
"AND (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE '%sensible%'))";
|
230 |
"AND (mots_cles_texte IS NULL OR mots_cles_texte NOT LIKE '%sensible%'))";
|
266 |
if ($this->criteresRecherche->typeSite == 'commune') {
|
231 |
} else {
|
267 |
$commune = $this->obtenirCoordonneesCommune();
|
232 |
$commune = $this->obtenirCoordonneesCommune($longitude, $latitude);
|
268 |
$condition .=
|
233 |
$conditions[] =
|
269 |
" OR (".
|
234 |
"(".
|
270 |
"((longitude IS NULL OR latitude IS NULL) OR (longitude=0 AND latitude=0) ".
|
235 |
"((longitude IS NULL OR latitude IS NULL) OR (longitude=0 AND latitude=0) ".
|
271 |
"OR (longitude>180 AND latitude>90)) ".
|
236 |
"OR longitude>180 OR latitude>90 OR mots_cles_texte LIKE '%sensible%') ".
|
- |
|
237 |
"AND ce_zone_geo=".$this->getBdd()->proteger($commune['id_zone_geo']).
|
- |
|
238 |
")";
|
272 |
"AND ce_zone_geo=".$this->getBdd()->proteger($commune['id_zone_geo']).
|
239 |
}
|
273 |
")";
|
240 |
}
|
- |
|
241 |
}
|
- |
|
242 |
if (count($conditions) > 0) {
|
- |
|
243 |
$sql = "AND (".implode(" OR ", $conditions).")";
|
274 |
}
|
244 |
}
|
275 |
return "AND ($condition)";
|
245 |
return $sql;
|
276 |
}
|
246 |
}
|
277 |
|
247 |
|
278 |
private function obtenirCoordonneesCommune() {
|
248 |
private function obtenirCoordonneesCommune($longitude, $latitude) {
|
279 |
$requete = "SELECT id_zone_geo, nom FROM cel_zones_geo WHERE wgs84_longitude=".
|
249 |
$requete = "SELECT id_zone_geo, nom FROM cel_zones_geo WHERE wgs84_longitude=$longitude ".
|
280 |
$this->criteresRecherche->longitude." AND wgs84_latitude=".$this->criteresRecherche->latitude;
|
250 |
"AND wgs84_latitude=$latitude";
|
281 |
$commune = $this->getBdd()->recuperer($requete);
|
251 |
$commune = $this->getBdd()->recuperer($requete);
|
282 |
if ($commune === false) {
|
252 |
if ($commune === false) {
|
283 |
$commune = null;
|
253 |
$commune = null;
|
284 |
}
|
254 |
}
|
Line 285... |
Line 255... |
285 |
return $commune;
|
255 |
return $commune;
|
286 |
}
|
256 |
}
|
- |
|
257 |
|
287 |
|
258 |
final protected function obtenirNomsStationsSurPoint() {
|
288 |
private function obtenirNomStation() {
|
259 |
// verifier si les coordonnees du point de requetage correspondent a une commune
|
289 |
// verifier si les coordonnees du point de requetage correspondent a une commune
|
260 |
$coordonnees = $this->recupererCoordonneesPremiereStation();
|
290 |
$station = $this->obtenirCoordonneesCommune();
|
261 |
$station = $this->obtenirCoordonneesCommune($coordonnees[0], $coordonnees[1]);
|
291 |
if (is_null($station)) {
|
262 |
if (is_null($station)) {
|
292 |
$requete = 'SELECT DISTINCT lieudit AS nom FROM cel_obs WHERE longitude='.
|
263 |
$requete = 'SELECT DISTINCT lieudit AS nom FROM cel_obs WHERE longitude='.
|
293 |
$this->criteresRecherche->longitude.' AND latitude='.$this->criteresRecherche->latitude;
|
264 |
$coordonnees[0].' AND latitude='.$coordonnees[1];
|
294 |
$station = $this->getBdd()->recuperer($requete);
|
265 |
$station = $this->getBdd()->recuperer($requete);
|
295 |
}
|
266 |
}
|
296 |
$nomStation = '';
|
267 |
$nomStation = '';
|
297 |
if ($station !== false) {
|
268 |
if ($station !== false) {
|
298 |
$nomStation = trim($station['nom']);
|
269 |
$nomStation = trim($station['nom']);
|
Line -... |
Line 270... |
- |
|
270 |
}
|
- |
|
271 |
return $nomStation;
|
- |
|
272 |
}
|
- |
|
273 |
|
- |
|
274 |
private function recupererCoordonneesPremiereStation() {
|
- |
|
275 |
$coordonnees = null;
|
- |
|
276 |
foreach ($this->criteresRecherche->stations as $station) {
|
- |
|
277 |
if ($station[0] == $this->nomSource) {
|
- |
|
278 |
$longitude = str_replace(",", ".", strval($station[3]));
|
- |
|
279 |
$latitude = str_replace(",", ".", strval($station[2]));
|
- |
|
280 |
$coordonnees = array($longitude, $latitude);
|
- |
|
281 |
}
|
299 |
}
|
282 |
}
|
Line 300... |
Line 283... |
300 |
return $nomStation;
|
283 |
return $coordonnees;
|
301 |
}
|
284 |
}
|