Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 369 | 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;
618 mathilde 29
 
161 jpm 30
	}
312 jpm 31
 
618 mathilde 32
	private function chargerRepartition() {
312 jpm 33
		$conteneur = new Conteneur();
34
		$cartesWs = $conteneur->getApiCartes();
35
		$cartesWs->setProjet('chorodep');
36
		$cartesWs->setLargeur('108x101');
37
		$urls = array();
38
		foreach ($this->noms as $nom) {
39
			if (array_key_exists('nom_retenu.code', $nom)) {
40
				$id = $nom['nom_retenu.code'];
313 jpm 41
				$id = $this->supprimerCodeReftaxAvecNn($id);
312 jpm 42
				$cartesWs->setId("nn:$id");
43
				if (array_key_exists($id, $urls) == false) {
44
					$urls[$id] = $cartesWs->getUrlPng();
45
				}
46
			}
47
		}
48
		$this->infosPourTpl['repartition']['urls'] = $urls;
282 gduche 49
	}
161 jpm 50
 
51
	public function getTplInfos() {
52
		return $this->infosPourTpl;
53
	}
54
 
55
	public function getTplNom() {
56
		return self::TPL_VUE;
57
	}
58
 
59
	public function formater() {
199 delphine 60
		$this->obtenirUrlsPhotos();
61
		$this->extraireInfosNomsPourTplDetermination();
618 mathilde 62
		$this->obtenirUrlsImagesCoste();
63
		$this->chargerRepartition();
161 jpm 64
	}
618 mathilde 65
 
66
	private function obtenirUrlsImagesCoste() {
67
		$this->extraireInfosTaxons();
68
		$this->imagesService->setProjet('coste');
69
		foreach ($this->infosPourTpl['taxons'] as $nn => $tax) {
70
			$this->imagesService->setNnTaxon($tax);
71
			$costeImg = $this->imagesService->getInfosImagesTaxons();
72
			if (!empty($costeImg)) {
73
				foreach ($costeImg as  $infos) {
74
					$num_taxon = $infos['num_taxonomique'];
75
					$images[$num_taxon][] = $infos['binaire.href'];
76
					$this->infosPourTpl['imagesCoste'] = $images;
77
				}
78
			}
79
		}
80
 
81
	}
82
 
83
	private function extraireInfosTaxons() {
84
		foreach ($this->noms as $id => $nom ) {
85
			if (array_key_exists('num_taxon', $nom)
86
				&& array_key_exists('taxon', $nom)) {
87
				$this->infosPourTpl['taxons'][$nom['taxon']] = $nom['num_taxon'];
88
			}
89
		}
90
	}
161 jpm 91
 
199 delphine 92
	private function obtenirUrlsPhotos() {
93
		$nns = $this->extraireNnDesNoms();
94
 
95
		$urls = $this->imagesService->getUrlsImagesParIdsNoms($nns);
96
 
97
		$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReftaxDesUrls($urls);
98
	}
99
 
100
	private function extraireNnDesNoms() {
101
		$nns = array();
102
		foreach ($this->noms as $id => $nom) {
103
			if (array_key_exists('nom_retenu.code', $nom)) {
104
				if (in_array($nom['nom_retenu.code'], $nns) == false) {
313 jpm 105
					$idAAjouter = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
199 delphine 106
					if (is_numeric($idAAjouter)) {
107
						$nns[] = $idAAjouter;
108
					}
109
				}
110
			}
111
		}
112
		return $nns;
113
	}
114
 
115
	private function supprimerCodeReftaxDesUrls($urls) {
313 jpm 116
		$urlsNettoyees = array();
199 delphine 117
		foreach ($urls as $id => $url) {
312 jpm 118
			$id = $this->supprimerCodeReftax($id);
199 delphine 119
			$urlsNettoyees[$id] = $url;
120
		}
121
		return $urlsNettoyees;
122
	}
123
 
312 jpm 124
	private function supprimerCodeReftax($chaine) {
125
		$codeReftax = $this->parametres->reftaxCourant.'.';
126
		$chaine = str_replace($codeReftax, '', $chaine);
127
		return $chaine;
128
	}
129
 
130
 
199 delphine 131
	private function extraireInfosNomsPourTplDetermination() {
132
		$taxons = array();
133
		foreach ($this->noms as $idNomCourant => $nom) {
313 jpm 134
			$nn = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
199 delphine 135
			if (array_key_exists($nn, $taxons) == false) {
136
				$taxon = array();
137
				$taxon['nomSci'] = $nom['taxon'];
369 delphine 138
				$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
282 gduche 139
				$taxon['repartition_vignette'] = $this->chargerRepartition($nn);
199 delphine 140
				$taxons[$nn] = $taxon;
141
			}
142
			$nom_verna = array();
143
			$nom_verna['nn'] = $nom['id'];
144
			$nom_verna['nom_vernaculaire'] = $nom['nom_vernaculaire'];
145
			$taxons[$nn]['nomVerna'][] = $nom_verna;
146
		}
147
		$this->infosPourTpl['noms'] = (count($taxons) > 0) ? $taxons : false;
148
	}
312 jpm 149
 
313 jpm 150
	private function supprimerCodeReftaxAvecNn($nn) {
199 delphine 151
		$codeReftax = $this->parametres->reftaxCourant.'.nn:';
152
		return str_replace($codeReftax, '', $nn);
153
	}
154
 
312 jpm 155
 
161 jpm 156
	public function trier() {
157
 
158
	}
159
 
160
	public function surligner() {
202 delphine 161
		$this->definirMotsASurligner();
162
		foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
163
			foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
164
				$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
165
			}
166
			$this->infosPourTpl['noms'][$idNom] = $nom;
167
		}
161 jpm 168
	}
312 jpm 169
 
202 delphine 170
	private function definirMotsASurligner() {
207 delphine 171
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
202 delphine 172
	}
312 jpm 173
 
202 delphine 174
	private function surlignerMotsMasqueRecherche($nom) {
175
		$this->surligneur->setTexte($nom);
176
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
177
		return $nom;
178
	}
161 jpm 179
}
180
?>