Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 880 Rev 931
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
	private $conteneur = null;
18
	private $conteneur = null;
19
	private $apiCartes = null;
19
	private $apiCartes = null;
20
 
20
 
21
	public function __construct(ParametresResultats $parametres, Array $resultats,
21
	public function __construct(ParametresResultats $parametres, Array $resultats,
22
		Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
22
		Surligneur $surligneur = null, Trieur $trieur = null, AppUrls $urls = null,
23
		ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
23
		ChaineManipulateur $manipulateurDeChaine = null, Images $imagesService = null) {
24
 
24
 
25
		$this->parametres = $parametres;
25
		$this->parametres = $parametres;
26
		$this->noms = $resultats['resultat'];
26
		$this->noms = $resultats['resultat'];
27
		$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
27
		$this->surligneur = (is_null($surligneur)) ? new Surligneur() : $surligneur;
28
		$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
28
		$this->trieur = (is_null($trieur)) ? new Trieur() : $trieur;
29
		$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
29
		$this->urls = (is_null($urls)) ? new AppUrls() : $urls;
30
		$this->manipulateurDeChaine = is_null($manipulateurDeChaine) ? new ChaineManipulateur() : $manipulateurDeChaine;
30
		$this->manipulateurDeChaine = is_null($manipulateurDeChaine) ? new ChaineManipulateur() : $manipulateurDeChaine;
31
		$this->imagesService = is_null($imagesService) ? new Images($this->parametres->projetImg) : $imagesService;
31
		$this->imagesService = is_null($imagesService) ? new Images($this->parametres->projetImg) : $imagesService;
32
		
32
		
33
		$this->conteneur = new Conteneur();
33
		$this->conteneur = new Conteneur();
34
		$this->apiCartes = $this->conteneur->getApiCartes();
34
		$this->apiCartes = $this->conteneur->getApiCartes();
35
	}
35
	}
36
 
-
 
37
	private function chargerRepartition() {
-
 
38
		$this->apiCartes->setProjet('chorodep');
-
 
39
		$this->apiCartes->setLargeur('108x101');
-
 
40
		$urls = array();
-
 
41
		foreach ($this->noms as $nom) {
-
 
42
			if (array_key_exists('nom_retenu.code', $nom)) {
-
 
43
				$id = $nom['nom_retenu.code'];
-
 
44
				$id = $this->supprimerCodeReftaxAvecNn($id);
-
 
45
				$this->apiCartes->setId("nn:$id");
-
 
46
				if (array_key_exists($id, $urls) == false) {
-
 
47
					$urls[$id] = $this->apiCartes->getUrlPng();
-
 
48
				}
-
 
49
			}
-
 
50
		}
-
 
51
		$this->infosPourTpl['repartition']['urls'] = $urls;
-
 
52
	}
-
 
53
 
36
 
54
	public function getTplInfos() {
37
	public function getTplInfos() {
55
		return $this->infosPourTpl;
38
		return $this->infosPourTpl;
56
	}
39
	}
57
 
40
 
58
	public function getTplNom() {
41
	public function getTplNom() {
59
		return self::TPL_VUE;
42
		return self::TPL_VUE;
60
	}
43
	}
61
 
44
 
62
	public function formater() {
45
	public function formater() {
-
 
46
		$this->obtenirUrlsDessins();
63
		$this->obtenirUrlsPhotos();
47
		$this->obtenirUrlsPhotos();
64
		$this->extraireInfosNomsPourTplDetermination();
-
 
65
		$this->obtenirUrlsImagesCoste();
-
 
66
		$this->chargerRepartition();
48
		$this->chargerRepartition();
-
 
49
		$this->extraireInfosNomsPourTplDetermination();
67
	}
50
	}
68
	
51
	
-
 
