Subversion Repositories eFlore/Projets.eflore-projets

Rev

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

Rev Author Line No. Line
208 jpm 1
<?php
2
class NomDAO {
3
	private $bdd = null;
4
	private $versions = null;
5
 
215 jpm 6
	public function __construct(Ressources $ressources, Parametres $parametres, Bdd $bdd, Versions $versions) {
208 jpm 7
		$this->ressources = $ressources;
8
		$this->parametres = $parametres;
9
		$this->bdd = $bdd;
10
		$this->versions = $versions;
11
	}
12
 
13
	public function rechercherInfosNom() {
14
		$table = $this->getTable();
15
		$detailsId = $this->ressources->getDetailsId();
16
		$detailsId = $this->bdd->proteger($detailsId);
17
		$requete =
18
				'SELECT ns.*,  '.
19
				'	nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
20
				"FROM $table AS ns ".
21
				"	LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
22
				"	LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
23
				"WHERE ns.num_nom = $detailsId ";
24
		$resultats = $this->bdd->recuperer($requete);
25
		$nom = new NomDO($resultats);
26
		return $nom;
27
	}
28
 
216 jpm 29
	public function rechercher() {
208 jpm 30
		$table = $this->getTable();
216 jpm 31
		$conditions = $this->getConditions();
32
		$where = $this->getWhere($conditions);
209 jpm 33
		$navigation = $this->getNavigation();
216 jpm 34
 
208 jpm 35
		$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*,  '.
209 jpm 36
			'	nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
37
			"FROM $table AS ns ".
38
			"	LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
39
			"	LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
216 jpm 40
			$where.$conditions.
209 jpm 41
			'ORDER BY ns.nom_sci ASC '.
42
			"LIMIT $navigation ";
211 jpm 43
 
208 jpm 44
		$resultats = $this->bdd->recupererTous($requete);
45
 
46
		return $resultats;
47
	}
48
 
49
	public function rechercherFloue() {
50
		$table = $this->getTable();
51
		$masque = $this->parametres->getMasquePourBdd();
212 jpm 52
		$where = $this->getWhere();
209 jpm 53
		$navigation = $this->getNavigation();
208 jpm 54
		$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*,  '.
209 jpm 55
			'	nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
56
			"FROM $table AS ns ".
57
			"	LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
58
			"	LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
212 jpm 59
			$where .
60
			($masque ? ($where ? ' AND ' : ' WHERE ').
61
				"	(SOUNDEX(ns.nom_sci) = SOUNDEX($masque)) ".
62
				"	OR (SOUNDEX(REVERSE(ns.nom_sci)) = SOUNDEX(REVERSE($masque))) " : '').
209 jpm 63
			'ORDER BY ns.nom_sci ASC '.
64
			"LIMIT $navigation ";
208 jpm 65
		$resultats = $this->bdd->recupererTous($requete);
66
		return $resultats;
67
	}
68
 
216 jpm 69
	private function getTable() {
70
		$versions = $this->versions->getVersions();
71
		$derniereVersion = end($versions);
72
		$projetNom = strtolower($this->ressources->getProjetNom());
73
		return $projetNom.'_v'.$derniereVersion;
209 jpm 74
	}
75
 
216 jpm 76
	private function getConditions() {
77
		$masquesStrictes = array('nn', 'rg');
78
		$paramsMasque = array(
79
			'' => 'nom_sci',
80
			'nn' => 'num_nom',
81
			'rg' => 'rang',
82
			'sg' => 'nom_supra_generique',
83
			'gen' => 'genre',
84
			'sp' => 'epithete_sp',
85
			'ssp' => 'epithete_infra_sp',
86
			'au' => 'auteur',
87
			'an' => 'annee');
88
 
89
		$operateurParDefaut = $this->getOperateurCondition();
90
		$conditionsSql = array();
91
		foreach ($paramsMasque as $typeMasque => $champ) {
92
			$operateur = in_array($typeMasque, $masquesStrictes) ? '=' : $operateurParDefaut;
93
			if ($valeurMasque = $this->parametres->getMasquePourBdd($typeMasque)) {
94
				$conditionsSql[] = "ns.$champ $operateur $valeurMasque";
95
			}
96
		}
97
		return implode(' AND ', $conditionsSql);
98
	}
99
 
100
	private function getOperateurCondition() {
101
		$operateur = '';
102
		$recherche = $this->parametres->get('recherche');
103
		if ($recherche == 'stricte') {
104
			$operateur = '=';
105
		} else if ($recherche == 'etendue') {
106
			$operateur = 'LIKE';
107
		}
108
		return $operateur;
109
	}
110
 
111
	private function getWhere($conditions = '') {
209 jpm 112
		$where = '';
113
		if ($this->ressources->getServiceNom() == 'taxons') {
114
			$where = 'WHERE ns.num_nom = ns.num_nom_retenu ';
216 jpm 115
		} else if ($conditions != '') {
209 jpm 116
			$where = 'WHERE ';
117
		}
118
		return $where;
119
	}
120
 
216 jpm 121
	private function getNavigation() {
122
		$debut = (int) $this->parametres->get('navigation.depart');
123
		$nbre = $this->parametres->get('navigation.limite');
124
		$navigation = "$debut,$nbre";
125
		return $navigation;
126
	}
127
 
208 jpm 128
	public function recupererNombreNomsTotal() {
129
		$requete = 'SELECT FOUND_ROWS() AS nbre';
130
		$nombre = $this->bdd->recuperer($requete);
131
		return (int) $nombre['nbre'];
132
	}
133
}
134
?>