Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 132 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 132 Rev 135
Line 13... Line 13...
13
 * @version		$Id$
13
 * @version		$Id$
14
 */
14
 */
15
class Resultat extends aControleur {
15
class Resultat extends aControleur {
Line 16... Line 16...
16
 
16
 
-
 
17
	private $resultatType = 'determination';
17
	private $resultatType = 'determination';
18
	private $masqueRecherche = '';
18
	private $projetImg = 'cel';
19
	private $projetImg = 'cel';
Line 19... Line 20...
19
	private $reftaxCourant = 'bdtfx';
20
	private $reftaxCourant = 'bdtfx';
20
 
21
 
Line 26... Line 27...
26
 
27
 
27
	private function capturerParametres() {
28
	private function capturerParametres() {
28
		if (isset($_GET['resultat'])) {
29
		if (isset($_GET['resultat'])) {
29
			$this->resultatType = $_GET['resultat'];
30
			$this->resultatType = $_GET['resultat'];
-
 
31
		}
-
 
32
		if (isset($_GET['nom'])) {
-
 
33
			$this->masqueRecherche = $_GET['nom'];
30
		}
34
		}
Line 31... Line 35...
31
	}
35
	}
32
 
36
 
33
	public function executerActionParDefaut() {
37
	public function executerActionParDefaut() {
Line 54... Line 58...
54
		$noms = $this->$methode($resultats);
58
		$noms = $this->$methode($resultats);
55
		return $noms;
59
		return $noms;
56
	}
60
	}
Line 57... Line 61...
57
 
61
 
-
 
62
	private function genererListeAlphab($resultats) {
-
 
63
		$noms = $this->trierParAlphabNaturel($resultats);
-
 
64
		$noms = $this->surlignerNoms($noms);
58
	private function genererListeAlphab($resultats) {
65
 
59
		$donnees = array();
66
		$donnees = array();
60
		$donnees['noms'] = $this->trierParNoms($resultats);
67
		$donnees['noms'] = $noms;
61
		return $this->getVue('resultat_liste_noms', $donnees);
68
		return $this->getVue('resultat_liste_noms', $donnees);
Line 62... Line 69...
62
	}
69
	}
-
 
70
 
-
 
71
	private function surlignerNoms($noms) {
-
 
72
		foreach ($noms as $id => $nom) {
-
 
73
			$noms[$id]['nom_sci'] = $this->surlignerMotsMasqueRecherche($nom['nom_sci']);
-
 
74
		}
-
 
75
		return $noms;
-
 
76
	}
-
 
77
 
-
 
78
	private function surlignerMotsMasqueRecherche($nom) {
-
 
79
		$mots = explode(' ', $this->masqueRecherche);
-
 
80
		foreach ($mots as $mot) {
-
 
81
			$nom = $this->surlignerMotDansTxt($mot, $nom);
-
 
82
		}
-
 
83
		return $nom;
-
 
84
	}
-
 
85
 
-
 
86
	private function surlignerMotDansTxt($mot, $txt){
-
 
87
		$ind = stripos($txt, $mot);
-
 
88
		$len = strlen($mot);
-
 
89
		$surlignage = $txt;
-
 
90
		if ($ind !== false){
-
 
91
			$debut = substr($txt, 0, $ind);
-
 
92
			$milieu = substr($txt, $ind, $len);
-
 
93
			$fin = $this->surlignerMotDansTxt($mot, substr($txt, $ind + $len));
-
 
94
			$surlignage = $debut.'<span class="surlignage">'.$milieu.'</span>'.$fin;
-
 
95
		}
-
 
96
		return $surlignage;
-
 
97
	}
63
 
98
 
64
	private function trierParNoms($noms) {
99
	private function trierParAlphabNaturel($noms) {
65
		$noms = Tableau::trierMD($noms, array('nom_sci' => SORT_ASC));
100
		$noms = Tableau::trierMDType($noms, array('nom_sci' => SORT_ASC), Tableau::TRI_NATUREL);
Line 66... Line 101...
66
		return $noms;
101
		return $noms;
-
 
102
	}
-
 
103
 
67
	}
104
	private function genererListeRetenu($resultats) {
68
 
105
		$noms = $this->trierParNomsRetenus($resultats);
69
	private function genererListeRetenu($resultats) {
106
		$noms = $this->surlignerNoms($noms);
70
		$donnees = array();
107
		$donnees = array();
Line 71... Line 108...
71
		$donnees['noms'] = $this->trierParNomsRetenus($resultats);
108
		$donnees['noms'] = $noms;
72
		return $this->getVue('resultat_liste_noms', $donnees);
109
		return $this->getVue('resultat_liste_noms', $donnees);
Line 80... Line 117...
80
				$nomsRetenus[$id] = $nom;
117
				$nomsRetenus[$id] = $nom;
81
			} else {
118
			} else {
82
				$nomsSynonymes[$id] = $nom;
119
				$nomsSynonymes[$id] = $nom;
83
			}
120
			}
84
		}
121
		}