52
	private function obtenirUrlsDessins() {
69
	private function obtenirUrlsImagesCoste() {
53
		if (Config::get(Registre::get('parametres.referentiel').'.baseDessins') != "") {
70
		$this->extraireInfosTaxons();
54
			$this->extraireInfosTaxons();
71
		$this->imagesService->setProjet('coste');
55
			$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseDessins'));
72
		$tax = implode(',', $this->infosPourTpl['taxons']);
56
			$tax = implode(',', $this->infosPourTpl['taxons']);
73
		$this->imagesService->setNnTaxon($tax);
57
			$this->imagesService->setNnTaxon($tax);
74
		$costeImg = $this->imagesService->getInfosImagesTaxons();
58
			$costeImg = $this->imagesService->getInfosImagesTaxons();
75
		if (!empty($costeImg)) {
59
			if (!empty($costeImg)) {
76
			foreach ($costeImg as  $infos) {
60
				foreach ($costeImg as  $infos) {
77
				$num_taxon = $infos['num_taxonomique'];
61
					$num_taxon = $infos['num_taxonomique'];
78
				$images[$num_taxon][] = $infos['binaire.href'];
62
					$images[$num_taxon][] = $infos['binaire.href'];
-
 
63
					$this->infosPourTpl['imagesCoste'] = $images;
79
				$this->infosPourTpl['imagesCoste'] = $images;
64
				}
80
			}
65
			}
81
		}
66
		}
82
	}
67
	}
83
	
68
	
84
	private function extraireInfosTaxons() {
69
	private function extraireInfosTaxons() {
85
		foreach ($this->noms as $id => $nom ) {
70
		foreach ($this->noms as $id => $nom ) {
86
			if (array_key_exists('num_taxon', $nom) 
71
			if (array_key_exists('num_taxon', $nom) 
87
				&& array_key_exists('taxon', $nom)) {
72
				&& array_key_exists('taxon', $nom)) {
88
				$this->infosPourTpl['taxons'][$nom['taxon']] = $nom['num_taxon'];
73
				$this->infosPourTpl['taxons'][$nom['taxon']] = $nom['num_taxon'];
89
			}
74
			}
90
		}
75
		}
91
	}
76
	}
92
 
77
 
93
	private function obtenirUrlsPhotos() {
78
	private function obtenirUrlsPhotos() {
94
		$nns = $this->extraireNnDesNoms();
79
		$nns = $this->extraireNnDesNoms();
95
		$urls = $this->imagesService->getUrlsImagesParIdsNoms($nns);
80
		$urls = $this->imagesService->getUrlsImagesParIdsNoms($nns);
96
		$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReftaxDesUrls($urls);
81
		$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReferentielDesUrls($urls);
97
	}
82
	}
98
 
83
 
99
	private function extraireNnDesNoms() {
84
	private function extraireNnDesNoms() {
100
		$nns = array();
85
		$nns = array();
101
		foreach ($this->noms as $id => $nom) {
86
		foreach ($this->noms as $id => $nom) {
102
			if (array_key_exists('nom_retenu.code', $nom)) {
87
			if (array_key_exists('nom_retenu.code', $nom)) {
103
				if (in_array($nom['nom_retenu.code'], $nns) == false) {
88
				if (in_array($nom['nom_retenu.code'], $nns) == false) {
104
					$idAAjouter = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
89
					$idAAjouter = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
105
					if (is_numeric($idAAjouter)) {
90
					if (is_numeric($idAAjouter)) {
106
						$nns[] = $idAAjouter;
91
						$nns[] = $idAAjouter;
107
					}
92
					}
108
				}
93
				}
109
			}
94
			}
110
		}
95
		}
111
		return $nns;
96
		return $nns;
112
	}
97
	}
113
 
98
 
114
	private function supprimerCodeReftaxDesUrls($urls) {
99
	private function supprimerCodeReferentielDesUrls($urls) {
115
		$urlsNettoyees = array();
100
		$urlsNettoyees = array();
116
		foreach ($urls as $id => $url) {
101
		foreach ($urls as $id => $url) {
117
			$id = $this->supprimerCodeReftax($id);
102
			$id = $this->supprimerCodeReferentiel($id);
118
			$urlsNettoyees[$id] = $url;
103
			$urlsNettoyees[$id] = $url;
119
		}
104
		}
120
		return $urlsNettoyees;
105
		return $urlsNettoyees;
121
	}
106
	}
122
 
107
 
123
	private function supprimerCodeReftax($chaine) {
108
	private function supprimerCodeReferentiel($chaine) {
124
		$codeReftax = $this->parametres->reftaxCourant.'.';
109
		$codeReferentiel = $this->parametres->referentielCourant.'.';
125
		$chaine = str_replace($codeReftax, '', $chaine);
110
		$chaine = str_replace($codeReferentiel, '', $chaine);
126
		return $chaine;
111
		return $chaine;
127
	}
112
	}
