Subversion Repositories eFlore/Projets.eflore-projets

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

<?php
class NomDAO {
        private $bdd = null;
        private $projet = null;
        private $versions = null;

        public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd, Projet $projet, Versions $versions) {
                $this->ressources = $ressources;
                $this->parametres = $parametres;
                $this->bdd = $bdd;
                $this->projet = $projet;
                $this->versions = $versions;
        }

        private function getTable() {
                $versions = $this->versions->getVersions();
                $derniereVersion = end($versions);
                $projetNom = $this->projet->getNom();
                return $projetNom.'_v'.$derniereVersion;
        }

        public function rechercherInfosNom() {
                $table = $this->getTable();
                $detailsId = $this->ressources->getDetailsId();
                $detailsId = $this->bdd->proteger($detailsId);
                $requete =
                                'SELECT ns.*,  '.
                                '       nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
                                "FROM $table AS ns ".
                                "       LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
                                "       LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
                                "WHERE ns.num_nom = $detailsId ";
                $resultats = $this->bdd->recuperer($requete);
                $nom = new NomDO($resultats);
                return $nom;
        }

        public function rechercherStricte() {
                $table = $this->getTable();
                $conditions = array();
                if ($masque = $this->parametres->getMasquePourBdd()) {
                        $conditions[] = "ns.nom_sci = $masque";
                }
                if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) {
                        $conditions[] = "ns.nom_supra_generique = $masqueSg";
                }
                if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) {
                        $conditions[] = "ns.genre = $masqueGen";
                }
                if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) {
                        $conditions[] = "ns.epithete_sp = $masqueSp";
                }

                $requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*,  '.
                                                '       nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
                                                "FROM $table AS ns ".
                                                "       LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
                                                "       LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
                (count($conditions) > 0 ? 'WHERE ' : '').
                implode(' AND ', $conditions).
                                                'ORDER BY ns.nom_sci ASC '.
                                                'LIMIT 0,100';
                $resultats = $this->bdd->recupererTous($requete);

                return $resultats;
        }

        public function rechercherEtendue() {
                $table = $this->getTable();
                $conditions = array();
                if ($masque = $this->parametres->getMasquePourBdd()) {
                        $conditions[] = "ns.nom_sci LIKE $masque";
                }
                if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) {
                        $conditions[] = "ns.nom_supra_generique LIKE $masqueSg";
                }
                if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) {
                        $conditions[] = "ns.genre LIKE $masqueGen";
                }
                if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) {
                        $conditions[] = "ns.epithete_sp LIKE $masqueSp";
                }
                $requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*,  '.
                                '       nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
                                "FROM $table AS ns ".
                                "       LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
                                "       LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
                (count($conditions) > 0 ? 'WHERE ' : '').
                implode(' AND ', $conditions).
                                'ORDER BY ns.nom_sci ASC '.
                                'LIMIT 0,100';

                $resultats = $this->bdd->recupererTous($requete);
                return $resultats;
        }

        public function rechercherFloue() {
                $table = $this->getTable();
                $masque = $this->parametres->getMasquePourBdd();
                $requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*,  '.
                                '       nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
                                "FROM $table AS ns ".
                                "       LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
                                "       LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
                ($masque ? 'WHERE '.
                                        "       (SOUNDEX(ns.nom_sci) = SOUNDEX($masque)) ".
                                        "       OR (SOUNDEX(REVERSE(ns.nom_sci)) = SOUNDEX(REVERSE($masque))) " : '').
                                'ORDER BY ns.nom_sci ASC '.
                                'LIMIT 0,100';
                $resultats = $this->bdd->recupererTous($requete);
                return $resultats;
        }

        public function recupererNombreNomsTotal() {
                $requete = 'SELECT FOUND_ROWS() AS nbre';
                $nombre = $this->bdd->recuperer($requete);
                return (int) $nombre['nbre'];
        }
}
?>