206 |
jpm |
1 |
<?php
|
215 |
jpm |
2 |
class TaxonsListeGenerique {
|
206 |
jpm |
3 |
|
|
|
4 |
private $parametres = null;
|
|
|
5 |
private $ressources = null;
|
209 |
jpm |
6 |
private $nomDao = null;
|
|
|
7 |
private $nomFormateur = null;
|
|
|
8 |
|
206 |
jpm |
9 |
private $listeUrl = null;
|
|
|
10 |
private $nbreTotalNoms = 0;
|
|
|
11 |
private $noms = array();
|
|
|
12 |
|
209 |
jpm |
13 |
public function __construct(Ressources $ressources, Parametres $parametres, NomDAO $nomDao, NomFormateur $nomFormateur) {
|
206 |
jpm |
14 |
$this->ressources = $ressources;
|
|
|
15 |
$this->parametres = $parametres;
|
209 |
jpm |
16 |
$this->nomDao = $nomDao;
|
|
|
17 |
$this->nomFormateur = $nomFormateur;
|
206 |
jpm |
18 |
}
|
|
|
19 |
|
|
|
20 |
public function setListeUrl($url) {
|
|
|
21 |
$this->listeUrl = $url;
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
public function consulter() {
|
|
|
25 |
$this->noms = $this->rechercher();
|
209 |
jpm |
26 |
$this->nbreNomsTotal = $this->nomDao->recupererNombreNomsTotal();
|
206 |
jpm |
27 |
$this->trierNoms();
|
|
|
28 |
$retour = $this->construireTableauRetour();
|
|
|
29 |
return $retour;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
private function rechercher() {
|
|
|
33 |
$resultats = array();
|
|
|
34 |
$recherche = $this->parametres->get('recherche');
|
|
|
35 |
|
|
|
36 |
if ($recherche == 'stricte') {
|
209 |
jpm |
37 |
$resultats = $this->nomDao->rechercherStricte();
|
206 |
jpm |
38 |
} else if ($recherche == 'etendue') {
|
209 |
jpm |
39 |
$resultats = $this->nomDao->rechercherEtendue();
|
206 |
jpm |
40 |
} else if ($recherche == 'floue') {
|
209 |
jpm |
41 |
$resultats = $this->nomDao->rechercherFloue();
|
206 |
jpm |
42 |
}
|
|
|
43 |
|
|
|
44 |
return $resultats;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
private function trierNoms() {
|
|
|
48 |
$recherche = $this->parametres->get('recherche');
|
|
|
49 |
if ($recherche == 'floue') {
|
|
|
50 |
$this->trierRechercheFloue();
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
public function trierRechercheFloue() {
|
|
|
55 |
$nomDemande = $this->parametres->get('masque');
|
|
|
56 |
$nomDemandeSimple = strtolower(Chaine::supprimerAccents($nomDemande));
|
|
|
57 |
|
|
|
58 |
foreach ($this->noms as $id => $nom) {
|
|
|
59 |
$nomFlouSimple = strtolower(Chaine::supprimerAccents($nom['nom_sci']));
|
|
|
60 |
// Prime pour la ressemblance globale :
|
|
|
61 |
$score = 500 - levenshtein($nomFlouSimple, $nomDemandeSimple);
|
|
|
62 |
// On affine
|
|
|
63 |
$score += similar_text($nomDemandeSimple, $nomFlouSimple) * 3;
|
|
|
64 |
$this->noms[$id]['score'] = $score;
|
|
|
65 |
}
|
|
|
66 |
$noms = $this->noms;
|
|
|
67 |
$this->noms = Tableau::trierMD($noms, array('score' => false));
|
|
|
68 |
//print_r($this->noms);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
private function construireTableauRetour() {
|
|
|
72 |
$retour = array('entete' => array(), 'resultats' => array());
|
|
|
73 |
$retour['resultats'] = $this->construireResultats();
|
|
|
74 |
$retour['entete'] = $this->construireEntete();
|
|
|
75 |
return $retour;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
private function construireResultats() {
|
|
|
79 |
$nomsFormates = array();
|
|
|
80 |
foreach ($this->noms as $nom) {
|
|
|
81 |
$id = $nom['num_nom'];
|
|
|
82 |
$nomsFormates[$id] = $this->formaterNom($nom);
|
|
|
83 |
}
|
|
|
84 |
return $nomsFormates;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
private function formaterNom($infos) {
|
|
|
88 |
$nomAFormater = new NomDO($infos);
|
209 |
jpm |
89 |
$this->nomFormateur->setNomAFormater($nomAFormater);
|
|
|
90 |
$this->nomFormateur->setChampsRetour($this->parametres->getListe('retour.champs'));
|
|
|
91 |
$nom = $this->nomFormateur->formaterListe();
|
206 |
jpm |
92 |
return $nom;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
private function construireEntete() {
|
|
|
96 |
$entete = array('masque' => '', 'depart' => 0, 'limite' => 100, 'total' => 0);
|
|
|
97 |
$entete['masque'] = $this->formaterEnteteMasque();
|
|
|
98 |
$entete['depart'] = (int) $this->parametres->get('navigation.depart');
|
|
|
99 |
$entete['limite'] = (int) $this->parametres->get('navigation.limite');
|
|
|
100 |
$entete['total'] = $this->nbreNomsTotal;
|
|
|
101 |
if ($hrefPrecedent = $this->formaterEnteteHrefPrecedent()) {
|
|
|
102 |
$entete['href.precedent'] = $hrefPrecedent;
|
|
|
103 |
}
|
|
|
104 |
if ($hrefSuivant = $this->formaterEnteteHrefSuivant()) {
|
|
|
105 |
$entete['href.suivant'] = $hrefSuivant;
|
|
|
106 |
}
|
|
|
107 |
return $entete;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
private function formaterEnteteMasque() {
|
|
|
111 |
$masqueComplet = array();
|
|
|
112 |
if ($this->parametres->exister('masque')) {
|
|
|
113 |
$masque = '';
|
|
|
114 |
$masque .= 'nom_sci='.$this->parametres->get('masque');
|
|
|
115 |
if ($this->parametres->get('recherche') == 'etendue') {
|
|
|
116 |
$masque .= '%';
|
|
|
117 |
}
|
|
|
118 |
$masqueComplet[] = $masque;
|
|
|
119 |
}
|
|
|
120 |
if ($this->parametres->exister('masque.sg')) {
|
|
|
121 |
$masque = '';
|
|
|
122 |
$masque .= 'nom_supra_generique='.$this->parametres->get('masque.sg');
|
|
|
123 |
if ($this->parametres->get('recherche') == 'etendue') {
|
|
|
124 |
$masque .= '%';
|
|
|
125 |
}
|
|
|
126 |
$masqueComplet[] = $masque;
|
|
|
127 |
}
|
|
|
128 |
if ($this->parametres->exister('masque.gen')) {
|
|
|
129 |
$masque = '';
|
|
|
130 |
$masque .= 'genre='.$this->parametres->get('masque.gen');
|
|
|
131 |
if ($this->parametres->get('recherche') == 'etendue') {
|
|
|
132 |
$masque .= '%';
|
|
|
133 |
}
|
|
|
134 |
$masqueComplet[] = $masque;
|
|
|
135 |
}
|
|
|
136 |
if ($this->parametres->exister('masque.sp')) {
|
|
|
137 |
$masque = '';
|
|
|
138 |
$masque .= 'epithete_sp='.$this->parametres->get('masque.sp');
|
|
|
139 |
if ($this->parametres->get('recherche') == 'etendue') {
|
|
|
140 |
$masque .= '%';
|
|
|
141 |
}
|
|
|
142 |
$masqueComplet[] = $masque;
|
|
|
143 |
}
|
|
|
144 |
return implode('&', $masqueComplet);
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
private function formaterEnteteHrefPrecedent() {
|
|
|
148 |
$limite = $this->parametres->get('navigation.limite');
|
|
|
149 |
$departActuel = $this->parametres->get('navigation.depart');
|
|
|
150 |
$departPrecedent = $departActuel - $limite;
|
|
|
151 |
$href = null;
|
|
|
152 |
if ($departPrecedent >= 0) {
|
|
|
153 |
$squelette = $this->construireTplHrefNavigation();
|
|
|
154 |
$href = sprintf($squelette, $departPrecedent, $limite);
|
|
|
155 |
}
|
|
|
156 |
return $href;
|
|
|
157 |
}
|
|
|
158 |
|
|
|
159 |
private function formaterEnteteHrefSuivant() {
|
|
|
160 |
$limite = $this->parametres->get('navigation.limite');
|
|
|
161 |
$departActuel = $this->parametres->get('navigation.depart');
|
|
|
162 |
$departSuivant = $departActuel + $limite;
|
|
|
163 |
$href = null;
|
|
|
164 |
if ($departSuivant < $this->nbreNomsTotal) {
|
|
|
165 |
$squelette = $this->construireTplHrefNavigation();
|
|
|
166 |
$href = sprintf($squelette, $departSuivant, $limite);
|
|
|
167 |
}
|
|
|
168 |
return $href;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
private function construireTplHrefNavigation() {
|
|
|
172 |
$requetes = array();
|
|
|
173 |
$this->parametres->rewind();
|
|
|
174 |
while (is_null($parametre = $this->parametres->key()) === false) {
|
|
|
175 |
if (strpos($parametre, 'navigation') === false) {
|
|
|
176 |
$valeur = $this->parametres->current();
|
|
|
177 |
$requetes[] = "$parametre=$valeur";
|
|
|
178 |
}
|
|
|
179 |
$this->parametres->next();
|
|
|
180 |
}
|
|
|
181 |
$requetes[] = "navigation.depart=%s";
|
|
|
182 |
$requetes[] = "navigation.limite=%s";
|
|
|
183 |
$tpl = $this->listeUrl.'?'.implode('&', $requetes);
|
|
|
184 |
return $tpl;
|
|
|
185 |
}
|
|
|
186 |
}
|
|
|
187 |
?>
|