146 |
jpm |
1 |
<?php
|
|
|
2 |
class RetenuFormateur implements Formateur {
|
|
|
3 |
|
159 |
jpm |
4 |
const TPL_VUE = 'liste_noms';
|
146 |
jpm |
5 |
|
|
|
6 |
private $parametres = null;
|
|
|
7 |
private $surligneur = null;
|
|
|
8 |
private $trieur = null;
|
|
|
9 |
private $urls = null;
|
|
|
10 |
private $fusioneur = null;
|
|
|
11 |
|
|
|
12 |
private $motsASurligner = array();
|
|
|
13 |
private $noms = array();
|
|
|
14 |
private $infosPourTpl = array();
|
|
|
15 |
|
|
|
16 |
public function __construct(ParametresResultats $parametres, Array $resultats, Surligneur $surligneur = null,
|
|
|
17 |
Trieur $trieur = null, AppUrls $urls = null, TableauManipulateur $tableau = null) {
|
|
|
18 |
$this->parametres = $parametres;
|
|
|
19 |
$this->noms = $resultats['resultat'];
|
|
|
20 |
$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
|
|
|
21 |
$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
|
|
|
22 |
$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
|
|
|
23 |
$this->fusioneur = (is_null($tableau)) ? new TableauManipulateur() : $tableau;
|
|
|
24 |
}
|
|
|
25 |
|
|
|
26 |
public function getTplInfos() {
|
|
|
27 |
return $this->infosPourTpl;
|
|
|
28 |
}
|
|
|
29 |
|
|
|
30 |
public function getTplNom() {
|
|
|
31 |
return self::TPL_VUE;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public function formater() {
|
|
|
35 |
foreach ($this->noms as $id => $nom) {
|
|
|
36 |
$infosDuNom = array();
|
|
|
37 |
$infosDuNom['nomSci'] = $nom['nom_sci'];
|
|
|
38 |
$infosDuNom['retenu'] = $nom['retenu'];
|
247 |
delphine |
39 |
$nom_retenu = $nom['retenu'] == 'true' ? $nom['nom_sci'] : '';
|
|
|
40 |
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id, $this->parametres->typeNom, $this->parametres->masqueRecherche, $nom_retenu);
|
146 |
jpm |
41 |
|
|
|
42 |
$this->infosPourTpl['noms'][$id] = $infosDuNom;
|
|
|
43 |
}
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public function trier() {
|
|
|
47 |
$nomsRetenus = array();
|
|
|
48 |
$nomsSynonymes = array();
|
|
|
49 |
|
|
|
50 |
foreach ($this->infosPourTpl['noms'] as $id => $nom) {
|
|
|
51 |
if ($nom['retenu'] == 'true') {
|
|
|
52 |
$nomsRetenus[$id] = $nom;
|
|
|
53 |
} else {
|
|
|
54 |
$nomsSynonymes[$id] = $nom;
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
$this->trieur->setTableau($nomsRetenus);
|
|
|
59 |
$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
|
|
|
60 |
$nomsRetenus = $this->trieur->trier();
|
|
|
61 |
|
|
|
62 |
$this->trieur->setTableau($nomsSynonymes);
|
|
|
63 |
$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
|
|
|
64 |
$nomsSynonymes = $this->trieur->trier();
|
|
|
65 |
|
|
|
66 |
$this->fusioneur->setTableau($nomsRetenus);
|
|
|
67 |
$this->fusioneur->etendreAvec($nomsSynonymes);
|
|
|
68 |
$this->infosPourTpl['noms'] = $this->fusioneur->getTableau();
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
public function surligner() {
|
|
|
72 |
$this->definirMotsASurligner();
|
|
|
73 |
foreach ($this->infosPourTpl['noms'] as $id => $nom) {
|
|
|
74 |
$this->infosPourTpl['noms'][$id]['nomSci'] = $this->surlignerMotsMasqueRecherche($nom['nomSci']);
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
private function definirMotsASurligner() {
|
|
|
79 |
$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
private function surlignerMotsMasqueRecherche($nom) {
|
|
|
83 |
$this->surligneur->setTexte($nom);
|
|
|
84 |
$nom = $this->surligneur->surlignerMots($this->motsASurligner);
|
|
|
85 |
return $nom;
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
?>
|