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;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
public function getTplInfos() {
|
|
|
32 |
return $this->infosPourTpl;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public function getTplNom() {
|
|
|
36 |
return self::TPL_VUE;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
public function formater() {
|
199 |
delphine |
40 |
$this->obtenirUrlsPhotos();
|
|
|
41 |
$this->extraireInfosNomsPourTplDetermination();
|
161 |
jpm |
42 |
}
|
|
|
43 |
|
199 |
delphine |
44 |
private function obtenirUrlsPhotos() {
|
|
|
45 |
$nns = $this->extraireNnDesNoms();
|
|
|
46 |
|
|
|
47 |
$urls = $this->imagesService->getUrlsImagesParIdsNoms($nns);
|
|
|
48 |
|
|
|
49 |
$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReftaxDesUrls($urls);
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
private function extraireNnDesNoms() {
|
|
|
53 |
$nns = array();
|
|
|
54 |
foreach ($this->noms as $id => $nom) {
|
|
|
55 |
if (array_key_exists('nom_retenu.code', $nom)) {
|
|
|
56 |
if (in_array($nom['nom_retenu.code'], $nns) == false) {
|
|
|
57 |
$idAAjouter = $this->supprimerCodeReftaxDesNns($nom['nom_retenu.code']);
|
|
|
58 |
if (is_numeric($idAAjouter)) {
|
|
|
59 |
$nns[] = $idAAjouter;
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
}
|
|
|
64 |
return $nns;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
private function supprimerCodeReftaxDesUrls($urls) {
|
|
|
68 |
$codeReftax = $this->parametres->reftaxCourant.'.';
|
|
|
69 |
$urlsNettoyees = array();
|
|
|
70 |
foreach ($urls as $id => $url) {
|
|
|
71 |
$id = str_replace($codeReftax, '', $id);
|
|
|
72 |
$urlsNettoyees[$id] = $url;
|
|
|
73 |
}
|
|
|
74 |
return $urlsNettoyees;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
private function extraireInfosNomsPourTplDetermination() {
|
|
|
79 |
$taxons = array();
|
|
|
80 |
foreach ($this->noms as $idNomCourant => $nom) {
|
|
|
81 |
$nn = $this->supprimerCodeReftaxDesNns($nom['nom_retenu.code']);
|
|
|
82 |
if (array_key_exists($nn, $taxons) == false) {
|
|
|
83 |
$taxon = array();
|
|
|
84 |
$taxon['nomSci'] = $nom['taxon'];
|
|
|
85 |
$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn);
|
|
|
86 |
$taxons[$nn] = $taxon;
|
|
|
87 |
}
|
|
|
88 |
$nom_verna = array();
|
|
|
89 |
$nom_verna['nn'] = $nom['id'];
|
|
|
90 |
$nom_verna['nom_vernaculaire'] = $nom['nom_vernaculaire'];
|
|
|
91 |
$taxons[$nn]['nomVerna'][] = $nom_verna;
|
|
|
92 |
}
|
|
|
93 |
$this->infosPourTpl['noms'] = (count($taxons) > 0) ? $taxons : false;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
private function supprimerCodeReftaxDesNns($nn) {
|
|
|
97 |
$codeReftax = $this->parametres->reftaxCourant.'.nn:';
|
|
|
98 |
return str_replace($codeReftax, '', $nn);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
|
161 |
jpm |
102 |
public function trier() {
|
|
|
103 |
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
public function surligner() {
|
202 |
delphine |
107 |
$this->definirMotsASurligner();
|
|
|
108 |
foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
|
|
|
109 |
foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
|
|
|
110 |
$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
|
|
|
111 |
}
|
|
|
112 |
$this->infosPourTpl['noms'][$idNom] = $nom;
|
|
|
113 |
}
|
161 |
jpm |
114 |
}
|
202 |
delphine |
115 |
|
|
|
116 |
private function definirMotsASurligner() {
|
|
|
117 |
$masqueSansAccent = $this->manipulateurDeChaine->supprimerAccents($this->parametres->masqueRecherche);
|
|
|
118 |
$this->motsASurligner = explode(' ', $masqueSansAccent);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
private function surlignerMotsMasqueRecherche($nom) {
|
|
|
122 |
$this->surligneur->setTexte($nom);
|
|
|
123 |
$nom = $this->surligneur->surlignerMots($this->motsASurligner);
|
|
|
124 |
return $nom;
|
|
|
125 |
}
|
161 |
jpm |
126 |
}
|
|
|
127 |
?>
|