Rev 369 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?php
class DecompoFormateur implements Formateur {
const TPL_VUE = 'decomposition';
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() {
$this->infosPourTpl['masqueRecherche'] = rawurlencode($this->parametres->masqueRecherche);
$this->infosPourTpl['baseUrlIco'] = $this->urls->obtenirUrlBaseDossier();
foreach ($this->noms as $id => $nom) {
$infosDuNom = array();
$infosDuNom['nomSci'] = $nom['nom_sci'];
$infosDuNom['retenu'] = $nom['retenu'];
$infosDuNom['auteur'] = is_null($nom['auteur']) ? '' : $nom['auteur'];
$infosDuNom['annee'] = is_null($nom['annee']) ? '' : $nom['annee'];
$infosDuNom['biblio'] = is_null($nom['biblio_origine']) ? '' : $nom['biblio_origine'];
$infosDuNom['addendum'] = is_null($nom['nom_addendum']) ? '' : $nom['nom_addendum'];
$infosDuNom['nn'] = $id;
$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;
}
}
?>