Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 137 Rev 146
Line 12... Line 12...
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
12
 * @license		http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL-v2
13
 * @version		$Id$
13
 * @version		$Id$
14
 */
14
 */
15
class Resultat extends aControleur {
15
class Resultat extends aControleur {
Line 16... Line -...
16
 
-
 
17
	private $resultatType = 'determination';
-
 
18
	private $masqueRecherche = '';
16
 
19
	private $projetImg = 'cel';
17
	private $parametres = null;
Line 20... Line 18...
20
	private $reftaxCourant = 'bdtfx';
18
	private $resultats = null;
-
 
19
 
-
 
20
	public function initialiser() {
21
 
21
		spl_autoload_register(array($this, 'chargerClassesResultat'));
22
	public function initialiser() {
22
		$this->parametres = new ParametresResultats();
23
		$this->capturerParametres();
23
		$this->capturerParametres();
-
 
24
		$this->parametres->reftaxCourant = Registre::get('parametres.referentiel');
-
 
25
		$this->parametres->projetImg = Config::get($this->parametres->reftaxCourant.'.referentielImages');
-
 
26
		$this->resultats = Registre::get('resultats');
-
 
27
	}
-
 
28
 
-
 
29
	private function chargerClassesResultat($classe) {
-
 
30
		$dossiers = array(dirname(__FILE__).DS);
-
 
31
		foreach ($dossiers as $chemin) {
-
 
32
			$fichierATester = $chemin.$classe.'.php';
-
 
33
			if (file_exists($fichierATester)) {
-
 
34
				include_once $fichierATester;
-
 
35
				return null;
24
		$this->reftaxCourant = Registre::get('parametres.referentiel');
36
			}
Line 25... Line 37...
25
		$this->projetImg = Config::get($this->reftaxCourant.'.referentielImages');
37
		}
26
	}
38
	}
27
 
39
 
28
	private function capturerParametres() {
40
	private function capturerParametres() {
29
		if (isset($_GET['resultat'])) {
41
		if (isset($_GET['resultat'])) {
30
			$this->resultatType = $_GET['resultat'];
42
			$this->parametres->type = $_GET['resultat'];
31
		}
43
		}
32
		if (isset($_GET['nom'])) {
44
		if (isset($_GET['nom'])) {
Line 33... Line 45...
33
			$this->masqueRecherche = $_GET['nom'];
45
			$this->parametres->masqueRecherche = $_GET['nom'];
34
		}
46
		}
35
	}
47
	}
Line 36... Line 48...
36
 
48
 
37
	public function executerActionParDefaut() {
-
 
38
		$this->executerResultat();
49
	public function executerActionParDefaut() {
39
	}
50
		$this->executerResultat();
40
 
51
	}
41
	public function executerResultat() {
52
 
42
		$resultats = Registre::get('resultats');
53
	public function executerResultat() {
43
		$donnees = array();
54
		$donnees = array();
44
		$donnees['typeResultat'] = $this->resultatType;
55
		$donnees['typeResultat'] = $this->parametres->type;
45
		$donnees['urlResAlphab'] = $this->obtenirUrlResultatAlphab();
56
		$donnees['urlResAlphab'] = $this->obtenirUrlResultatAlphab();
Line 46... Line 57...
46
		$donnees['urlResRetenu'] = $this->obtenirUrlResultatRetenu();
57
		$donnees['urlResRetenu'] = $this->obtenirUrlResultatRetenu();
47
		$donnees['urlResDetermination'] = $this->obtenirUrlResultatDetermination();
58
		$donnees['urlResDetermination'] = $this->obtenirUrlResultatDetermination();
Line 48... Line 59...
48
		$donnees['urlResDecompo'] = $this->obtenirUrlResultatDecompo();
59
		$donnees['urlResDecompo'] = $this->obtenirUrlResultatDecompo();
49
		$donnees['nbreTaxons'] = $resultats['entete']['total'];
-
 
50
		$donnees['nomsHtml'] = $this->getNoms($resultats['resultat']);
60
		$donnees['nbreTaxons'] = $this->resultats['entete']['total'];
51
 
-
 
52
		$this->setSortie(self::RENDU_CORPS, $this->getVue('resultat', $donnees));
-
 
53
	}
-
 
54
 
-
 
55
	private function getNoms($resultats) {
-
 
56
		$noms = null;
-
 
57
		$methode = 'genererListe'.ucwords($this->resultatType);
-
 
58
		$noms = $this->$methode($resultats);
-
 
59
		return $noms;
-
 
60
	}
-
 
61
 
-
 
62
	private function genererListeAlphab($resultats) {
-
 
63
		$noms = $this->trierParAlphabNaturel($resultats);
-
 
64
		$noms = $this->surlignerNoms($noms);
-
 
65
 
-
 
66
		$donnees = array();
-
 
67
		$donnees['noms'] = $noms;
-
 
68
		return $this->getVue('resultat_liste_noms', $donnees);
-
 
69
	}
-
 
70
 
-
 
71
	private function surlignerNoms($noms) {
-
 
72
		foreach ($noms as $id => $nom) {
-
 
73
			$noms[$id]['nom_sci'] = $this->surlignerMotsMasqueRecherche($nom['nom_sci']);
61
		$donnees['nomsHtml'] = $this->getNomsFormates();
74
		}
62
 
75
		return $noms;
63
		$this->setSortie(self::RENDU_CORPS, $this->getVue('resultat', $donnees));
76
	}
-
 
77
 
-
 
78
	private function surlignerMotsMasqueRecherche($nom) {
-
 
79
		$mots = explode(' ', $this->masqueRecherche);
-
 
80
		$surligneur = new Surligneur();
-
 
81
		$surligneur->setTexte($nom);
-
 
82
		$nom = $surligneur->surlignerMots($mots);
-
 
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
	}
-
 
98
 
-
 
99
	private function trierParAlphabNaturel($noms) {
-
 
100
		$noms = Tableau::trierMDType($noms, array('nom_sci' => SORT_ASC), Tableau::TRI_NATUREL);
-
 
101
		return $noms;
-
 
102
	}
-
 
103
 
-
 
104
	private function genererListeRetenu($resultats) {
-
 
105
		$noms = $this->trierParNomsRetenus($resultats);
-
 
106
		$noms = $this->surlignerNoms($noms);
-
 
107
		$donnees = array();
-
 
108
		$donnees['noms'] = $noms;
-
 
109
		return $this->getVue('resultat_liste_noms', $donnees);
-
 
110
	}
-
 
111
 
-
 
112
	private function trierParNomsRetenus($noms) {
-
 
113
		$nomsRetenus = array();
-
 
114
		$nomsSynonymes = array();
-
 
115
		foreach ($noms as $id => $nom) {
-
 
116
			if ($nom['retenu'] == 'true') {
-
 
117
				$nomsRetenus[$id] = $nom;
-
 
118
			} else {
-
 
119
				$nomsSynonymes[$id] = $nom;
-
 
120
			}
-
 
121
		}
-
 
122
		$nomsRetenus = Tableau::trierMDType($nomsRetenus, array('nom_sci' => SORT_ASC), Tableau::TRI_NATUREL);
-
 
123
		$nomsSynonymes = Tableau::trierMDType($nomsSynonymes, array('nom_sci' => SORT_ASC), Tableau::TRI_NATUREL);
-
 
124
		$noms = array_merge($nomsRetenus, $nomsSynonymes);
-
 
125
		return $noms;
-
 
126
	}
-
 
127
 
-
 
128
	private function genererListeDetermination($resultats) {
-
 
129
		$donnees = array();
-
 
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;
64
	}
134
 
-
 
135
		if ($noms) {
-
 
136
			$noms = $this->tierNomsPourDetermination($noms);
-
 
137
			$noms = $this->surlignerNomsPourDetermination($noms);
-
 
138
		}
-
 
139
		$donnees['noms'] = $noms;
-
 
140
		return $this->getVue('resultat_determination_noms', $donnees);
-
 
141
	}
-
 
142
 
-
 
143
	private function obtenirUrlsPhotos($noms) {
-
 
144
		$ids = $this->extraireIdDesNoms($noms);
-
 
145
		$Images = new Images($this->projetImg);
-
 
146
		$urls = $Images->getUrlsImagesParIdsNoms($ids);
-
 
147
		$urlsReftaxCourant = $this->supprimerCodeReftaxDesIds($urls);
-
 
148
		return $urlsReftaxCourant;
-
 
149
	}
-
 
150
 
-
 
151
	private function extraireIdDesNoms($noms) {
-
 
152
		$ids = array();
-
 
153
		foreach ($noms as $id => $nom) {
-
 
154
			$ids[] = $id;
-
 
155
		}
-
 
156
		return $ids;
-
 
157
	}
-
 
158
 
-
 
159
	private function supprimerCodeReftaxDesIds($urls) {
-
 
160
		$codeReftax = $this->reftaxCourant.'.';
-
 
161
		foreach ($urls as $id => $url) {
-
 
162
			$id = str_replace($codeReftax, '', $id);
-
 
163
			$urls[$id] = $url;
-
 
164
		}
-
 
165
		return $urls;
-
 
166
	}
-
 
167
 
-
 
168
	private function extraireNomsPourDetermination($noms) {
-
 
169
		$nomsSansCorrespondance = array();
-
 
170
		$nomsAvecCorrespondance = array();
-
 
171
		foreach ($noms as $idNomCourant => $nom) {
-
 
172
			if ($nom['retenu'] == 'true') {
-
 
173
				$nomRetenu = array();
-
 
174
				$nomRetenu['nom_sci_retenu'] = $nom['nom_sci'];
-
 
175
				$nomRetenu['url'] = $this->obtenirUrlFiche($idNomCourant);
-
 
176
				$nomsAvecCorrespondance[$idNomCourant] = $nomRetenu;
-
 
177
			} else {
-
 
178
				if ($nom['nom_retenu'] == null) {
-
 
179
					$nomsSansCorrespondance[$idNomCourant] = $nom['nom_sci'];
-
 
180
				} else {
-
 
181
					$idNomRetenu = $nom['nom_retenu.id'];
-
 
182
					if (array_key_exists($nom['nom_retenu.id'], $nomsAvecCorrespondance) == false) {
-
 
183
						$nomRetenu = array();
-
 
184
						$nomRetenu['nom_sci_retenu'] = $nom['nom_retenu'];
-
 
185
						$nomRetenu['url'] = $this->obtenirUrlFiche($idNomRetenu);
-
 
186
						$nomsAvecCorrespondance[$idNomRetenu] = $nomRetenu;
-
 
187
					}
-
 
188
					$nomsAvecCorrespondance[$idNomRetenu]['synonymes'][] = array('nn' => $idNomCourant, 'nom_sci' => $nom['nom_sci']);
-
 
189
				}
-
 
190
 
-
 
191
			}
-
 
192
		}
-
 
193
		$nomsPourDetermination = array();
-
 
194
		if (count($nomsSansCorrespondance) > 0) {
-
 
195
			$nomsPourDetermination['nsc'] = $nomsSansCorrespondance;
-
 
196
		}
-
 
197
		if (count($nomsAvecCorrespondance) > 0) {
-
 
198
			$nomsPourDetermination['nac'] = $nomsAvecCorrespondance;
-
 
199
		}
-
 
200
		return $nomsPourDetermination;
-
 
201
	}
-
 
202
 
-
 
203
	public function tierNomsPourDetermination($noms) {
-
 
204
		$nom_demande_ss = strtolower(Chaine::supprimerAccents($this->masqueRecherche));
-
 
205
		foreach ($noms as $id => $nom) {
-
 
206
			$nom_flou_ss = strtolower(Chaine::supprimerAccents($nom['nom_sci_retenu']));
-
 
207
			$stat = array();
-
 
208
			// Prime pour la ressemblance globale :
-
 
209
			$score = 500 - levenshtein($nom_flou_ss, $nom_demande_ss);
-
 
210
			// On affine
-
 
211
			$score = $score + (similar_text($nom_demande_ss, $nom_flou_ss) * 3);
-
 
212
			$nom['score'] = $score;
-
 
213
			$noms[$id] = $nom;
-
 
214
		}
-
 
215
		$noms = Tableau::trierMD($noms, array('score' => SORT_DESC));
-
 
216
		return $noms;
-
 
217
	}
-
 
218
 
-
 
219
	private function surlignerNomsPourDetermination($noms) {
-
 
220
		foreach ($noms as $idNom => $nom) {
-
 
221
			$nom['nom_sci_retenu'] = $this->surlignerMotsMasqueRecherche($nom['nom_sci_retenu']);
-
 
222
			if (isset($nom['synonymes'])) {
65
 
223
				foreach ($nom['synonymes'] as $idSyn => $synonyme) {
-
 
224
					$nom['synonymes'][$idSyn]['nom_sci'] = $this->surlignerMotsMasqueRecherche($synonyme['nom_sci']);
-
 
225
				}
-
 
226
			}
-
 
227
			$noms[$idNom] = $nom;
66
	private function getNomsFormates() {
228
		}
67
		$resultatFormateur = ResultatFormateurFabrique::creer($this->parametres, $this->resultats);
229
		return $noms;
68
		$resultatFormateur->formater();
230
	}
69
		$resultatFormateur->trier();