-
 
113
	
-
 
114
	private function chargerRepartition() {
-
 
115
		if (Config::get(Registre::get('parametres.referentiel').'.baseRepartition') != "") {
-
 
116
			$this->apiCartes->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseRepartition'));
-
 
117
			$this->apiCartes->setLargeur('108x101');
-
 
118
			$urls = array();
-
 
119
			foreach ($this->noms as $nom) {
-
 
120
				if (array_key_exists('nom_retenu.code', $nom)) {
-
 
121
					$id = $nom['nom_retenu.code'];
-
 
122
					$id = $this->supprimerCodeReferentielAvecNn($id);
-
 
123
					$this->apiCartes->setId("nn:$id");
-
 
124
					if (array_key_exists($id, $urls) == false) {
-
 
125
						$urls[$id] = $this->apiCartes->getUrlPng();
-
 
126
					}
-
 
127
				}
-
 
128
			}
-
 
129
			$this->infosPourTpl['repartition']['urls'] = $urls;
-
 
130
		}
-
 
131
	}
128
	
132
	
129
	function supprimerAccents($chaine){
133
	function supprimerAccents($chaine){
130
		return strtr($chaine,array('à' => 'a','á' => 'a','â' => 'a','ã' => 'a','ä' => 'a',
134
		return strtr($chaine,array('à' => 'a','á' => 'a','â' => 'a','ã' => 'a','ä' => 'a',
131
										'ç' => 'c',
135
										'ç' => 'c',
132
										'è' => 'e','é' => 'e','ê' => 'e','ë' => 'e',
136
										'è' => 'e','é' => 'e','ê' => 'e','ë' => 'e',
133
										'ì' => 'i','í' => 'i','î' => 'i','ï' => 'i',
137
										'ì' => 'i','í' => 'i','î' => 'i','ï' => 'i',
134
										'ñ' => 'n',
138
										'ñ' => 'n',
135
										'ò' => 'o', 'ó' => 'o' , 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 
139
										'ò' => 'o', 'ó' => 'o' , 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 
136
										'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 
140
										'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', 
137
										'ý' => 'y', 'ÿ' => 'y'));
141
										'ý' => 'y', 'ÿ' => 'y'));
138
	}
142
	}
139
	
143
	
140
 
144
 
