Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 212 | Go to most recent revision | Details | Compare with Previous | 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
	private function getTable() {
14
		$versions = $this->versions->getVersions();
15
		$derniereVersion = end($versions);
215 jpm 16
		$projetNom = strtolower($this->ressources->getProjetNom());
208 jpm 17
		return $projetNom.'_v'.$derniereVersion;
18
	}
19
 
20
	public function rechercherInfosNom() {
21
		$table = $this->getTable();
22
		$detailsId = $this->ressources->getDetailsId();
23
		$detailsId = $this->bdd->proteger($detailsId);
24
		$requete =
25
				'SELECT ns.*,  '.
26
				'	nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
27
				"FROM $table AS ns ".
28
				"	LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
29
				"	LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
30
				"WHERE ns.num_nom = $detailsId ";
31
		$resultats = $this->bdd->recuperer($requete);
32
		$nom = new NomDO($resultats);
33
		return $nom;
34
	}
35
 
36
	public function rechercherStricte() {
37
		$table = $this->getTable();
38
		$conditions = array();
39
		if ($masque = $this->parametres->getMasquePourBdd()) {
40
			$conditions[] = "ns.nom_sci = $masque";
41
		}
42
		if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) {
43
			$conditions[] = "ns.nom_supra_generique = $masqueSg";
44
		}
45
		if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) {
46
			$conditions[] = "ns.genre = $masqueGen";
47
		}
48
		if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) {
49
			$conditions[] = "ns.epithete_sp = $masqueSp";
50
		}
209 jpm 51
		$navigation = $this->getNavigation();
208 jpm 52
		$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*,  '.
209 jpm 53
			'	nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
54
			"FROM $table AS ns ".
55
			"	LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
56
			"	LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
57
			$this->getWhere($conditions).
58
			implode(' AND ', $conditions).
59
			'ORDER BY ns.nom_sci ASC '.
60
			"LIMIT $navigation ";
211 jpm 61
 
208 jpm 62
		$resultats = $this->bdd->recupererTous($requete);
63
 
64
		return $resultats;
65
	}
66
 
67
	public function rechercherEtendue() {
68
		$table = $this->getTable();
69
		$conditions = array();
70
		if ($masque = $this->parametres->getMasquePourBdd()) {
71
			$conditions[] = "ns.nom_sci LIKE $masque";
72
		}
73
		if ($masqueSg = $this->parametres->getMasquePourBdd('sg')) {
74
			$conditions[] = "ns.nom_supra_generique LIKE $masqueSg";
75
		}
76
		if ($masqueGen = $this->parametres->getMasquePourBdd('gen')) {
77
			$conditions[] = "ns.genre LIKE $masqueGen";
78
		}
79
		if ($masqueSp = $this->parametres->getMasquePourBdd('sp')) {
80
			$conditions[] = "ns.epithete_sp LIKE $masqueSp";
81
		}
209 jpm 82
		$navigation = $this->getNavigation();
208 jpm 83
		$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*,  '.
209 jpm 84
			'	nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
85
			"FROM $table AS ns ".
86
			"	LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
87
			"	LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
88
			$this->getWhere($conditions).
89
			implode(' AND ', $conditions).
90
			'ORDER BY ns.nom_sci ASC '.
91
			"LIMIT $navigation ";
208 jpm 92
 
93
		$resultats = $this->bdd->recupererTous($requete);
94
		return $resultats;
95
	}
96
 
97
	public function rechercherFloue() {
98
		$table = $this->getTable();
99
		$masque = $this->parametres->getMasquePourBdd();
212 jpm 100
		$where = $this->getWhere();
209 jpm 101
		$navigation = $this->getNavigation();
208 jpm 102
		$requete = 'SELECT SQL_CALC_FOUND_ROWS ns.*,  '.
209 jpm 103
			'	nr.nom_sci AS nr_nom_sci, nb.nom_sci AS nb_nom_sci '.
104
			"FROM $table AS ns ".
105
			"	LEFT JOIN $table AS nr ON (ns.num_nom_retenu = nr.num_nom) ".
106
			"	LEFT JOIN $table AS nb ON (ns.basionyme = nb.num_nom) ".
212 jpm 107
			$where .
108
			($masque ? ($where ? ' AND ' : ' WHERE ').
109
				"	(SOUNDEX(ns.nom_sci) = SOUNDEX($masque)) ".
110
				"	OR (SOUNDEX(REVERSE(ns.nom_sci)) = SOUNDEX(REVERSE($masque))) " : '').
209 jpm 111
			'ORDER BY ns.nom_sci ASC '.
112
			"LIMIT $navigation ";
208 jpm 113
		$resultats = $this->bdd->recupererTous($requete);
114
		return $resultats;
115
	}
116
 
209 jpm 117
	private function getNavigation() {
211 jpm 118
		$debut = (int) $this->parametres->get('navigation.depart');
209 jpm 119
		$nbre = $this->parametres->get('navigation.limite');
211 jpm 120
		$navigation = "$debut,$nbre";
121
		return $navigation;
209 jpm 122
	}
123
 
124
	private function getWhere($conditions = array()) {
125
		$where = '';
126
		if ($this->ressources->getServiceNom() == 'taxons') {
127
			$where = 'WHERE ns.num_nom = ns.num_nom_retenu ';
128
		} else if (count($conditions) > 0) {
129
			$where = 'WHERE ';
130
		}
131
		return $where;
132
	}
133
 
208 jpm 134
	public function recupererNombreNomsTotal() {
135
		$requete = 'SELECT FOUND_ROWS() AS nbre';
136
		$nombre = $this->bdd->recuperer($requete);
137
		return (int) $nombre['nbre'];
138
	}
139
}
140
?>