Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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