Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev Author Line No. Line
161 jpm 1
<?php
2
class DeterminationVernaFormateur implements Formateur {
3
 
4
	const TPL_VUE = 'determination_verna';
5
 
6
	private $parametres = null;
7
	private $surligneur = null;
8
	private $trieur = null;
9
	private $urls = null;
10
	private $fusioneur = null;
11
	private $manipulateurDeChaine = null;
12
	private $imagesService = null;
13
 
14
	private $motsASurligner = array();
15
	private $noms = array();
16
	private $infosPourTpl = array();
17
 
18
	public function __construct(ParametresResultats $parametres, Array $resultats,
19
		Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
20
		ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
21
 
22
		$this->parametres = $parametres;
23
		$this->noms = $resultats['resultat'];
24
		$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
25
		$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
26
		$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
27
		$this->manipulateurDeChaine = is_null($manipulateurDeChaine) ? new ChaineManipulateur() : $manipulateurDeChaine;
28
		$this->imagesService = is_null($imagesService) ? new Images($this->parametres->projetImg) : $imagesService;
282 gduche 29
		$this->chargerRepartition();
161 jpm 30
	}
282 gduche 31
 
32
	private function chargerRepartition($nn) {
33
		$serviceRepartition = new Cartes('chorodep', $nn, 'nn', "108x101");
34
		$urlPng = $serviceRepartition->getUrlPng();
35
		return $urlPng;
36
	}
161 jpm 37
 
38
	public function getTplInfos() {
39
		return $this->infosPourTpl;
40
	}
41
 
42
	public function getTplNom() {
43
		return self::TPL_VUE;
44
	}
45
 
46
	public function formater() {
199 delphine 47
		$this->obtenirUrlsPhotos();
48
		$this->extraireInfosNomsPourTplDetermination();
161 jpm 49
	}
50
 
199 delphine 51
	private function obtenirUrlsPhotos() {
52
		$nns = $this->extraireNnDesNoms();
53
 
54
		$urls = $this->imagesService->getUrlsImagesParIdsNoms($nns);
55
 
56
		$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReftaxDesUrls($urls);
57
	}
58
 
59
	private function extraireNnDesNoms() {
60
		$nns = array();
61
		foreach ($this->noms as $id => $nom) {
62
			if (array_key_exists('nom_retenu.code', $nom)) {
63
				if (in_array($nom['nom_retenu.code'], $nns) == false) {
64
					$idAAjouter = $this->supprimerCodeReftaxDesNns($nom['nom_retenu.code']);
65
					if (is_numeric($idAAjouter)) {
66
						$nns[] = $idAAjouter;
67
					}
68
				}
69
			}
70
		}
71
		return $nns;
72
	}
73
 
74
	private function supprimerCodeReftaxDesUrls($urls) {
75
		$codeReftax = $this->parametres->reftaxCourant.'.';
76
		$urlsNettoyees = array();
77
		foreach ($urls as $id => $url) {
78
			$id = str_replace($codeReftax, '', $id);
79
			$urlsNettoyees[$id] = $url;
80
		}
81
		return $urlsNettoyees;
82
	}
83
 
84
 
85
	private function extraireInfosNomsPourTplDetermination() {
86
		$taxons = array();
87
		foreach ($this->noms as $idNomCourant => $nom) {
88
			$nn = $this->supprimerCodeReftaxDesNns($nom['nom_retenu.code']);
89
			if (array_key_exists($nn, $taxons) == false) {
90
				$taxon = array();
91
				$taxon['nomSci'] = $nom['taxon'];
248 delphine 92
				$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche, $nom['taxon']);
282 gduche 93
				$taxon['repartition_vignette'] = $this->chargerRepartition($nn);
199 delphine 94
				$taxons[$nn] = $taxon;
95
			}
96
			$nom_verna = array();
97
			$nom_verna['nn'] = $nom['id'];
98
			$nom_verna['nom_vernaculaire'] = $nom['nom_vernaculaire'];
99
			$taxons[$nn]['nomVerna'][] = $nom_verna;
100
		}
101
		$this->infosPourTpl['noms'] = (count($taxons) > 0) ? $taxons : false;
102
	}
103
 
104
	private function supprimerCodeReftaxDesNns($nn) {
105
		$codeReftax = $this->parametres->reftaxCourant.'.nn:';
106
		return str_replace($codeReftax, '', $nn);
107
	}
108
 
109
 
161 jpm 110
	public function trier() {
111
 
112
	}
113
 
114
	public function surligner() {
202 delphine 115
		$this->definirMotsASurligner();
116
		foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
117
			foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
118
				$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
119
			}
120
			$this->infosPourTpl['noms'][$idNom] = $nom;
121
		}
161 jpm 122
	}
202 delphine 123
 
124
	private function definirMotsASurligner() {
207 delphine 125
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
202 delphine 126
	}
127
 
128
	private function surlignerMotsMasqueRecherche($nom) {
129
		$this->surligneur->setTexte($nom);
130
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
131
		return $nom;
132
	}
161 jpm 133
}
134
?>