Subversion Repositories eFlore/Applications.eflore-consultation

Rev

Rev 282 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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