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();
|
|
|
17 |
|
|
|
18 |
public function __construct(ParametresResultats $parametres, Array $resultats,
|
|
|
19 |
Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
|
|
|
20 |
ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
|
|
|
21 |
|
|
|
22 |
$this->parametres = $parametres;
|
|
|
23 |
$this->noms = $resultats['resultat'];
|
|
|
24 |
$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
|
|
|
25 |
$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
|
|
|
26 |
$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
|
|
|
27 |
$this->manipulateurDeChaine = is_null($manipulateurDeChaine) ? new ChaineManipulateur() : $manipulateurDeChaine;
|
|
|
28 |
$this->imagesService = is_null($imagesService) ? new Images($this->parametres->projetImg) : $imagesService;
|
618 |
mathilde |
29 |
|
161 |
jpm |
30 |
}
|
312 |
jpm |
31 |
|
618 |
mathilde |
32 |
private function chargerRepartition() {
|
312 |
jpm |
33 |
$conteneur = new Conteneur();
|
|
|
34 |
$cartesWs = $conteneur->getApiCartes();
|
|
|
35 |
$cartesWs->setProjet('chorodep');
|
|
|
36 |
$cartesWs->setLargeur('108x101');
|
|
|
37 |
$urls = array();
|
|
|
38 |
foreach ($this->noms as $nom) {
|
|
|
39 |
if (array_key_exists('nom_retenu.code', $nom)) {
|
|
|
40 |
$id = $nom['nom_retenu.code'];
|
313 |
jpm |
41 |
$id = $this->supprimerCodeReftaxAvecNn($id);
|
312 |
jpm |
42 |
$cartesWs->setId("nn:$id");
|
|
|
43 |
if (array_key_exists($id, $urls) == false) {
|
|
|
44 |
$urls[$id] = $cartesWs->getUrlPng();
|
|
|
45 |
}
|
|
|
46 |
}
|
|
|
47 |
}
|
|
|
48 |
$this->infosPourTpl['repartition']['urls'] = $urls;
|
282 |
gduche |
49 |
}
|
161 |
jpm |
50 |
|
|
|
51 |
public function getTplInfos() {
|
|
|
52 |
return $this->infosPourTpl;
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
public function getTplNom() {
|
|
|
56 |
return self::TPL_VUE;
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
public function formater() {
|
199 |
delphine |
60 |
$this->obtenirUrlsPhotos();
|
|
|
61 |
$this->extraireInfosNomsPourTplDetermination();
|
618 |
mathilde |
62 |
$this->obtenirUrlsImagesCoste();
|
|
|
63 |
$this->chargerRepartition();
|
161 |
jpm |
64 |
}
|
618 |
mathilde |
65 |
|
|
|
66 |
private function obtenirUrlsImagesCoste() {
|
|
|
67 |
$this->extraireInfosTaxons();
|
|
|
68 |
$this->imagesService->setProjet('coste');
|
736 |
aurelien |
69 |
$tax = implode(',', $this->infosPourTpl['taxons']);
|
|
|
70 |
$this->imagesService->setNnTaxon($tax);
|
|
|
71 |
$costeImg = $this->imagesService->getInfosImagesTaxons();
|
|
|
72 |
if (!empty($costeImg)) {
|
|
|
73 |
foreach ($costeImg as $infos) {
|
|
|
74 |
$num_taxon = $infos['num_taxonomique'];
|
|
|
75 |
$images[$num_taxon][] = $infos['binaire.href'];
|
|
|
76 |
$this->infosPourTpl['imagesCoste'] = $images;
|
618 |
mathilde |
77 |
}
|
|
|
78 |
}
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
private function extraireInfosTaxons() {
|
|
|
82 |
foreach ($this->noms as $id => $nom ) {
|
|
|
83 |
if (array_key_exists('num_taxon', $nom)
|
|
|
84 |
&& array_key_exists('taxon', $nom)) {
|
|
|
85 |
$this->infosPourTpl['taxons'][$nom['taxon']] = $nom['num_taxon'];
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
}
|
161 |
jpm |
89 |
|
199 |
delphine |
90 |
private function obtenirUrlsPhotos() {
|
|
|
91 |
$nns = $this->extraireNnDesNoms();
|
|
|
92 |
$urls = $this->imagesService->getUrlsImagesParIdsNoms($nns);
|
|
|
93 |
$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReftaxDesUrls($urls);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
private function extraireNnDesNoms() {
|
|
|
97 |
$nns = array();
|
|
|
98 |
foreach ($this->noms as $id => $nom) {
|
|
|
99 |
if (array_key_exists('nom_retenu.code', $nom)) {
|
|
|
100 |
if (in_array($nom['nom_retenu.code'], $nns) == false) {
|
313 |
jpm |
101 |
$idAAjouter = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
|
199 |
delphine |
102 |
if (is_numeric($idAAjouter)) {
|
|
|
103 |
$nns[] = $idAAjouter;
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
return $nns;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
private function supprimerCodeReftaxDesUrls($urls) {
|
313 |
jpm |
112 |
$urlsNettoyees = array();
|
199 |
delphine |
113 |
foreach ($urls as $id => $url) {
|
312 |
jpm |
114 |
$id = $this->supprimerCodeReftax($id);
|
199 |
delphine |
115 |
$urlsNettoyees[$id] = $url;
|
|
|
116 |
}
|
|
|
117 |
return $urlsNettoyees;
|
|
|
118 |
}
|
|
|
119 |
|
312 |
jpm |
120 |
private function supprimerCodeReftax($chaine) {
|
|
|
121 |
$codeReftax = $this->parametres->reftaxCourant.'.';
|
|
|
122 |
$chaine = str_replace($codeReftax, '', $chaine);
|
|
|
123 |
return $chaine;
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
|
199 |
delphine |
127 |
private function extraireInfosNomsPourTplDetermination() {
|
|
|
128 |
$taxons = array();
|
|
|
129 |
foreach ($this->noms as $idNomCourant => $nom) {
|
313 |
jpm |
130 |
$nn = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
|
199 |
delphine |
131 |
if (array_key_exists($nn, $taxons) == false) {
|
|
|
132 |
$taxon = array();
|
|
|
133 |
$taxon['nomSci'] = $nom['taxon'];
|
369 |
delphine |
134 |
$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
|
282 |
gduche |
135 |
$taxon['repartition_vignette'] = $this->chargerRepartition($nn);
|
199 |
delphine |
136 |
$taxons[$nn] = $taxon;
|
|
|
137 |
}
|
|
|
138 |
$nom_verna = array();
|
|
|
139 |
$nom_verna['nn'] = $nom['id'];
|
|
|
140 |
$nom_verna['nom_vernaculaire'] = $nom['nom_vernaculaire'];
|
|
|
141 |
$taxons[$nn]['nomVerna'][] = $nom_verna;
|
|
|
142 |
}
|
|
|
143 |
$this->infosPourTpl['noms'] = (count($taxons) > 0) ? $taxons : false;
|
|
|
144 |
}
|
312 |
jpm |
145 |
|
313 |
jpm |
146 |
private function supprimerCodeReftaxAvecNn($nn) {
|
199 |
delphine |
147 |
$codeReftax = $this->parametres->reftaxCourant.'.nn:';
|
|
|
148 |
return str_replace($codeReftax, '', $nn);
|
|
|
149 |
}
|
|
|
150 |
|
312 |
jpm |
151 |
|
161 |
jpm |
152 |
public function trier() {
|
|
|
153 |
|
|
|
154 |
}
|
|
|
155 |
|
|
|
156 |
public function surligner() {
|
202 |
delphine |
157 |
$this->definirMotsASurligner();
|
|
|
158 |
foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
|
|
|
159 |
foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
|
|
|
160 |
$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
|
|
|
161 |
}
|
|
|
162 |
$this->infosPourTpl['noms'][$idNom] = $nom;
|
|
|
163 |
}
|
161 |
jpm |
164 |
}
|
312 |
jpm |
165 |
|
202 |
delphine |
166 |
private function definirMotsASurligner() {
|
207 |
delphine |
167 |
$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
|
202 |
delphine |
168 |
}
|
312 |
jpm |
169 |
|
202 |
delphine |
170 |
private function surlignerMotsMasqueRecherche($nom) {
|
|
|
171 |
$this->surligneur->setTexte($nom);
|
|
|
172 |
$nom = $this->surligneur->surlignerMots($this->motsASurligner);
|
|
|
173 |
return $nom;
|
|
|
174 |
}
|
161 |
jpm |
175 |
}
|
|
|
176 |
?>
|