Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 163 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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'];
216 delphine 39
			$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id, $this->parametres->typeNom, $this->parametres->masqueRecherche);
146 jpm 40
 
41
			$this->infosPourTpl['noms'][$id] = $infosDuNom;
42
		}
43
	}
44
 
45
	public function trier() {
46
		$nomsRetenus = array();
47
		$nomsSynonymes = array();
48
 
49
		foreach ($this->infosPourTpl['noms'] as $id => $nom) {
50
			if ($nom['retenu'] == 'true') {
51
				$nomsRetenus[$id] = $nom;
52
			} else {
53
				$nomsSynonymes[$id] = $nom;
54
			}
55
		}
56
 
57
		$this->trieur->setTableau($nomsRetenus);
58
		$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
59
		$nomsRetenus = $this->trieur->trier();
60
 
61
		$this->trieur->setTableau($nomsSynonymes);
62
		$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
63
		$nomsSynonymes = $this->trieur->trier();
64
 
65
		$this->fusioneur->setTableau($nomsRetenus);
66
		$this->fusioneur->etendreAvec($nomsSynonymes);
67
		$this->infosPourTpl['noms'] = $this->fusioneur->getTableau();
68
	}
69
 
70
	public function surligner() {
71
		$this->definirMotsASurligner();
72
		foreach ($this->infosPourTpl['noms'] as $id => $nom) {
73
			$this->infosPourTpl['noms'][$id]['nomSci'] = $this->surlignerMotsMasqueRecherche($nom['nomSci']);
74
		}
75
	}
76
 
77
	private function definirMotsASurligner() {
78
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
79
	}
80
 
81
	private function surlignerMotsMasqueRecherche($nom) {
82
		$this->surligneur->setTexte($nom);
83
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
84
		return $nom;
85
	}
86
}
87
?>