85
		$nomsRetenus = Tableau::trierTableauMd($nomsRetenus, array('nom_sci' => SORT_ASC));
122
		$nomsRetenus = Tableau::trierMDType($nomsRetenus, array('nom_sci' => SORT_ASC), Tableau::TRI_NATUREL);
86
		$nomsSynonymes = Tableau::trierTableauMd($nomsSynonymes, array('nom_sci' => SORT_ASC));
123
		$nomsSynonymes = Tableau::trierMDType($nomsSynonymes, array('nom_sci' => SORT_ASC), Tableau::TRI_NATUREL);
87
		$noms = array_merge($nomsRetenus, $nomsSynonymes);
124
		$noms = array_merge($nomsRetenus, $nomsSynonymes);
88
		return $noms;
125
		return $noms;
89
	}
126
	}
Line 90... Line 127...
90
 
127
 
91
	private function genererListeDetermination($resultats) {
128
	private function genererListeDetermination($resultats) {
92
		$donnees = array();
129
		$donnees = array();
93
		$donnees['imagesUrls'] = $this->obtenirUrlsPhotos($resultats);
130
		$donnees['imagesUrls'] = $this->obtenirUrlsPhotos($resultats);
-
 
131
		$noms = $this->extraireNomsPourDetermination($resultats);
-
 
132
		$donnees['nomsSansCorrespondance'] = isset($noms['nsc']) ? $noms['nsc'] : false;
-
 
133
		$noms = isset($noms['nac']) ? $noms['nac'] : false;
-
 
134
 
-
 
135
		if ($noms) {
-
 
136
			$noms = $this->tierNomsPourDetermination($noms);
-
 
137
			$noms = $this->surlignerNomsPourDetermination($noms);
-
 
138
		}
94
		$donnees['noms'] = $this->trierSynonymes($resultats);
139
		$donnees['noms'] = $noms;
95
		return $this->getVue('resultat_determination_noms', $donnees);
140
		return $this->getVue('resultat_determination_noms', $donnees);
Line 96... Line 141...
96
	}
141
	}
97
 
142
 
Line 118... Line 163...
118
			$urls[$id] = $url;
163
			$urls[$id] = $url;
119
		}
164
		}
120
		return $urls;
165
		return $urls;
121
	}
166
	}
Line -... Line 167...
-
 
167
 
-
 
168
	private function surlignerNomsPourDetermination($noms) {
-
 
169
		foreach ($noms as $idNom => $nom) {
-
 
170
			$nom['nom_sci_retenu'] = $this->surlignerMotsMasqueRecherche($nom['nom_sci_retenu']);
-
 
171
			if (isset($nom['synonymes'])) {
-
 
172
				foreach ($nom['synonymes'] as $idSyn => $synonyme) {
-
 
173
					$nom['synonymes'][$idSyn]['nom_sci'] = $this->surlignerMotsMasqueRecherche($synonyme['nom_sci']);
-
 
174
				}
-
 
175
			}
-
 
176
			$noms[$idNom] = $nom;
-
 
177
		}
-
 
178
		return $noms;
-
 
179
	}
122
 
180
 
