Rev 872 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
class AlphabFormateur implements Formateur {
const TPL_VUE = 'liste_noms';
private $parametres = null;
private $surligneur = null;
private $trieur = null;
private $urls = 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) {
$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;
}
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_complet'];
$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() {
$this->trieur->setTableau($this->infosPourTpl['noms']);
$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
$this->infosPourTpl['noms'] = $this->trieur->trier();
}
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;
}
}
?>