Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 216 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 216 Rev 247
1
<?php
1
<?php
2
class RetenuFormateur implements Formateur {
2
class RetenuFormateur implements Formateur {
3
 
3
 
4
	const TPL_VUE = 'liste_noms';
4
	const TPL_VUE = 'liste_noms';
5
 
5
 
6
	private $parametres = null;
6
	private $parametres = null;
7
	private $surligneur = null;
7
	private $surligneur = null;
8
	private $trieur = null;
8
	private $trieur = null;
9
	private $urls = null;
9
	private $urls = null;
10
	private $fusioneur = null;
10
	private $fusioneur = null;
11
 
11
 
12
	private $motsASurligner = array();
12
	private $motsASurligner = array();
13
	private $noms = array();
13
	private $noms = array();
14
	private $infosPourTpl = array();
14
	private $infosPourTpl = array();
15
 
15
 
16
	public function __construct(ParametresResultats $parametres, Array $resultats, Surligneur $surligneur = null,
16
	public function __construct(ParametresResultats $parametres, Array $resultats, Surligneur $surligneur = null,
17
		Trieur $trieur = null, AppUrls $urls = null, TableauManipulateur $tableau = null) {
17
		Trieur $trieur = null, AppUrls $urls = null, TableauManipulateur $tableau = null) {
18
		$this->parametres = $parametres;
18
		$this->parametres = $parametres;
19
		$this->noms = $resultats['resultat'];
19
		$this->noms = $resultats['resultat'];
20
		$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
20
		$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
21
		$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
21
		$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
22
		$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
22
		$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
23
		$this->fusioneur = (is_null($tableau)) ? new TableauManipulateur() : $tableau;
23
		$this->fusioneur = (is_null($tableau)) ? new TableauManipulateur() : $tableau;
24
	}
24
	}
25
 
25
 
26
	public function getTplInfos() {
26
	public function getTplInfos() {
27
		return $this->infosPourTpl;
27
		return $this->infosPourTpl;
28
	}
28
	}
29
 
29
 
30
	public function getTplNom() {
30
	public function getTplNom() {
31
		return self::TPL_VUE;
31
		return self::TPL_VUE;
32
	}
32
	}
33
 
33
 
34
	public function formater() {
34
	public function formater() {
35
		foreach ($this->noms as $id => $nom) {
35
		foreach ($this->noms as $id => $nom) {
36
			$infosDuNom = array();
36
			$infosDuNom = array();
37
			$infosDuNom['nomSci'] = $nom['nom_sci'];
37
			$infosDuNom['nomSci'] = $nom['nom_sci'];
38
			$infosDuNom['retenu'] = $nom['retenu'];
38
			$infosDuNom['retenu'] = $nom['retenu'];
-
 
39
			$nom_retenu = $nom['retenu'] == 'true' ? $nom['nom_sci'] : '';
39
			$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id, $this->parametres->typeNom, $this->parametres->masqueRecherche);
40
			$infosDuNom['urlFiche'] = $this->urls->obtenirUrlFiche($id, $this->parametres->typeNom, $this->parametres->masqueRecherche, $nom_retenu);
40
 
41
 
41
			$this->infosPourTpl['noms'][$id] = $infosDuNom;
42
			$this->infosPourTpl['noms'][$id] = $infosDuNom;
42
		}
43
		}
43
	}
44
	}
44
 
45
 
45
	public function trier() {
46
	public function trier() {
46
		$nomsRetenus = array();
47
		$nomsRetenus = array();
47
		$nomsSynonymes = array();
48
		$nomsSynonymes = array();
48
 
49
 
49
		foreach ($this->infosPourTpl['noms'] as $id => $nom) {
50
		foreach ($this->infosPourTpl['noms'] as $id => $nom) {
50
			if ($nom['retenu'] == 'true') {
51
			if ($nom['retenu'] == 'true') {
51
				$nomsRetenus[$id] = $nom;
52
				$nomsRetenus[$id] = $nom;
52
			} else {
53
			} else {
53
				$nomsSynonymes[$id] = $nom;
54
				$nomsSynonymes[$id] = $nom;
54
			}
55
			}
55
		}
56
		}
56
 
57
 
57
		$this->trieur->setTableau($nomsRetenus);
58
		$this->trieur->setTableau($nomsRetenus);
58
		$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
59
		$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
59
		$nomsRetenus = $this->trieur->trier();
60
		$nomsRetenus = $this->trieur->trier();
60
 
61
 
61
		$this->trieur->setTableau($nomsSynonymes);
62
		$this->trieur->setTableau($nomsSynonymes);
62
		$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
63
		$this->trieur->setChampsEtOrdres(array('nomSci' => SORT_ASC));
63
		$nomsSynonymes = $this->trieur->trier();
64
		$nomsSynonymes = $this->trieur->trier();
64
 
65
 
65
		$this->fusioneur->setTableau($nomsRetenus);
66
		$this->fusioneur->setTableau($nomsRetenus);
66
		$this->fusioneur->etendreAvec($nomsSynonymes);
67
		$this->fusioneur->etendreAvec($nomsSynonymes);
67
		$this->infosPourTpl['noms'] = $this->fusioneur->getTableau();
68
		$this->infosPourTpl['noms'] = $this->fusioneur->getTableau();
68
	}
69
	}
69
 
70
 
70
	public function surligner() {
71
	public function surligner() {
71
		$this->definirMotsASurligner();
72
		$this->definirMotsASurligner();
72
		foreach ($this->infosPourTpl['noms'] as $id => $nom) {
73
		foreach ($this->infosPourTpl['noms'] as $id => $nom) {
73
			$this->infosPourTpl['noms'][$id]['nomSci'] = $this->surlignerMotsMasqueRecherche($nom['nomSci']);
74
			$this->infosPourTpl['noms'][$id]['nomSci'] = $this->surlignerMotsMasqueRecherche($nom['nomSci']);
74
		}
75
		}
75
	}
76
	}
76
 
77
 
77
	private function definirMotsASurligner() {
78
	private function definirMotsASurligner() {
78
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
79
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
79
	}
80
	}
80
 
81
 
81
	private function surlignerMotsMasqueRecherche($nom) {
82
	private function surlignerMotsMasqueRecherche($nom) {
82
		$this->surligneur->setTexte($nom);
83
		$this->surligneur->setTexte($nom);
83
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
84
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
84
		return $nom;
85
		return $nom;
85
	}
86
	}
86
}
87
}
87
?>
88
?>