Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 211 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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