Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 312 | 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
	}
312 jpm 31
 
282 gduche 32
	private function chargerRepartition($nn) {
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();
161 jpm 62
	}
63
 
199 delphine 64
	private function obtenirUrlsPhotos() {
65
		$nns = $this->extraireNnDesNoms();
66
 
67
		$urls = $this->imagesService->getUrlsImagesParIdsNoms($nns);
68
 
69
		$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReftaxDesUrls($urls);
70
	}
71
 
72
	private function extraireNnDesNoms() {
73
		$nns = array();
74
		foreach ($this->noms as $id => $nom) {
75
			if (array_key_exists('nom_retenu.code', $nom)) {
76
				if (in_array($nom['nom_retenu.code'], $nns) == false) {
313 jpm 77
					$idAAjouter = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
199 delphine 78
					if (is_numeric($idAAjouter)) {
79
						$nns[] = $idAAjouter;
80
					}
81
				}
82
			}
83
		}
84
		return $nns;
85
	}
86
 
87
	private function supprimerCodeReftaxDesUrls($urls) {
313 jpm 88
		$urlsNettoyees = array();
199 delphine 89
		foreach ($urls as $id => $url) {
312 jpm 90
			$id = $this->supprimerCodeReftax($id);
199 delphine 91
			$urlsNettoyees[$id] = $url;
92
		}
93
		return $urlsNettoyees;
94
	}
95
 
312 jpm 96
	private function supprimerCodeReftax($chaine) {
97
		$codeReftax = $this->parametres->reftaxCourant.'.';
98
		$chaine = str_replace($codeReftax, '', $chaine);
99
		return $chaine;
100
	}
101
 
102
 
199 delphine 103
	private function extraireInfosNomsPourTplDetermination() {
104
		$taxons = array();
105
		foreach ($this->noms as $idNomCourant => $nom) {
313 jpm 106
			$nn = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
199 delphine 107
			if (array_key_exists($nn, $taxons) == false) {
108
				$taxon = array();
109
				$taxon['nomSci'] = $nom['taxon'];
248 delphine 110
				$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche, $nom['taxon']);
282 gduche 111
				$taxon['repartition_vignette'] = $this->chargerRepartition($nn);
199 delphine 112
				$taxons[$nn] = $taxon;
113
			}
114
			$nom_verna = array();
115
			$nom_verna['nn'] = $nom['id'];
116
			$nom_verna['nom_vernaculaire'] = $nom['nom_vernaculaire'];
117
			$taxons[$nn]['nomVerna'][] = $nom_verna;
118
		}
119
		$this->infosPourTpl['noms'] = (count($taxons) > 0) ? $taxons : false;
120
	}
312 jpm 121
 
313 jpm 122
	private function supprimerCodeReftaxAvecNn($nn) {
199 delphine 123
		$codeReftax = $this->parametres->reftaxCourant.'.nn:';
124
		return str_replace($codeReftax, '', $nn);
125
	}
126
 
312 jpm 127
 
161 jpm 128
	public function trier() {
129
 
130
	}
131
 
132
	public function surligner() {
202 delphine 133
		$this->definirMotsASurligner();
134
		foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
135
			foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
136
				$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
137
			}
138
			$this->infosPourTpl['noms'][$idNom] = $nom;
139
		}
161 jpm 140
	}
312 jpm 141
 
202 delphine 142
	private function definirMotsASurligner() {
207 delphine 143
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
202 delphine 144
	}
312 jpm 145
 
202 delphine 146
	private function surlignerMotsMasqueRecherche($nom) {
147
		$this->surligneur->setTexte($nom);
148
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
149
		return $nom;
150
	}
161 jpm 151
}
152
?>