161 |
jpm |
1 |
<?php
|
|
|
2 |
class AlphabVernaFormateur implements Formateur {
|
|
|
3 |
|
|
|
4 |
const TPL_VUE = 'liste_noms_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 |
}
|
791 |
mathilde |
38 |
|
|
|
39 |
private function supprimerCodeReftaxAvecNn($nn) {
|
|
|
40 |
$codeReftax = $this->parametres->reftaxCourant.'.nn:';
|
|
|
41 |
return str_replace($codeReftax, '', $nn);
|
|
|
42 |
}
|
798 |
mathilde |
43 |
|
|
|
44 |
|
|
|
45 |
private function renvoyerInfoVerna($nn, $valeurs) {
|
|
|
46 |
$infosDuNom = array();
|
|
|
47 |
$infosDuNom['nomSci'] = $valeurs['taxon'];
|
|
|
48 |
$infosDuNom['nomVerna'] = $valeurs['nom_vernaculaire'];
|
|
|
49 |
$infosDuNom['langue'] = $valeurs['code_langue'];
|
|
|
50 |
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
|
|
|
51 |
return $infosDuNom ;
|
|
|
52 |
}
|
161 |
jpm |
53 |
|
798 |
mathilde |
54 |
function supprimerAccents($chaine){
|
|
|
55 |
return strtr($chaine,array('à' => 'a','á' => 'a','â' => 'a','ã' => 'a','ä' => 'a',
|
|
|
56 |
'ç' => 'c',
|
|
|
57 |
'è' => 'e','é' => 'e','ê' => 'e','ë' => 'e',
|
|
|
58 |
'ì' => 'i','í' => 'i','î' => 'i','ï' => 'i',
|
|
|
59 |
'ñ' => 'n',
|
|
|
60 |
'ò' => 'o', 'ó' => 'o' , 'ô' => 'o', 'õ' => 'o', 'ö' => 'o',
|
|
|
61 |
'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u',
|
|
|
62 |
'ý' => 'y', 'ÿ' => 'y'));
|
|
|
63 |
}
|
|
|
64 |
|
161 |
jpm |
65 |
public function formater() {
|
798 |
mathilde |
66 |
$nomVerna = array();
|
791 |
mathilde |
67 |
foreach ($this->noms as $id => $nom) {
|
|
|
68 |
$nn = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
|
798 |
mathilde |
69 |
$nom_min = strtolower($nom['nom_vernaculaire']);
|
|
|
70 |
$nom_ss_accent = $this->supprimerAccents($nom_min);
|
|
|
71 |
if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/', $nom_ss_accent)) {
|
|
|
72 |
$nomVerna[0][$id] = $this->renvoyerInfoVerna($nn, $nom);
|
|
|
73 |
} else {
|
|
|
74 |
$nomVerna[1][$id] = $this->renvoyerInfoVerna($nn, $nom);
|
|
|
75 |
}
|
791 |
mathilde |
76 |
}
|
798 |
mathilde |
77 |
ksort($nomVerna);
|
|
|
78 |
$this->infosPourTpl['noms'] = isset($nomVerna) ? $nomVerna : false;
|
161 |
jpm |
79 |
}
|
|
|
80 |
|
798 |
mathilde |
81 |
public function trier() {
|
|
|
82 |
$verna = array();
|
|
|
83 |
foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
|
|
|
84 |
$verna += $this->classerAlphabetiquement('nomVerna', $valeurs);
|
|
|
85 |
}
|
|
|
86 |
$this->infosPourTpl['noms'] = $verna;
|
161 |
jpm |
87 |
}
|
798 |
mathilde |
88 |
|
|
|
89 |
private function classerAlphabetiquement($champs, $valeurs) {
|
|
|
90 |
$this->trieur->setTableau($valeurs);
|
931 |
delphine |
91 |
$this->trieur->setChampsEtOrdres(array($champs => 'nat'));
|
798 |
mathilde |
92 |
return $this->trieur->trier();
|
|
|
93 |
}
|
161 |
jpm |
94 |
|
|
|
95 |
public function surligner() {
|
798 |
mathilde |
96 |
$this->definirMotsASurligner();
|
|
|
97 |
foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
|
|
|
98 |
$this->infosPourTpl['noms'][$idNom]['nomVerna'] = $this->surlignerMotsMasqueRecherche($nom['nomVerna']);
|
|
|
99 |
}
|
|
|
100 |
}
|
161 |
jpm |
101 |
|
798 |
mathilde |
102 |
private function definirMotsASurligner() {
|
|
|
103 |
$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
|
|
|
104 |
|
161 |
jpm |
105 |
}
|
798 |
mathilde |
106 |
|
|
|
107 |
private function surlignerMotsMasqueRecherche($nom) {
|
|
|
108 |
$this->surligneur->setTexte($nom);
|
|
|
109 |
$nom = $this->surligneur->surlignerMots($this->motsASurligner);
|
|
|
110 |
return $nom;
|
|
|
111 |
}
|
161 |
jpm |
112 |
}
|
|
|
113 |
?>
|