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 |
|
618 |
mathilde |
37 |
private function chargerRepartition() {
|
747 |
aurelien |
38 |
$this->apiCartes->setProjet('chorodep');
|
|
|
39 |
$this->apiCartes->setLargeur('108x101');
|
312 |
jpm |
40 |
$urls = array();
|
|
|
41 |
foreach ($this->noms as $nom) {
|
|
|
42 |
if (array_key_exists('nom_retenu.code', $nom)) {
|
|
|
43 |
$id = $nom['nom_retenu.code'];
|
313 |
jpm |
44 |
$id = $this->supprimerCodeReftaxAvecNn($id);
|
747 |
aurelien |
45 |
$this->apiCartes->setId("nn:$id");
|
312 |
jpm |
46 |
if (array_key_exists($id, $urls) == false) {
|
747 |
aurelien |
47 |
$urls[$id] = $this->apiCartes->getUrlPng();
|
312 |
jpm |
48 |
}
|
|
|
49 |
}
|
|
|
50 |
}
|
|
|
51 |
$this->infosPourTpl['repartition']['urls'] = $urls;
|
282 |
gduche |
52 |
}
|
161 |
jpm |
53 |
|
|
|
54 |
public function getTplInfos() {
|
|
|
55 |
return $this->infosPourTpl;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public function getTplNom() {
|
|
|
59 |
return self::TPL_VUE;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
public function formater() {
|
199 |
delphine |
63 |
$this->obtenirUrlsPhotos();
|
|
|
64 |
$this->extraireInfosNomsPourTplDetermination();
|
618 |
mathilde |
65 |
$this->obtenirUrlsImagesCoste();
|
|
|
66 |
$this->chargerRepartition();
|
161 |
jpm |
67 |
}
|
618 |
mathilde |
68 |
|
|
|
69 |
private function obtenirUrlsImagesCoste() {
|
|
|
70 |
$this->extraireInfosTaxons();
|
|
|
71 |
$this->imagesService->setProjet('coste');
|
736 |
aurelien |
72 |
$tax = implode(',', $this->infosPourTpl['taxons']);
|
|
|
73 |
$this->imagesService->setNnTaxon($tax);
|
|
|
74 |
$costeImg = $this->imagesService->getInfosImagesTaxons();
|
|
|
75 |
if (!empty($costeImg)) {
|
|
|
76 |
foreach ($costeImg as $infos) {
|
|
|
77 |
$num_taxon = $infos['num_taxonomique'];
|
|
|
78 |
$images[$num_taxon][] = $infos['binaire.href'];
|
|
|
79 |
$this->infosPourTpl['imagesCoste'] = $images;
|
618 |
mathilde |
80 |
}
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
private function extraireInfosTaxons() {
|
|
|
85 |
foreach ($this->noms as $id => $nom ) {
|
|
|
86 |
if (array_key_exists('num_taxon', $nom)
|
|
|
87 |
&& array_key_exists('taxon', $nom)) {
|
|
|
88 |
$this->infosPourTpl['taxons'][$nom['taxon']] = $nom['num_taxon'];
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
}
|
161 |
jpm |
92 |
|
199 |
delphine |
93 |
private function obtenirUrlsPhotos() {
|
|
|
94 |
$nns = $this->extraireNnDesNoms();
|
|
|
95 |
$urls = $this->imagesService->getUrlsImagesParIdsNoms($nns);
|
|
|
96 |
$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReftaxDesUrls($urls);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
private function extraireNnDesNoms() {
|
|
|
100 |
$nns = array();
|
|
|
101 |
foreach ($this->noms as $id => $nom) {
|
|
|
102 |
if (array_key_exists('nom_retenu.code', $nom)) {
|
|
|
103 |
if (in_array($nom['nom_retenu.code'], $nns) == false) {
|
313 |
jpm |
104 |
$idAAjouter = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
|
199 |
delphine |
105 |
if (is_numeric($idAAjouter)) {
|
|
|
106 |
$nns[] = $idAAjouter;
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
return $nns;
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
private function supprimerCodeReftaxDesUrls($urls) {
|
313 |
jpm |
115 |
$urlsNettoyees = array();
|
199 |
delphine |
116 |
foreach ($urls as $id => $url) {
|
312 |
jpm |
117 |
$id = $this->supprimerCodeReftax($id);
|
199 |
delphine |
118 |
$urlsNettoyees[$id] = $url;
|
|
|
119 |
}
|
|
|
120 |
return $urlsNettoyees;
|
|
|
121 |
}
|
|
|
122 |
|
312 |
jpm |
123 |
private function supprimerCodeReftax($chaine) {
|
|
|
124 |
$codeReftax = $this->parametres->reftaxCourant.'.';
|
|
|
125 |
$chaine = str_replace($codeReftax, '', $chaine);
|
|
|
126 |
return $chaine;
|
|
|
127 |
}
|
798 |
mathilde |
128 |
|
|
|
129 |
function supprimerAccents($chaine){
|
|
|
130 |
return strtr($chaine,array('à' => 'a','á' => 'a','â' => 'a','ã' => 'a','ä' => 'a',
|
|
|
131 |
'ç' => 'c',
|
|
|
132 |
'è' => 'e','é' => 'e','ê' => 'e','ë' => 'e',
|
|
|
133 |
'ì' => 'i','í' => 'i','î' => 'i','ï' => 'i',
|
|
|
134 |
'ñ' => 'n',
|
|
|
135 |
'ò' => 'o', 'ó' => 'o' , 'ô' => 'o', 'õ' => 'o', 'ö' => 'o',
|
|
|
136 |
'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u',
|
|
|
137 |
'ý' => 'y', 'ÿ' => 'y'));
|
|
|
138 |
}
|
|
|
139 |
|
312 |
jpm |
140 |
|
199 |
delphine |
141 |
private function extraireInfosNomsPourTplDetermination() {
|
|
|
142 |
$taxons = array();
|
|
|
143 |
foreach ($this->noms as $idNomCourant => $nom) {
|
313 |
jpm |
144 |
$nn = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
|
798 |
mathilde |
145 |
$nom_min = strtolower($nom['nom_vernaculaire']);
|
|
|
146 |
$nom_ss_accent = $this->supprimerAccents($nom_min);
|
|
|
147 |
if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/', $nom_ss_accent )) {
|
|
|
148 |
//au moins un debute par la requête
|
|
|
149 |
if (isset($taxons) && array_key_exists($nn, $taxons[0]) == false) {
|
790 |
mathilde |
150 |
$taxons[0][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
|
|
|
151 |
}
|
|
|
152 |
$taxons[0][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
|
|
|
153 |
} else {
|
|
|
154 |
//contient
|
798 |
mathilde |
155 |
if (isset($taxons) && array_key_exists($nn, $taxons[1]) == false) {
|
790 |
mathilde |
156 |
$taxons[1][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
|
|
|
157 |
}
|
|
|
158 |
$taxons[1][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
|
199 |
delphine |
159 |
}
|
|
|
160 |
}
|
790 |
mathilde |
161 |
$this->infosPourTpl['noms'] = isset($taxons) ? $taxons : false;
|
199 |
delphine |
162 |
}
|
790 |
mathilde |
163 |
|
|
|
164 |
private function renvoyerInfosNomVerna($valeurs) {
|
|
|
165 |
$nom_verna = array();
|
|
|
166 |
$nom_verna['nn'] = $valeurs['id'];
|
|
|
167 |
$nom_verna['nom_vernaculaire'] = $valeurs['nom_vernaculaire'];
|
|
|
168 |
return $nom_verna;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
private function renvoyerInfosTaxon($nomSci, $nn) {
|
|
|
172 |
$taxon = array();
|
|
|
173 |
$taxon['nomSci'] = $nomSci;
|
|
|
174 |
$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
|
|
|
175 |
$taxon['repartition_vignette'] = $this->chargerRepartition($nn);
|
|
|
176 |
return $taxon;
|
|
|
177 |
}
|
312 |
jpm |
178 |
|
313 |
jpm |
179 |
private function supprimerCodeReftaxAvecNn($nn) {
|
199 |
delphine |
180 |
$codeReftax = $this->parametres->reftaxCourant.'.nn:';
|
|
|
181 |
return str_replace($codeReftax, '', $nn);
|
|
|
182 |
}
|
|
|
183 |
|
790 |
mathilde |
184 |
//tri alphabétique des noms scientifiques par catégorie (débute par , contient )
|
161 |
jpm |
185 |
public function trier() {
|
790 |
mathilde |
186 |
$verna = array();
|
|
|
187 |
foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
|
|
|
188 |
$verna += $this->classerAlphabetiquement('nomSci', $valeurs);
|
|
|
189 |
}
|
|
|
190 |
$this->infosPourTpl['noms'] = $verna;
|
161 |
jpm |
191 |
}
|
790 |
mathilde |
192 |
|
|
|
193 |
private function classerAlphabetiquement($champs, $valeurs) {
|
|
|
194 |
$this->trieur->setTableau($valeurs);
|
|
|
195 |
$this->trieur->setChampsEtOrdres(array($champs => SORT_NATURAL));
|
|
|
196 |
return $this->trieur->trier();
|
|
|
197 |
}
|
|
|
198 |
|
798 |
mathilde |
199 |
|
161 |
jpm |
200 |
|
|
|
201 |
public function surligner() {
|
202 |
delphine |
202 |
$this->definirMotsASurligner();
|
|
|
203 |
foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
|
|
|
204 |
foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
|
|
|
205 |
$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
|
|
|
206 |
}
|
|
|
207 |
$this->infosPourTpl['noms'][$idNom] = $nom;
|
|
|
208 |
}
|
161 |
jpm |
209 |
}
|
312 |
jpm |
210 |
|
202 |
delphine |
211 |
private function definirMotsASurligner() {
|
207 |
delphine |
212 |
$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
|
798 |
mathilde |
213 |
|
202 |
delphine |
214 |
}
|
790 |
mathilde |
215 |
|
202 |
delphine |
216 |
private function surlignerMotsMasqueRecherche($nom) {
|
|
|
217 |
$this->surligneur->setTexte($nom);
|
|
|
218 |
$nom = $this->surligneur->surlignerMots($this->motsASurligner);
|
|
|
219 |
return $nom;
|
|
|
220 |
}
|
161 |
jpm |
221 |
}
|
|
|
222 |
?>
|