123
	private function trierSynonymes($noms) {
181
	private function extraireNomsPourDetermination($noms) {
124
		$nomsSansCorrespondance = array();
182
		$nomsSansCorrespondance = array();
125
		$nomsRetenus = array();
183
		$nomsAvecCorrespondance = array();
126
		foreach ($noms as $idNomCourant => $nom) {
184
		foreach ($noms as $idNomCourant => $nom) {
127
			if ($nom['retenu'] == 'true') {
185
			if ($nom['retenu'] == 'true') {
128
				$nomRetenu = array();
186
				$nomRetenu = array();
129
				$nomRetenu['nom_sci_retenu'] = $nom['nom_sci'];
187
				$nomRetenu['nom_sci_retenu'] = $nom['nom_sci'];
130
				$nomRetenu['url'] = $this->obtenirUrlFiche($idNomCourant);
188
				$nomRetenu['url'] = $this->obtenirUrlFiche($idNomCourant);
131
				$nomsRetenus[$idNomCourant] = $nomRetenu;
189
				$nomsAvecCorrespondance[$idNomCourant] = $nomRetenu;
132
			} else {
190
			} else {
133
				if ($nom['nom_retenu'] == null) {
191
				if ($nom['nom_retenu'] == null) {
134
					$nomsSansCorrespondance[] = array('nn' => $idNomCourant, 'nom_sci' => $nom['nom_sci']);
192
					$nomsSansCorrespondance[$idNomCourant] = $nom['nom_sci'];
135
				} else {
193
				} else {
136
					$idNomRetenu = $nom['nom_retenu.id'];
194
					$idNomRetenu = $nom['nom_retenu.id'];
137
					if (array_key_exists($nom['nom_retenu.id'], $nomsRetenus) == false) {
195
					if (array_key_exists($nom['nom_retenu.id'], $nomsAvecCorrespondance) == false) {
138
						$nomRetenu = array();
196
						$nomRetenu = array();
139
						$nomRetenu['nom_sci_retenu'] = $nom['nom_retenu'];
197
						$nomRetenu['nom_sci_retenu'] = $nom['nom_retenu'];
140
						$nomRetenu['url'] = $this->obtenirUrlFiche($idNomRetenu);
198
						$nomRetenu['url'] = $this->obtenirUrlFiche($idNomRetenu);
141
						$nomsRetenus[$idNomRetenu] = $nomRetenu;
199
						$nomsAvecCorrespondance[$idNomRetenu] = $nomRetenu;
142
					}
200
					}
143
					$nomsRetenus[$idNomRetenu]['synonymes'][] = array('nn' => $idNomCourant, 'nom_sci' => $nom['nom_sci']);
201
					$nomsAvecCorrespondance[$idNomRetenu]['synonymes'][] = array('nn' => $idNomCourant, 'nom_sci' => $nom['nom_sci']);
Line 144... Line 202...
144
				}
202
				}
145
 
203
 
146
			}
204
			}
147
		}
205
		}
148
		$nomsRetenus = Tableau::trierMD($nomsRetenus, array('nom_sci_retenu' => SORT_ASC));
206
		$nomsPourDetermination = array();
149
		if (count($nomsSansCorrespondance) > 0) {
207
		if (count($nomsSansCorrespondance) > 0) {
-
 
208
			$nomsPourDetermination['nsc'] = $nomsSansCorrespondance;
-
 
209
		}
-
 
210
		if (count($nomsAvecCorrespondance) > 0) {
-
 
211
			$nomsPourDetermination['nac'] = $nomsAvecCorrespondance;
-
 
212
		}
-
 
213
		return $nomsPourDetermination;
-
 
214
	}
-
 
215
 
-
 
216
	public function tierNomsPourDetermination($noms) {
-
 
217
		$nom_demande_ss = strtolower(Chaine::supprimerAccents($this->masqueRecherche));
-
 
218
		foreach ($noms as $id => $nom) {
-
 
219
			$nom_flou_ss = strtolower(Chaine::supprimerAccents($nom['nom_sci_retenu']));
-
 
220
			$stat = array();
-
 
221
			// Prime pour la ressemblance globale :
-
 
222
			$score = 500 - levenshtein($nom_flou_ss, $nom_demande_ss);
-
 
223
			// On affine
-
 
224
			$score = $score + (similar_text($nom_demande_ss, $nom_flou_ss) * 3);
-
 
225
			$nom['score'] = $score;
-
 
226
			$noms[$id] = $nom;
150
			$nomsRetenus['nsc']['liste'] = $nomsSansCorrespondance;
227
		}
151
		}
228
		$noms = Tableau::trierMD($noms, array('score' => SORT_DESC));
Line 152... Line 229...
152
		return $nomsRetenus;
229
		return $noms;
153
	}
230
	}
154
 
231