| Line 12... |
Line 12... |
| 12 |
private $imagesService = null;
|
12 |
private $imagesService = null;
|
| Line 13... |
Line 13... |
| 13 |
|
13 |
|
| 14 |
private $motsASurligner = array();
|
14 |
private $motsASurligner = array();
|
| 15 |
private $noms = array();
|
15 |
private $noms = array();
|
| 16 |
private $infosPourTpl = array();
|
16 |
private $infosPourTpl = array();
|
| 17 |
|
17 |
|
| 18 |
public function __construct(ParametresResultats $parametres, Array $resultats,
|
18 |
public function __construct(ParametresResultats $parametres, Array $resultats,
|
| 19 |
Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
|
19 |
Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
|
| Line 20... |
Line 20... |
| 20 |
ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
|
20 |
ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
|
| Line 35... |
Line 35... |
| 35 |
public function getTplNom() {
|
35 |
public function getTplNom() {
|
| 36 |
return self::TPL_VUE;
|
36 |
return self::TPL_VUE;
|
| 37 |
}
|
37 |
}
|
| Line 38... |
Line 38... |
| 38 |
|
38 |
|
| - |
|
39 |
public function formater() {
|
| - |
|
40 |
$this->extraireInfosTaxons();
|
| 39 |
public function formater() {
|
41 |
|
| 40 |
$this->obtenirUrlsDessins();
|
42 |
$this->obtenirUrlsDessins();
|
| 41 |
$this->obtenirUrlsPhotos();
|
43 |
$this->obtenirUrlsPhotos();
|
| - |
|
44 |
$this->chargerRepartition();
|
| 42 |
$this->chargerRepartition();
|
45 |
|
| 43 |
$this->extraireInfosNomsPourTplDetermination();
|
46 |
$this->extraireInfosNomsPourTplDetermination();
|
| 44 |
$this->infosPourTpl['urlWidget'] = Config::get('base_url_widget_saisie')."?referentiel=".Registre::get('parametres.referentiel');
|
47 |
$this->infosPourTpl['urlWidget'] = Config::get('base_url_widget_saisie')."?referentiel=".Registre::get('parametres.referentiel');
|
| 45 |
}
|
48 |
}
|
| 46 |
|
49 |
|
| 47 |
private function obtenirUrlsDessins() {
|
50 |
private function obtenirUrlsDessins() {
|
| 48 |
if (Config::get(Registre::get('parametres.referentiel').'.baseDessins') != "") {
|
- |
|
| 49 |
$this->extraireInfosTaxons();
|
51 |
if (Config::get(Registre::get('parametres.referentiel').'.baseDessins') != "") {
|
| 50 |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseDessins'));
|
52 |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseDessins'));
|
| 51 |
$tax = implode(',', $this->infosPourTpl['taxons']);
|
53 |
$tax = implode(',', $this->infosPourTpl['taxons']);
|
| 52 |
$this->imagesService->setNnTaxon($tax);
|
54 |
$this->imagesService->setNnTaxon($tax);
|
| 53 |
$costeImg = $this->imagesService->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
|
55 |
$costeImg = $this->imagesService->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
|
| Line 58... |
Line 60... |
| 58 |
$this->infosPourTpl['dessins'] = $images;
|
60 |
$this->infosPourTpl['dessins'] = $images;
|
| 59 |
}
|
61 |
}
|
| 60 |
}
|
62 |
}
|
| 61 |
}
|
63 |
}
|
| 62 |
}
|
64 |
}
|
| 63 |
|
65 |
|
| 64 |
private function extraireInfosTaxons() {
|
66 |
private function extraireInfosTaxons() {
|
| 65 |
foreach ($this->noms as $id => $nom ) {
|
67 |
foreach ($this->noms as $id => $nom ) {
|
| 66 |
if (array_key_exists('num_taxonomique', $nom)) {
|
68 |
if (array_key_exists('num_taxonomique', $nom)) {
|
| 67 |
$this->infosPourTpl['taxons'][$id] = $nom['num_taxonomique'];
|
69 |
$this->infosPourTpl['taxons'][$id] = $nom['num_taxonomique'];
|
| 68 |
}
|
70 |
}
|
| 69 |
}
|
71 |
}
|
| 70 |
}
|
72 |
}
|
| 71 |
|
73 |
|
| 72 |
private function obtenirUrlsPhotos() {
|
74 |
private function obtenirUrlsPhotos() {
|
| 73 |
if (Config::get(Registre::get('parametres.referentiel').'.baseImages') != "") {
|
75 |
if (Config::get(Registre::get('parametres.referentiel').'.baseImages') != "") {
|
| 74 |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseImages'));
|
76 |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseImages'));
|
| 75 |
$ids = $this->extraireIdDesNoms();
|
77 |
$ids = $this->extraireIdDesNoms();
|
| 76 |
$urls = $this->imagesService->setApi(Eflore::API_EFLORE)->getUrlsImagesParIdsNoms($ids);
|
78 |
$urls = $this->imagesService->setApi(Eflore::API_EFLORE)->getUrlsImagesParIdsNoms($ids);
|
| 77 |
$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReferentielDesIds($urls);
|
79 |
$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReferentielDesIds($urls);
|
| 78 |
}
|
80 |
}
|
| 79 |
}
|
81 |
}
|
| 80 |
|
82 |
|
| 81 |
private function extraireIdDesNoms() {
|
83 |
private function extraireIdDesNoms() {
|
| 82 |
$ids = array();
|
84 |
$ids = array();
|
| 83 |
foreach ($this->noms as $id => $nom) {
|
85 |
foreach ($this->noms as $id => $nom) {
|
| 84 |
$idAAjouter = $id;
|
86 |
$idAAjouter = $id;
|
| 85 |
if (is_numeric($idAAjouter)) {
|
87 |
if (is_numeric($idAAjouter)) {
|
| Line 94... |
Line 96... |
| 94 |
}
|
96 |
}
|
| 95 |
}
|
97 |
}
|
| 96 |
}
|
98 |
}
|
| 97 |
return $ids;
|
99 |
return $ids;
|
| 98 |
}
|
100 |
}
|
| 99 |
|
101 |
|
| 100 |
private function extraireNumerosNomSynonymes() {
|
- |
|
| 101 |
$numNomsASynonyme = array();
|
- |
|
| 102 |
foreach ($this->noms as $id => $nom) {
|
- |
|
| 103 |
// certains taxons requêtés via /bdtfx/noms?masque= n'ont pas de num_tax ni de num_nom_retenu
|
- |
|
| 104 |
if(!isset($nom['nom_retenu.id'])) continue;
|
- |
|
| 105 |
$num_nom_retenu = $nom['nom_retenu.id'];
|
- |
|
| 106 |
if(!isset($numNomsASynonyme[$num_nom_retenu])) {
|
- |
|
| 107 |
$numNomsASynonyme[$num_nom_retenu] = array();
|
- |
|
| 108 |
}
|
- |
|
| 109 |
$numNomsASynonyme[$num_nom_retenu][] = $id;
|
- |
|
| 110 |
if($num_nom_retenu != $id) {
|
- |
|
| 111 |
$numNomsASynonyme[$id] = $numNomsASynonyme[$num_nom_retenu];
|
- |
|
| 112 |
}
|
- |
|
| 113 |
}
|
- |
|
| 114 |
return $numNomsASynonyme;
|
- |
|
| 115 |
}
|
- |
|
| 116 |
|
- |
|
| 117 |
private function supprimerCodeReferentielDesIds($urls) {
|
102 |
private function supprimerCodeReferentielDesIds($urls) {
|
| 118 |
$urlsNettoyees = array();
|
103 |
$urlsNettoyees = array();
|
| 119 |
foreach ($urls as $id => $url) {
|
104 |
foreach ($urls as $id => $url) {
|
| 120 |
$id = $this->supprimerCodeReferentiel($id);
|
105 |
$id = $this->supprimerCodeReferentiel($id);
|
| 121 |
$urlsNettoyees[$id] = $url;
|
106 |
$urlsNettoyees[$id] = $url;
|
| 122 |
}
|
107 |
}
|
| 123 |
return $urlsNettoyees;
|
108 |
return $urlsNettoyees;
|
| 124 |
}
|
109 |
}
|
| 125 |
|
110 |
|
| 126 |
private function supprimerCodeReferentiel($chaine) {
|
111 |
private function supprimerCodeReferentiel($chaine) {
|
| 127 |
$codeReferentiel = Registre::get('parametres.referentiel').'.';
|
112 |
$codeReferentiel = Registre::get('parametres.referentiel').'.';
|
| 128 |
$chaine = str_replace($codeReferentiel, '', $chaine);
|
113 |
$chaine = str_replace($codeReferentiel, '', $chaine);
|
| 129 |
return $chaine;
|
114 |
return $chaine;
|
| 130 |
}
|
115 |
}
|
| 131 |
|
116 |
|
| 132 |
// TODO : utiliser le conteneur pour charger tous les objets de cette classe
|
117 |
// TODO : utiliser le conteneur pour charger tous les objets de cette classe
|
| 133 |
private function chargerRepartition() {
|
118 |
private function chargerRepartition() {
|
| - |
|
119 |
$referentiel = Registre::get('parametres.referentiel');
|
| 134 |
if (Config::get(Registre::get('parametres.referentiel').'.baseRepartition') != "") {
|
120 |
if (Config::get("$referentiel.baseRepartition") != '') {
|
| 135 |
$conteneur = new Conteneur();
|
121 |
$conteneur = new Conteneur();
|
| 136 |
$cartesWs = $conteneur->getApiCartes();
|
122 |
$cartesWs = $conteneur->getApiCartes();
|
| 137 |
$cartesWs->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseRepartition'));
|
123 |
$cartesWs->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseRepartition'));
|
| 138 |
$cartesWs->setLargeur('108x101');
|
124 |
$cartesWs->setLargeur('108x101');
|
| 139 |
$urls = array();
|
125 |
$urls = array();
|
| 140 |
$numsNomsASynonymes = $this->extraireNumerosNomSynonymes();
|
- |
|
| 141 |
foreach ($this->noms as $id => $nom) {
|
126 |
foreach ($this->noms as $id => $nom) {
|
| 142 |
if (array_key_exists('nom_retenu.id', $nom)) {
|
127 |
if (array_key_exists('num_taxonomique', $nom)) {
|
| 143 |
$id = $nom['nom_retenu.id'];
|
128 |
$nt = $nom['num_taxonomique'];
|
| 144 |
$idsNoms = $numsNomsASynonymes[$id];
|
- |
|
| 145 |
$cartesWs->setId("nn:".implode(',',$idsNoms)."");
|
129 |
$cartesWs->setId("$referentiel.nt:$nt");
|
| 146 |
if (array_key_exists($id, $urls) == false) {
|
130 |
if (array_key_exists($id, $urls) == false) {
|
| 147 |
$urls[$id] = $cartesWs->getUrlPng();
|
131 |
$urls[$id] = $cartesWs->getUrlPng();
|
| 148 |
}
|
132 |
}
|
| 149 |
}
|
133 |
}
|
| 150 |
}
|
134 |
}
|
| Line 156... |
Line 140... |
| 156 |
$tri = $this->diviserResultats();
|
140 |
$tri = $this->diviserResultats();
|
| 157 |
$this->infosPourTpl['nomsSansCorrespondance'] = isset($tri['sansCorres']) ? $tri['sansCorres'] : false;
|
141 |
$this->infosPourTpl['nomsSansCorrespondance'] = isset($tri['sansCorres']) ? $tri['sansCorres'] : false;
|
| 158 |
$this->infosPourTpl['noms'] = isset($tri['retenus']) ? $tri['retenus'] : false;
|
142 |
$this->infosPourTpl['noms'] = isset($tri['retenus']) ? $tri['retenus'] : false;
|
| 159 |
$this->infosPourTpl['synonymes'] = isset($tri['synonymes'] ) ? $tri['synonymes'] : false;
|
143 |
$this->infosPourTpl['synonymes'] = isset($tri['synonymes'] ) ? $tri['synonymes'] : false;
|
| 160 |
}
|
144 |
}
|
| 161 |
|
145 |
|
| 162 |
/**
|
146 |
/**
|
| 163 |
* division ordonnée par
|
147 |
* division ordonnée par
|
| 164 |
* 1 - noms retenus qui commencent par la requete
|
148 |
* 1 - noms retenus qui commencent par la requete
|
| 165 |
* 2 - requete contenue dans un synonyme dont le nom retenu ne contient pas la requete
|
149 |
* 2 - requete contenue dans un synonyme dont le nom retenu ne contient pas la requete
|
| 166 |
* 3 - requete contenue dans un hybride retenu
|
150 |
* 3 - requete contenue dans un hybride retenu
|
| 167 |
* 4 - requete contenue dans un nom retenu mais pas au début
|
151 |
* 4 - requete contenue dans un nom retenu mais pas au début
|
| 168 |
* 5 - requete contenue dans un nom sans correspondance
|
152 |
* 5 - requete contenue dans un nom sans correspondance
|
| 169 |
*
|
153 |
*
|
| 170 |
*/
|
154 |
*/
|
| 171 |
private function diviserResultats() {
|
155 |
private function diviserResultats() {
|
| 172 |
$tri = array();
|
156 |
$tri = array();
|
| 173 |
$sansCorres = array();
|
157 |
$sansCorres = array();
|
| 174 |
$synonymes = array();
|
158 |
$synonymes = array();
|
| Line 181... |
Line 165... |
| 181 |
//hybrides
|
165 |
//hybrides
|
| 182 |
$retenus[2][$cle] = $this->retournerInfosNomRetenu($cle,$valeurs['nom_sci_complet'], $valeurs['rang.libelle']);
|
166 |
$retenus[2][$cle] = $this->retournerInfosNomRetenu($cle,$valeurs['nom_sci_complet'], $valeurs['rang.libelle']);
|
| 183 |
} elseif (strripos($valeurs['nom_sci_complet'], $this->parametres->masqueRecherche) === 0) {//preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/', strtolower($valeurs['nom_sci']) ) ) {
|
167 |
} elseif (strripos($valeurs['nom_sci_complet'], $this->parametres->masqueRecherche) === 0) {//preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/', strtolower($valeurs['nom_sci']) ) ) {
|
| 184 |
//commence par
|
168 |
//commence par
|
| 185 |
$retenus[0][$cle] = $this->retournerInfosNomRetenu($cle,$valeurs['nom_sci_complet'], $valeurs['rang.libelle']);
|
169 |
$retenus[0][$cle] = $this->retournerInfosNomRetenu($cle,$valeurs['nom_sci_complet'], $valeurs['rang.libelle']);
|
| 186 |
} else {
|
170 |
} else {
|
| 187 |
//contient
|
171 |
//contient
|
| 188 |
$retenus[3][$cle] = $this->retournerInfosNomRetenu($cle,$valeurs['nom_sci_complet'], $valeurs['rang.libelle']);
|
172 |
$retenus[3][$cle] = $this->retournerInfosNomRetenu($cle,$valeurs['nom_sci_complet'], $valeurs['rang.libelle']);
|
| 189 |
}
|
173 |
}
|
| 190 |
} else {//synonymes
|
174 |
} else {//synonymes
|
| 191 |
$idNomRetenu = $valeurs['nom_retenu.id'];
|
175 |
$idNomRetenu = $valeurs['nom_retenu.id'];
|
| Line 201... |
Line 185... |
| 201 |
$tri['retenus'] = $retenus;
|
185 |
$tri['retenus'] = $retenus;
|
| 202 |
$tri['synonymes'] = $synonymes;
|
186 |
$tri['synonymes'] = $synonymes;
|
| 203 |
$tri['sansCorres'] = $sansCorres;
|
187 |
$tri['sansCorres'] = $sansCorres;
|
| 204 |
return $tri;
|
188 |
return $tri;
|
| 205 |
}
|
189 |
}
|
| 206 |
|
190 |
|
| 207 |
private function retournerInfosNomRetenu($cle, $nom_sci, $rang) {
|
191 |
private function retournerInfosNomRetenu($cle, $nom_sci, $rang) {
|
| 208 |
$infos = array();
|
192 |
$infos = array();
|
| 209 |
$infos['nomSciRetenu'] = $nom_sci;
|
193 |
$infos['nomSciRetenu'] = $nom_sci;
|
| 210 |
$infos['urlFiche'] = $this->urls->obtenirUrlFiche($cle, $this->parametres->typeNom, strtolower($this->parametres->masqueRecherche), $nom_sci);
|
194 |
$infos['urlFiche'] = $this->urls->obtenirUrlFiche($cle, $this->parametres->typeNom, strtolower($this->parametres->masqueRecherche), $nom_sci);
|
| 211 |
$infos['rang'] = $rang;
|
195 |
$infos['rang'] = $rang;
|
| 212 |
return $infos;
|
196 |
return $infos;
|
| 213 |
}
|
197 |
}
|
| 214 |
|
198 |
|
| 215 |
private function retournerInfosSynonyme($cle, $valeurs) {
|
199 |
private function retournerInfosSynonyme($cle, $valeurs) {
|
| 216 |
$infos = array();
|
200 |
$infos = array();
|
| 217 |
$infos['nn'] = $cle;
|
201 |
$infos['nn'] = $cle;
|
| 218 |
$infos['nomSci'] = $valeurs['nom_sci_complet'];
|
202 |
$infos['nomSci'] = $valeurs['nom_sci_complet'];
|
| 219 |
$infos['urlFiche'] = $this->urls->obtenirUrlFiche($cle, $this->parametres->typeNom, $this->parametres->masqueRecherche, $valeurs['nom_retenu.libelle']);
|
203 |
$infos['urlFiche'] = $this->urls->obtenirUrlFiche($cle, $this->parametres->typeNom, $this->parametres->masqueRecherche, $valeurs['nom_retenu.libelle']);
|
| 220 |
return $infos;
|
204 |
return $infos;
|
| 221 |
}
|
205 |
}
|
| 222 |
|
206 |
|
| 223 |
public function trier() {
|
207 |
public function trier() {
|
| 224 |
$nomsRetenus = array();
|
208 |
$nomsRetenus = array();
|
| 225 |
foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs ) { //classement alpha par groupes
|
209 |
foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs ) { //classement alpha par groupes
|
| 226 |
$nomsRetenus += $this->classerAlphabetiquement('nomSciRetenu', $valeurs);
|
210 |
$nomsRetenus += $this->classerAlphabetiquement('nomSciRetenu', $valeurs);
|
| 227 |
}
|
211 |
}
|
| 228 |
$this->infosPourTpl['noms'] = $nomsRetenus;
|
212 |
$this->infosPourTpl['noms'] = $nomsRetenus;
|
| 229 |
$this->infosPourTpl['nomsSansCorrespondance'] =
|
213 |
$this->infosPourTpl['nomsSansCorrespondance'] =
|
| 230 |
$this->classerAlphabetiquement('nomSciRetenu', $this->infosPourTpl['nomsSansCorrespondance'] );
|
214 |
$this->classerAlphabetiquement('nomSciRetenu', $this->infosPourTpl['nomsSansCorrespondance'] );
|
| 231 |
}
|
215 |
}
|
| 232 |
|
216 |
|
| 233 |
private function ajouterAuxNomsScoreSimilariteAvec($masque) {
|
217 |
private function ajouterAuxNomsScoreSimilariteAvec($masque) {
|
| 234 |
$nom_demande_ss = strtolower($this->manipulateurDeChaine->supprimerAccents($masque));
|
218 |
$nom_demande_ss = strtolower($this->manipulateurDeChaine->supprimerAccents($masque));
|
| 235 |
foreach ($this->infosPourTpl['noms'] as $id => $nom) {
|
219 |
foreach ($this->infosPourTpl['noms'] as $id => $nom) {
|
| 236 |
$nom_flou_ss = strtolower($this->manipulateurDeChaine->supprimerAccents($nom['nomSciRetenu']));
|
220 |
$nom_flou_ss = strtolower($this->manipulateurDeChaine->supprimerAccents($nom['nomSciRetenu']));
|
| 237 |
$stat = array();
|
221 |
$stat = array();
|
| Line 241... |
Line 225... |
| 241 |
$score = $score + (similar_text($nom_demande_ss, $nom_flou_ss) * 3);
|
225 |
$score = $score + (similar_text($nom_demande_ss, $nom_flou_ss) * 3);
|
| 242 |
$nom['score'] = $score;
|
226 |
$nom['score'] = $score;
|
| 243 |
$this->infosPourTpl['noms'][$id] = $nom;
|
227 |
$this->infosPourTpl['noms'][$id] = $nom;
|
| 244 |
}
|
228 |
}
|
| 245 |
}
|
229 |
}
|
| 246 |
|
230 |
|
| 247 |
private function classerAlphabetiquement($champs, $valeurs) {
|
231 |
private function classerAlphabetiquement($champs, $valeurs) {
|
| 248 |
$this->trieur->setTableau($valeurs);
|
232 |
$this->trieur->setTableau($valeurs);
|
| 249 |
$this->trieur->setChampsEtOrdres(array($champs => 'nat'));
|
233 |
$this->trieur->setChampsEtOrdres(array($champs => 'nat'));
|
| 250 |
return $this->trieur->trier();
|
234 |
return $this->trieur->trier();
|
| 251 |
}
|
235 |
}
|
| Line 259... |
Line 243... |
| 259 |
$this->infosPourTpl['synonymes'][$idNom][$idSyn]['nomSci'] = $this->surlignerMotsMasqueRecherche($synonyme['nomSci']);
|
243 |
$this->infosPourTpl['synonymes'][$idNom][$idSyn]['nomSci'] = $this->surlignerMotsMasqueRecherche($synonyme['nomSci']);
|
| 260 |
}
|
244 |
}
|
| 261 |
}
|
245 |
}
|
| 262 |
}
|
246 |
}
|
| 263 |
}
|
247 |
}
|
| 264 |
|
248 |
|
| 265 |
private function definirMotsASurligner() {
|
249 |
private function definirMotsASurligner() {
|
| 266 |
$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
|
250 |
$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
|
| 267 |
}
|
251 |
}
|
| 268 |
private function surlignerMotsMasqueRecherche($nom) {
|
252 |
private function surlignerMotsMasqueRecherche($nom) {
|
| 269 |
$this->surligneur->setTexte($nom);
|
253 |
$this->surligneur->setTexte($nom);
|