Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
146 jpm 1
<?php
2
class DecompoFormateur implements Formateur {
3
 
149 jpm 4
	const TPL_VUE = 'decomposition';
146 jpm 5
 
149 jpm 6
	private $parametres = null;
7
	private $surligneur = null;
8
	private $trieur = null;
9
	private $urls = null;
10
	private $motsASurligner = array();
11
	private $noms = array();
12
	private $infosPourTpl = array();
13
 
14
	public function __construct(ParametresResultats $parametres, Array $resultats, Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null) {
15
		$this->parametres = $parametres;
16
		$this->noms = $resultats['resultat'];
17
		$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
18
		$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
19
		$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
146 jpm 20
	}
21
 
149 jpm 22
	public function getTplInfos() {
23
		return $this->infosPourTpl;
24
	}
25
 
26
	public function getTplNom() {
27
		return self::TPL_VUE;
28
	}
29
 
146 jpm 30
	public function formater() {
188 jpm 31
		$this->infosPourTpl['masqueRecherche'] = rawurlencode($this->parametres->masqueRecherche);
32
		$this->infosPourTpl['baseUrlIco'] = $this->urls->obtenirUrlBaseDossier();
149 jpm 33
		foreach ($this->noms as $id => $nom) {
34
			$infosDuNom = array();
35
			$infosDuNom['nomSci'] = $nom['nom_sci'];
718 delphine 36
			$infosDuNom['retenu'] = $nom['retenu'];
149 jpm 37
			$infosDuNom['auteur'] = is_null($nom['auteur']) ? '' : $nom['auteur'];
38
			$infosDuNom['annee'] = is_null($nom['annee']) ? '' : $nom['annee'];
39
			$infosDuNom['biblio'] = is_null($nom['biblio_origine']) ? '' : $nom['biblio_origine'];
40
			$infosDuNom['addendum'] = is_null($nom['nom_addendum']) ? '' : $nom['nom_addendum'];
41
			$infosDuNom['nn'] = $id;
247 delphine 42
			$nom_retenu = $nom['retenu'] == 'true' ? $nom['nom_sci'] : '';
369 delphine 43
			$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id, $this->parametres->typeNom, $this->parametres->masqueRecherche);
149 jpm 44
 
45
			$this->infosPourTpl['noms'][$id] = $infosDuNom;
46
		}
146 jpm 47
	}
149 jpm 48
 
49
	public function trier() {
50
		$this->trieur->setTableau($this->infosPourTpl['noms']);
51
		$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
52
		$this->infosPourTpl['noms'] = $this->trieur->trier();
53
	}
54
 
55
	public function surligner() {
56
		$this->definirMotsASurligner();
57
		foreach ($this->infosPourTpl['noms'] as $id => $nom) {
58
			$this->infosPourTpl['noms'][$id]['nomSci'] = $this->surlignerMotsMasqueRecherche($nom['nomSci']);
59
		}
60
	}
61
 
62
	private function definirMotsASurligner() {
63
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
64
	}
65
 
66
	private function surlignerMotsMasqueRecherche($nom) {
67
		$this->surligneur->setTexte($nom);
68
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
69
		return $nom;
70
	}
146 jpm 71
}
72
?>