161 |
jpm |
1 |
<?php
|
|
|
2 |
class DeterminationVernaFormateur implements Formateur {
|
|
|
3 |
|
|
|
4 |
const TPL_VUE = 'determination_verna';
|
|
|
5 |
|
|
|
6 |
private $parametres = null;
|
|
|
7 |
private $surligneur = null;
|
|
|
8 |
private $trieur = null;
|
|
|
9 |
private $urls = null;
|
|
|
10 |
private $fusioneur = null;
|
|
|
11 |
private $manipulateurDeChaine = null;
|
|
|
12 |
private $imagesService = null;
|
|
|
13 |
|
|
|
14 |
private $motsASurligner = array();
|
|
|
15 |
private $noms = array();
|
|
|
16 |
private $infosPourTpl = array();
|
747 |
aurelien |
17 |
|
|
|
18 |
private $conteneur = null;
|
|
|
19 |
private $apiCartes = null;
|
161 |
jpm |
20 |
|
|
|
21 |
public function __construct(ParametresResultats $parametres, Array $resultats,
|
|
|
22 |
Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
|
|
|
23 |
ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
|
|
|
24 |
|
|
|
25 |
$this->parametres = $parametres;
|
|
|
26 |
$this->noms = $resultats['resultat'];
|
|
|
27 |
$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
|
|
|
28 |
$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
|
|
|
29 |
$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
|
|
|
30 |
$this->manipulateurDeChaine = is_null($manipulateurDeChaine) ? new ChaineManipulateur() : $manipulateurDeChaine;
|
|
|
31 |
$this->imagesService = is_null($imagesService) ? new Images($this->parametres->projetImg) : $imagesService;
|
747 |
aurelien |
32 |
|
|
|
33 |
$this->conteneur = new Conteneur();
|
|
|
34 |
$this->apiCartes = $this->conteneur->getApiCartes();
|
161 |
jpm |
35 |
}
|
312 |
jpm |
36 |
|
161 |
jpm |
37 |
public function getTplInfos() {
|
|
|
38 |
return $this->infosPourTpl;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public function getTplNom() {
|
|
|
42 |
return self::TPL_VUE;
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
public function formater() {
|
931 |
delphine |
46 |
$this->obtenirUrlsDessins();
|
199 |
delphine |
47 |
$this->obtenirUrlsPhotos();
|
931 |
delphine |
48 |
$this->chargerRepartition();
|
199 |
delphine |
49 |
$this->extraireInfosNomsPourTplDetermination();
|
1274 |
aurelien |
50 |
$this->infosPourTpl['urlWidget'] = Config::get('base_url_widget_saisie')."?referentiel=".Registre::get('parametres.referentiel');
|
161 |
jpm |
51 |
}
|
618 |
mathilde |
52 |
|
931 |
delphine |
53 |
private function obtenirUrlsDessins() {
|
|
|
54 |
if (Config::get(Registre::get('parametres.referentiel').'.baseDessins') != "") {
|
|
|
55 |
$this->extraireInfosTaxons();
|
|
|
56 |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseDessins'));
|
|
|
57 |
$tax = implode(',', $this->infosPourTpl['taxons']);
|
|
|
58 |
$this->imagesService->setNnTaxon($tax);
|
1115 |
mathias |
59 |
$costeImg = $this->imagesService->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
|
931 |
delphine |
60 |
if (!empty($costeImg)) {
|
|
|
61 |
foreach ($costeImg as $infos) {
|
|
|
62 |
$num_taxon = $infos['num_taxonomique'];
|
|
|
63 |
$images[$num_taxon][] = $infos['binaire.href'];
|
|
|
64 |
$this->infosPourTpl['imagesCoste'] = $images;
|
|
|
65 |
}
|
618 |
mathilde |
66 |
}
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
private function extraireInfosTaxons() {
|
|
|
71 |
foreach ($this->noms as $id => $nom ) {
|
|
|
72 |
if (array_key_exists('num_taxon', $nom)
|
|
|
73 |
&& array_key_exists('taxon', $nom)) {
|
|
|
74 |
$this->infosPourTpl['taxons'][$nom['taxon']] = $nom['num_taxon'];
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
}
|
161 |
jpm |
78 |
|
199 |
delphine |
79 |
private function obtenirUrlsPhotos() {
|
1060 |
aurelien |
80 |
if (Config::get(Registre::get('parametres.referentiel').'.baseImages') != "") {
|
|
|
81 |
$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseImages'));
|
|
|
82 |
$nns = $this->extraireNnDesNoms();
|
1115 |
mathias |
83 |
$urls = $this->imagesService->setApi(Eflore::API_EFLORE)->getUrlsImagesParIdsNoms($nns);
|
1060 |
aurelien |
84 |
$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReferentielDesUrls($urls);
|
|
|
85 |
}
|
199 |
delphine |
86 |
}
|
|
|
87 |
|
|
|
88 |
private function extraireNnDesNoms() {
|
|
|
89 |
$nns = array();
|
|
|
90 |
foreach ($this->noms as $id => $nom) {
|
|
|
91 |
if (array_key_exists('nom_retenu.code', $nom)) {
|
|
|
92 |
if (in_array($nom['nom_retenu.code'], $nns) == false) {
|
931 |
delphine |
93 |
$idAAjouter = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
|
199 |
delphine |
94 |
if (is_numeric($idAAjouter)) {
|
|
|
95 |
$nns[] = $idAAjouter;
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
return $nns;
|
|
|
101 |
}
|
|
|
102 |
|
931 |
delphine |
103 |
private function supprimerCodeReferentielDesUrls($urls) {
|
313 |
jpm |
104 |
$urlsNettoyees = array();
|
199 |
delphine |
105 |
foreach ($urls as $id => $url) {
|
931 |
delphine |
106 |
$id = $this->supprimerCodeReferentiel($id);
|
199 |
delphine |
107 |
$urlsNettoyees[$id] = $url;
|
|
|
108 |
}
|
|
|
109 |
return $urlsNettoyees;
|
|
|
110 |
}
|
|
|
111 |
|
931 |
delphine |
112 |
private function supprimerCodeReferentiel($chaine) {
|
|
|
113 |
$codeReferentiel = $this->parametres->referentielCourant.'.';
|
|
|
114 |
$chaine = str_replace($codeReferentiel, '', $chaine);
|
312 |
jpm |
115 |
return $chaine;
|
|
|
116 |
}
|
798 |
mathilde |
117 |
|
931 |
delphine |
118 |
private function chargerRepartition() {
|
1068 |
raphael |
119 |
// $numsNomsASynonymes = $this->extraireNumerosNomSynonymes();
|
|
|
120 |
if (Config::get(Registre::get('parametres.referentiel').'.baseRepartition') == "") {
|
|
|
121 |
return;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
$this->apiCartes->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseRepartition'));
|
|
|
125 |
$this->apiCartes->setLargeur('108x101');
|
|
|
126 |
$urls = array();
|
|
|
127 |
foreach ($this->noms as $nom) {
|
|
|
128 |
if (array_key_exists('nom_retenu.code', $nom)) {
|
|
|
129 |
$id = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
|
|
|
130 |
$this->apiCartes->setId("nn:" . $id); // . ',' . implode(',', array_keys($numsNomsASynonymes[$id])));
|
|
|
131 |
if (array_key_exists($id, $urls) == false) {
|
|
|
132 |
$urls[$id] = $this->apiCartes->getUrlPng();
|
931 |
delphine |
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
1068 |
raphael |
136 |
$this->infosPourTpl['repartition']['urls'] = $urls;
|
931 |
delphine |
137 |
}
|
|
|
138 |
|
1004 |
aurelien |
139 |
private function extraireNumerosNomSynonymes() {
|
|
|
140 |
$numNomsASynonyme = array();
|
|
|
141 |
foreach ($this->noms as $id => $nom) {
|
|
|
142 |
$num_nom_retenu = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
|
1068 |
raphael |
143 |
// faux
|
|
|
144 |
$numNomsASynonyme[$num_nom_retenu][$id] = TRUE;
|
1004 |
aurelien |
145 |
}
|
|
|
146 |
return $numNomsASynonyme;
|
|
|
147 |
}
|
|
|
148 |
|
199 |
delphine |
149 |
private function extraireInfosNomsPourTplDetermination() {
|
|
|
150 |
$taxons = array();
|
|
|
151 |
foreach ($this->noms as $idNomCourant => $nom) {
|
1068 |
raphael |
152 |
$nn = intval($this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']));
|
|
|
153 |
$nomV = iconv('UTF-8', 'ASCII//TRANSLIT', strtolower($nom['nom_vernaculaire']));
|
|
|
154 |
if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).'(?: |$)/', $nomV)) {
|
|
|
155 |
// au moins un debute par la requête
|
798 |
mathilde |
156 |
if (isset($taxons) && array_key_exists($nn, $taxons[0]) == false) {
|
790 |
mathilde |
157 |
$taxons[0][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
|
|
|
158 |
}
|
|
|
159 |
$taxons[0][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
|
|
|
160 |
} else {
|
1068 |
raphael |
161 |
// contient
|
931 |
delphine |
162 |
if (isset($taxons) && (!isset($taxons[1]) || array_key_exists($nn, $taxons[1]) == false)) {
|
790 |
mathilde |
163 |
$taxons[1][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
|
|
|
164 |
}
|
|
|
165 |
$taxons[1][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
|
199 |
delphine |
166 |
}
|
|
|
167 |
}
|
790 |
mathilde |
168 |
$this->infosPourTpl['noms'] = isset($taxons) ? $taxons : false;
|
199 |
delphine |
169 |
}
|
790 |
mathilde |
170 |
|
|
|
171 |
private function renvoyerInfosNomVerna($valeurs) {
|
|
|
172 |
$nom_verna = array();
|
|
|
173 |
$nom_verna['nn'] = $valeurs['id'];
|
|
|
174 |
$nom_verna['nom_vernaculaire'] = $valeurs['nom_vernaculaire'];
|
|
|
175 |
return $nom_verna;
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
private function renvoyerInfosTaxon($nomSci, $nn) {
|
|
|
179 |
$taxon = array();
|
|
|
180 |
$taxon['nomSci'] = $nomSci;
|
|
|
181 |
$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
|
1068 |
raphael |
182 |
$this->chargerRepartition($nn);
|
|
|
183 |
$taxon['repartition_vignette'] = $this->infosPourTpl['repartition']['urls'];
|
790 |
mathilde |
184 |
return $taxon;
|
|
|
185 |
}
|
312 |
jpm |
186 |
|
931 |
delphine |
187 |
private function supprimerCodeReferentielAvecNn($nn) {
|
1068 |
raphael |
188 |
return str_replace($this->parametres->referentielCourant.'.nn:', '', $nn);
|
199 |
delphine |
189 |
}
|
|
|
190 |
|
790 |
mathilde |
191 |
//tri alphabétique des noms scientifiques par catégorie (débute par , contient )
|
161 |
jpm |
192 |
public function trier() {
|
790 |
mathilde |
193 |
$verna = array();
|
|
|
194 |
foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
|
|
|
195 |
$verna += $this->classerAlphabetiquement('nomSci', $valeurs);
|
|
|
196 |
}
|
|
|
197 |
$this->infosPourTpl['noms'] = $verna;
|
161 |
jpm |
198 |
}
|
790 |
mathilde |
199 |
|
|
|
200 |
private function classerAlphabetiquement($champs, $valeurs) {
|
|
|
201 |
$this->trieur->setTableau($valeurs);
|
931 |
delphine |
202 |
$this->trieur->setChampsEtOrdres(array($champs => 'nat'));
|
790 |
mathilde |
203 |
return $this->trieur->trier();
|
|
|
204 |
}
|
|
|
205 |
|
798 |
mathilde |
206 |
|
161 |
jpm |
207 |
|
|
|
208 |
public function surligner() {
|
202 |
delphine |
209 |
$this->definirMotsASurligner();
|
|
|
210 |
foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
|
|
|
211 |
foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
|
|
|
212 |
$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
|
|
|
213 |
}
|
|
|
214 |
$this->infosPourTpl['noms'][$idNom] = $nom;
|
|
|
215 |
}
|
161 |
jpm |
216 |
}
|
312 |
jpm |
217 |
|
202 |
delphine |
218 |
private function definirMotsASurligner() {
|
207 |
delphine |
219 |
$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
|
798 |
mathilde |
220 |
|
202 |
delphine |
221 |
}
|
790 |
mathilde |
222 |
|
202 |
delphine |
223 |
private function surlignerMotsMasqueRecherche($nom) {
|
|
|
224 |
$this->surligneur->setTexte($nom);
|
|
|
225 |
$nom = $this->surligneur->surlignerMots($this->motsASurligner);
|
|
|
226 |
return $nom;
|
|
|
227 |
}
|
161 |
jpm |
228 |
}
|
|
|
229 |
?>
|