Subversion Repositories eFlore/Projets.eflore-projets

Rev

Blame | Last modification | View Log | RSS feed

<?php

final class DonneesFloradata extends SourceDonnees {
        
        public function __construct($limitesCarte, $taxon, $source) {
                parent::__construct($limitesCarte, $taxon, $source);
        }
        
        final public function recupererStations() {
                $bdd = new Bdd();
                $bdd->requeter("USE ".Config::get('bdd_nom_floradata'));
                $condition = "longitude IS NULL OR latitude IS NULL OR longitude=0 OR latitude=0 ".
                "OR longitude>180 OR latitude>90 OR mots_cles_texte LIKE '%sensible%'";
                $requete =
                "SELECT COUNT(id_observation) AS nb_observations, ".
                "Floor(If({$condition},wgs84_latitude,latitude)*10)/10 AS lat, ".
                "Floor(If({$condition},wgs84_longitude,longitude)*10)/10 AS lng ".
                "FROM cel_obs LEFT JOIN cel_zones_geo cz ON ce_zone_geo=id_zone_geo ".
                "WHERE transmission=1 AND ".$this->construireWhereTaxon()." AND ".
                "(".
                        "(".
                                "longitude BETWEEN ".$this->limitesCarte['ouest']." AND ".$this->limitesCarte['est']." ".
                                "AND latitude BETWEEN ".$this->limitesCarte['sud']." AND ".$this->limitesCarte['nord'].
                        ") OR (".
                                "({$condition}) AND ".
                                "wgs84_longitude BETWEEN ".$this->limitesCarte['ouest']." AND ".$this->limitesCarte['est']." ".
                                "AND wgs84_latitude BETWEEN ".$this->limitesCarte['sud']." AND ".$this->limitesCarte['nord'].
                        ")".
                ") ".
                "GROUP BY Floor(If({$condition},wgs84_latitude,latitude)*10)/10, Floor(If({$condition},wgs84_longitude,longitude)*10)/10 ".
                "ORDER BY lat DESC, lng ASC";
                return $bdd->recupererTous($requete);
        }
        
        final protected function construireWhereTaxon() {
                $criteres = array();
                $nomRang = $this->obtenirNomRang($this->taxon);
                if ($nomRang == 'famille') {
                        $criteres[] = "famille=".$this->bdd->proteger($this->taxon['nom_sci']);
                } else {
                        $criteres[] = "nt=".$this->taxon['num_taxonomique'];
                        $sousTaxons = $this->recupererSynonymesEtSousEspeces();
                        foreach ($sousTaxons as $sousTaxon) {
                                $criteres[] ="nt=".$sousTaxon['num_taxonomique'];
                        }
                }
                return "(".implode(' OR ',array_unique($criteres)).")";
        }
        
}

?>