Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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