Subversion Repositories eFlore/Projets.eflore-projets

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
727 alex 1
<?php
2
 
3
final class DonneesFloradata extends SourceDonnees {
4
 
5
	public function __construct($limitesCarte, $taxon, $source) {
6
		parent::__construct($limitesCarte, $taxon, $source);
7
	}
8
 
9
	final public function recupererStations() {
10
		$bdd = new Bdd();
11
		$bdd->requeter("USE ".Config::get('bdd_nom_floradata'));
12
		$condition = "longitude IS NULL OR latitude IS NULL OR longitude=0 OR latitude=0 ".
13
		"OR longitude>180 OR latitude>90 OR mots_cles_texte LIKE '%sensible%'";
14
		$requete =
15
		"SELECT COUNT(id_observation) AS nb_observations, ".
16
		"Floor(If({$condition},wgs84_latitude,latitude)*10)/10 AS lat, ".
17
		"Floor(If({$condition},wgs84_longitude,longitude)*10)/10 AS lng ".
18
		"FROM cel_obs LEFT JOIN cel_zones_geo cz ON ce_zone_geo=id_zone_geo ".
19
		"WHERE transmission=1 AND ".$this->construireWhereTaxon()." AND ".
20
		"(".
21
			"(".
22
				"longitude BETWEEN ".$this->limitesCarte['ouest']." AND ".$this->limitesCarte['est']." ".
23
				"AND latitude BETWEEN ".$this->limitesCarte['sud']." AND ".$this->limitesCarte['nord'].
24
			") OR (".
25
				"({$condition}) AND ".
26
				"wgs84_longitude BETWEEN ".$this->limitesCarte['ouest']." AND ".$this->limitesCarte['est']." ".
27
				"AND wgs84_latitude BETWEEN ".$this->limitesCarte['sud']." AND ".$this->limitesCarte['nord'].
28
			")".
29
		") ".
30
		"GROUP BY Floor(If({$condition},wgs84_latitude,latitude)*10)/10, Floor(If({$condition},wgs84_longitude,longitude)*10)/10 ".
31
		"ORDER BY lat DESC, lng ASC";
32
		return $bdd->recupererTous($requete);
33
	}
34
 
35
	final protected function construireWhereTaxon() {
36
		$criteres = array();
37
		$nomRang = $this->obtenirNomRang($this->taxon);
38
		if ($nomRang == 'famille') {
39
			$criteres[] = "famille=".$this->bdd->proteger($this->taxon['nom_sci']);
40
		} else {
41
			$criteres[] = "nt=".$this->taxon['num_taxonomique'];
42
			$sousTaxons = $this->recupererSynonymesEtSousEspeces();
43
			foreach ($sousTaxons as $sousTaxon) {
44
				$criteres[] ="nt=".$sousTaxon['num_taxonomique'];
45
			}
46
		}
47
		return "(".implode(' OR ',array_unique($criteres)).")";
48
	}
49
 
50
}
51
 
52
?>