Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 727 | Go to most recent revision | Details | Compare with Previous | 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']);
735 alex 40
		} elseif ($nomRang == 'genre') {
41
			$criteres[] = "nom_sel LIKE ".$this->bdd->proteger($this->taxon['nom_sci'].'%');
727 alex 42
		} else {
735 alex 43
			$taxons = array($this->taxon['num_taxonomique']);
727 alex 44
			$sousTaxons = $this->recupererSynonymesEtSousEspeces();
45
			foreach ($sousTaxons as $sousTaxon) {
735 alex 46
				$taxons[] = $sousTaxon['num_taxonomique'];
727 alex 47
			}
735 alex 48
			$criteres[] = "nt IN (".implode(',', $taxons).")";
727 alex 49
		}
50
		return "(".implode(' OR ',array_unique($criteres)).")";
51
	}
52
 
53
}
54
 
55
?>