141
	private function extraireInfosNomsPourTplDetermination() {
145
	private function extraireInfosNomsPourTplDetermination() {
142
		$taxons = array();
146
		$taxons = array();
143
		foreach ($this->noms as $idNomCourant => $nom) {
147
		foreach ($this->noms as $idNomCourant => $nom) {
144
			$nn = $this->supprimerCodeReftaxAvecNn($nom['nom_retenu.code']);
148
			$nn = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
145
			$nom_min = strtolower($nom['nom_vernaculaire']);
149
			$nom_min = strtolower($nom['nom_vernaculaire']);
146
			$nom_ss_accent = $this->supprimerAccents($nom_min);
150
			$nom_ss_accent = $this->supprimerAccents($nom_min);
147
			if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/', $nom_ss_accent )) {
151
			if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).' |^'.strtolower($this->parametres->masqueRecherche).'$/', $nom_ss_accent )) {
148
				//au moins un debute par la requête
152
				//au moins un debute par la requête
149
				if (isset($taxons) && array_key_exists($nn, $taxons[0]) == false) { 
153
				if (isset($taxons) && array_key_exists($nn, $taxons[0]) == false) { 
150
					$taxons[0][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
154
					$taxons[0][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
151
				}
155
				}
152
				$taxons[0][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
156
				$taxons[0][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
153
			} else { 
157
			} else { 
154
				//contient
158
				//contient
155
				if (isset($taxons) && array_key_exists($nn, $taxons[1]) == false) {
159
				if (isset($taxons) && (!isset($taxons[1]) || array_key_exists($nn, $taxons[1]) == false)) {
156
					$taxons[1][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
160
					$taxons[1][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
157
				}
161
				}
158
				$taxons[1][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
162
				$taxons[1][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
159
			}
163
			}
160
		}
164
		}
161
		$this->infosPourTpl['noms'] = isset($taxons)  ? $taxons : false;
165
		$this->infosPourTpl['noms'] = isset($taxons)  ? $taxons : false;
162
	}
166
	}
163
	
167
	
164
	private function renvoyerInfosNomVerna($valeurs) {
168
	private function renvoyerInfosNomVerna($valeurs) {
165
		$nom_verna = array();
169
		$nom_verna = array();
166
		$nom_verna['nn'] = $valeurs['id'];
170
		$nom_verna['nn'] = $valeurs['id'];
167
		$nom_verna['nom_vernaculaire'] = $valeurs['nom_vernaculaire'];
171
		$nom_verna['nom_vernaculaire'] = $valeurs['nom_vernaculaire'];
168
		return $nom_verna;
172
		return $nom_verna;
169
	}
173
	}
170
	
174
	
171
	private function renvoyerInfosTaxon($nomSci, $nn) {
175
	private function renvoyerInfosTaxon($nomSci, $nn) {
172
		$taxon = array();
176
		$taxon = array();
173
		$taxon['nomSci'] = $nomSci;
177
		$taxon['nomSci'] = $nomSci;
174
		$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
178
		$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
175
		$taxon['repartition_vignette'] = $this->chargerRepartition($nn);
179
		$taxon['repartition_vignette'] = $this->chargerRepartition($nn);
176
		return $taxon;
180
		return $taxon;
177
	}
181
	}
178
 
182
 
179
	private function supprimerCodeReftaxAvecNn($nn) {
183
	private function supprimerCodeReferentielAvecNn($nn) {
180
		$codeReftax = $this->parametres->reftaxCourant.'.nn:';
184
		$codeReferentiel = $this->parametres->referentielCourant.'.nn:';
181
		return str_replace($codeReftax, '', $nn);
185
		return str_replace($codeReferentiel, '', $nn);
182
	}
186
	}
183
 
187
 
184
	//tri alphabétique des noms scientifiques par catégorie (débute par , contient )
188
	//tri alphabétique des noms scientifiques par catégorie (débute par , contient )
185
	public function trier() {
189
	public function trier() {
186
		$verna = array();
190
		$verna = array();
187
		foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
191
		foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
188
			$verna += $this->classerAlphabetiquement('nomSci', $valeurs);
192
			$verna += $this->classerAlphabetiquement('nomSci', $valeurs);
189
		}
193
		}
190
		$this->infosPourTpl['noms'] = $verna;
194
		$this->infosPourTpl['noms'] = $verna;
191
	}
195
	}
192
	
196
	
193
	private function classerAlphabetiquement($champs, $valeurs) {
197
	private function classerAlphabetiquement($champs, $valeurs) {
194
		$this->trieur->setTableau($valeurs);
198
		$this->trieur->setTableau($valeurs);
195
		$this->trieur->setChampsEtOrdres(array($champs => SORT_NATURAL));
199
		$this->trieur->setChampsEtOrdres(array($champs => 'nat'));
196
		return $this->trieur->trier();
200
		return $this->trieur->trier();
197
	}
201
	}
198
	
202
	
199
	
203
	
200
 
204
 
201
	public function surligner() {
205
	public function surligner() {
202
		$this->definirMotsASurligner();
206
		$this->definirMotsASurligner();
203
		foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
207
		foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
204
			foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
208
			foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
205
				$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
209
				$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
206
			}
210
			}
207
			$this->infosPourTpl['noms'][$idNom] = $nom;
211
			$this->infosPourTpl['noms'][$idNom] = $nom;
208
		}
212
		}
209
	}
213
	}
210
 
214
 
211
	private function definirMotsASurligner() {
215
	private function definirMotsASurligner() {
212
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
216
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
213
 
217
 
214
	}
218
	}
215
	
219
	
216
	private function surlignerMotsMasqueRecherche($nom) {
220
	private function surlignerMotsMasqueRecherche($nom) {
217
		$this->surligneur->setTexte($nom);
221
		$this->surligneur->setTexte($nom);
218
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
222
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
219
		return $nom;
223
		return $nom;
220
	}
224
	}
221
}
225
}
222
?>
226
?>