Rev 247 | Blame | Last modification | View Log | RSS feed
<?php
class RetenuFormateur implements Formateur {
const TPL_VUE = 'liste_noms';
private $parametres = null;
private $surligneur = null;
private $trieur = null;
private $urls = null;
private $fusioneur = null;
private $motsASurligner = array();
private $noms = array();
private $infosPourTpl = array();
public function __construct(ParametresResultats $parametres, Array $resultats, Surligneur $surligneur = null,
Trieur $trieur = null, AppUrls $urls = null, TableauManipulateur $tableau = null) {
$this->parametres = $parametres;
$this->noms = $resultats['resultat'];
$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
$this->fusioneur = (is_null($tableau)) ? new TableauManipulateur() : $tableau;
}
public function getTplInfos() {
return $this->infosPourTpl;
}
public function getTplNom() {
return self::TPL_VUE;
}
public function formater() {
foreach ($this->noms as $id => $nom) {
$infosDuNom = array();
$infosDuNom['nomSci'] = $nom['nom_sci'];
$infosDuNom['retenu'] = $nom['retenu'];
$nom_retenu = $nom['retenu'] == 'true' ? $nom['nom_sci'] : '';
$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id, $this->parametres->typeNom, $this->parametres->masqueRecherche);
$this->infosPourTpl['noms'][$id] = $infosDuNom;
}
}
public function trier() {
$nomsRetenus = array();
$nomsSynonymes = array();
foreach ($this->infosPourTpl['noms'] as $id => $nom) {
if ($nom['retenu'] == 'true') {
$nomsRetenus[$id] = $nom;
} else {
$nomsSynonymes[$id] = $nom;
}
}
$this->trieur->setTableau($nomsRetenus);
$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
$nomsRetenus = $this->trieur->trier();
$this->trieur->setTableau($nomsSynonymes);
$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
$nomsSynonymes = $this->trieur->trier();
$this->fusioneur->setTableau($nomsRetenus);
$this->fusioneur->etendreAvec($nomsSynonymes);
$this->infosPourTpl['noms'] = $this->fusioneur->getTableau();
}
public function surligner() {
$this->definirMotsASurligner();
foreach ($this->infosPourTpl['noms'] as $id => $nom) {
$this->infosPourTpl['noms'][$id]['nomSci'] = $this->surlignerMotsMasqueRecherche($nom['nomSci']);
}
}
private function definirMotsASurligner() {
$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
}
private function surlignerMotsMasqueRecherche($nom) {
$this->surligneur->setTexte($nom);
$nom = $this->surligneur->surlignerMots($this->motsASurligner);
return $nom;
}
}
?>