Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

Rev 1068 Rev 1115
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
 
36
 
37
	public function getTplInfos() {
37
	public function getTplInfos() {
38
		return $this->infosPourTpl;
38
		return $this->infosPourTpl;
39
	}
39
	}
40
 
40
 
41
	public function getTplNom() {
41
	public function getTplNom() {
42
		return self::TPL_VUE;
42
		return self::TPL_VUE;
43
	}
43
	}
44
 
44
 
45
	public function formater() {
45
	public function formater() {
46
		$this->obtenirUrlsDessins();
46
		$this->obtenirUrlsDessins();
47
		$this->obtenirUrlsPhotos();
47
		$this->obtenirUrlsPhotos();
48
		$this->chargerRepartition();
48
		$this->chargerRepartition();
49
		$this->extraireInfosNomsPourTplDetermination();
49
		$this->extraireInfosNomsPourTplDetermination();
50
	}
50
	}
51
	
51
	
52
	private function obtenirUrlsDessins() {
52
	private function obtenirUrlsDessins() {
53
		if (Config::get(Registre::get('parametres.referentiel').'.baseDessins') != "") {
53
		if (Config::get(Registre::get('parametres.referentiel').'.baseDessins') != "") {
54
			$this->extraireInfosTaxons();
54
			$this->extraireInfosTaxons();
55
			$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseDessins'));
55
			$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseDessins'));
56
			$tax = implode(',', $this->infosPourTpl['taxons']);
56
			$tax = implode(',', $this->infosPourTpl['taxons']);
57
			$this->imagesService->setNnTaxon($tax);
57
			$this->imagesService->setNnTaxon($tax);
58
			$costeImg = $this->imagesService->getInfosImagesTaxons();
58
			$costeImg = $this->imagesService->setApi(Eflore::API_EFLORE)->getInfosImagesTaxons();
59
			if (!empty($costeImg)) {
59
			if (!empty($costeImg)) {
60
				foreach ($costeImg as  $infos) {
60
				foreach ($costeImg as  $infos) {
61
					$num_taxon = $infos['num_taxonomique'];
61
					$num_taxon = $infos['num_taxonomique'];
62
					$images[$num_taxon][] = $infos['binaire.href'];
62
					$images[$num_taxon][] = $infos['binaire.href'];
63
					$this->infosPourTpl['imagesCoste'] = $images;
63
					$this->infosPourTpl['imagesCoste'] = $images;
64
				}
64
				}
65
			}
65
			}
66
		}
66
		}
67
	}
67
	}
68
	
68
	
69
	private function extraireInfosTaxons() {
69
	private function extraireInfosTaxons() {
70
		foreach ($this->noms as $id => $nom ) {
70
		foreach ($this->noms as $id => $nom ) {
71
			if (array_key_exists('num_taxon', $nom) 
71
			if (array_key_exists('num_taxon', $nom) 
72
				&& array_key_exists('taxon', $nom)) {
72
				&& array_key_exists('taxon', $nom)) {
73
				$this->infosPourTpl['taxons'][$nom['taxon']] = $nom['num_taxon'];
73
				$this->infosPourTpl['taxons'][$nom['taxon']] = $nom['num_taxon'];
74
			}
74
			}
75
		}
75
		}
76
	}
76
	}
77
 
77
 
78
	private function obtenirUrlsPhotos() {
78
	private function obtenirUrlsPhotos() {
79
		if (Config::get(Registre::get('parametres.referentiel').'.baseImages') != "") {
79
		if (Config::get(Registre::get('parametres.referentiel').'.baseImages') != "") {
80
			$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseImages'));
80
			$this->imagesService->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseImages'));
81
			$nns = $this->extraireNnDesNoms();
81
			$nns = $this->extraireNnDesNoms();
82
			$urls = $this->imagesService->getUrlsImagesParIdsNoms($nns);
82
			$urls = $this->imagesService->setApi(Eflore::API_EFLORE)->getUrlsImagesParIdsNoms($nns);
83
			$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReferentielDesUrls($urls);
83
			$this->infosPourTpl['imagesUrls'] = $this->supprimerCodeReferentielDesUrls($urls);
84
		}
84
		}
85
	}
85
	}
86
 
86
 
87
	private function extraireNnDesNoms() {
87
	private function extraireNnDesNoms() {
88
		$nns = array();
88
		$nns = array();
89
		foreach ($this->noms as $id => $nom) {
89
		foreach ($this->noms as $id => $nom) {
90
			if (array_key_exists('nom_retenu.code', $nom)) {
90
			if (array_key_exists('nom_retenu.code', $nom)) {
91
				if (in_array($nom['nom_retenu.code'], $nns) == false) {
91
				if (in_array($nom['nom_retenu.code'], $nns) == false) {
92
					$idAAjouter = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
92
					$idAAjouter = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
93
					if (is_numeric($idAAjouter)) {
93
					if (is_numeric($idAAjouter)) {
94
						$nns[] = $idAAjouter;
94
						$nns[] = $idAAjouter;
95
					}
95
					}
96
				}
96
				}
97
			}
97
			}
98
		}
98
		}
99
		return $nns;
99
		return $nns;
100
	}
100
	}
101
 
101
 
102
	private function supprimerCodeReferentielDesUrls($urls) {
102
	private function supprimerCodeReferentielDesUrls($urls) {
103
		$urlsNettoyees = array();
103
		$urlsNettoyees = array();
104
		foreach ($urls as $id => $url) {
104
		foreach ($urls as $id => $url) {
105
			$id = $this->supprimerCodeReferentiel($id);
105
			$id = $this->supprimerCodeReferentiel($id);
106
			$urlsNettoyees[$id] = $url;
106
			$urlsNettoyees[$id] = $url;
107
		}
107
		}
108
		return $urlsNettoyees;
108
		return $urlsNettoyees;
109
	}
109
	}
110
 
110
 
111
	private function supprimerCodeReferentiel($chaine) {
111
	private function supprimerCodeReferentiel($chaine) {
112
		$codeReferentiel = $this->parametres->referentielCourant.'.';
112
		$codeReferentiel = $this->parametres->referentielCourant.'.';
113
		$chaine = str_replace($codeReferentiel, '', $chaine);
113
		$chaine = str_replace($codeReferentiel, '', $chaine);
114
		return $chaine;
114
		return $chaine;
115
	}
115
	}
116
	
116
	
117
	private function chargerRepartition() {
117
	private function chargerRepartition() {
118
		// $numsNomsASynonymes = $this->extraireNumerosNomSynonymes();
118
		// $numsNomsASynonymes = $this->extraireNumerosNomSynonymes();
119
		if (Config::get(Registre::get('parametres.referentiel').'.baseRepartition') == "") {
119
		if (Config::get(Registre::get('parametres.referentiel').'.baseRepartition') == "") {
120
			return;
120
			return;
121
		}
121
		}
122
 
122
 
123
		$this->apiCartes->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseRepartition'));
123
		$this->apiCartes->setProjet(Config::get(Registre::get('parametres.referentiel').'.baseRepartition'));
124
		$this->apiCartes->setLargeur('108x101');
124
		$this->apiCartes->setLargeur('108x101');
125
		$urls = array();
125
		$urls = array();
126
		foreach ($this->noms as $nom) {
126
		foreach ($this->noms as $nom) {
127
			if (array_key_exists('nom_retenu.code', $nom)) {
127
			if (array_key_exists('nom_retenu.code', $nom)) {
128
				$id = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
128
				$id = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
129
				$this->apiCartes->setId("nn:" . $id); //  . ',' . implode(',', array_keys($numsNomsASynonymes[$id])));
129
				$this->apiCartes->setId("nn:" . $id); //  . ',' . implode(',', array_keys($numsNomsASynonymes[$id])));
130
				if (array_key_exists($id, $urls) == false) {
130
				if (array_key_exists($id, $urls) == false) {
131
					$urls[$id] = $this->apiCartes->getUrlPng();
131
					$urls[$id] = $this->apiCartes->getUrlPng();
132
				}
132
				}
133
			}
133
			}
134
		}
134
		}
135
		$this->infosPourTpl['repartition']['urls'] = $urls;
135
		$this->infosPourTpl['repartition']['urls'] = $urls;
136
	}
136
	}
137
	
137
	
138
	private function extraireNumerosNomSynonymes() {
138
	private function extraireNumerosNomSynonymes() {
139
		$numNomsASynonyme = array();
139
		$numNomsASynonyme = array();
140
		foreach ($this->noms as $id => $nom) {
140
		foreach ($this->noms as $id => $nom) {
141
			$num_nom_retenu = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
141
			$num_nom_retenu = $this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']);
142
			// faux
142
			// faux
143
			$numNomsASynonyme[$num_nom_retenu][$id] = TRUE;
143
			$numNomsASynonyme[$num_nom_retenu][$id] = TRUE;
144
		}
144
		}
145
		return $numNomsASynonyme;
145
		return $numNomsASynonyme;
146
	}
146
	}
147
	
147
	
148
	private function extraireInfosNomsPourTplDetermination() {
148
	private function extraireInfosNomsPourTplDetermination() {
149
		$taxons = array();
149
		$taxons = array();
150
		foreach ($this->noms as $idNomCourant => $nom) {
150
		foreach ($this->noms as $idNomCourant => $nom) {
151
			$nn = intval($this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']));
151
			$nn = intval($this->supprimerCodeReferentielAvecNn($nom['nom_retenu.code']));
152
			$nomV = iconv('UTF-8', 'ASCII//TRANSLIT', strtolower($nom['nom_vernaculaire']));
152
			$nomV = iconv('UTF-8', 'ASCII//TRANSLIT', strtolower($nom['nom_vernaculaire']));
153
			if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).'(?: |$)/', $nomV)) {
153
			if (preg_match('/^'.strtolower($this->parametres->masqueRecherche).'(?: |$)/', $nomV)) {
154
				// au moins un debute par la requête
154
				// au moins un debute par la requête
155
				if (isset($taxons) && array_key_exists($nn, $taxons[0]) == false) { 
155
				if (isset($taxons) && array_key_exists($nn, $taxons[0]) == false) { 
156
					$taxons[0][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
156
					$taxons[0][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
157
				}
157
				}
158
				$taxons[0][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
158
				$taxons[0][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
159
			} else { 
159
			} else { 
160
				// contient
160
				// contient
161
				if (isset($taxons) && (!isset($taxons[1]) || array_key_exists($nn, $taxons[1]) == false)) {
161
				if (isset($taxons) && (!isset($taxons[1]) || array_key_exists($nn, $taxons[1]) == false)) {
162
					$taxons[1][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
162
					$taxons[1][$nn] = $this->renvoyerInfosTaxon($nom['taxon'], $nn);
163
				}
163
				}
164
				$taxons[1][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
164
				$taxons[1][$nn]['nomVerna'][] = $this->renvoyerInfosNomVerna($nom);
165
			}
165
			}
166
		}
166
		}
167
		$this->infosPourTpl['noms'] = isset($taxons)  ? $taxons : false;
167
		$this->infosPourTpl['noms'] = isset($taxons)  ? $taxons : false;
168
	}
168
	}
169
	
169
	
170
	private function renvoyerInfosNomVerna($valeurs) {
170
	private function renvoyerInfosNomVerna($valeurs) {
171
		$nom_verna = array();
171
		$nom_verna = array();
172
		$nom_verna['nn'] = $valeurs['id'];
172
		$nom_verna['nn'] = $valeurs['id'];
173
		$nom_verna['nom_vernaculaire'] = $valeurs['nom_vernaculaire'];
173
		$nom_verna['nom_vernaculaire'] = $valeurs['nom_vernaculaire'];
174
		return $nom_verna;
174
		return $nom_verna;
175
	}
175
	}
176
	
176
	
177
	private function renvoyerInfosTaxon($nomSci, $nn) {
177
	private function renvoyerInfosTaxon($nomSci, $nn) {
178
		$taxon = array();
178
		$taxon = array();
179
		$taxon['nomSci'] = $nomSci;
179
		$taxon['nomSci'] = $nomSci;
180
		$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
180
		$taxon['urlFiche'] = $this->urls->obtenirUrlFiche($nn, $this->parametres->typeNom, $this->parametres->masqueRecherche);
181
		$this->chargerRepartition($nn);
181
		$this->chargerRepartition($nn);
182
		$taxon['repartition_vignette'] = $this->infosPourTpl['repartition']['urls'];
182
		$taxon['repartition_vignette'] = $this->infosPourTpl['repartition']['urls'];
183
		return $taxon;
183
		return $taxon;
184
	}
184
	}
185
 
185
 
186
	private function supprimerCodeReferentielAvecNn($nn) {
186
	private function supprimerCodeReferentielAvecNn($nn) {
187
		return str_replace($this->parametres->referentielCourant.'.nn:', '', $nn);
187
		return str_replace($this->parametres->referentielCourant.'.nn:', '', $nn);
188
	}
188
	}
189
 
189
 
190
	//tri alphabétique des noms scientifiques par catégorie (débute par , contient )
190
	//tri alphabétique des noms scientifiques par catégorie (débute par , contient )
191
	public function trier() {
191
	public function trier() {
192
		$verna = array();
192
		$verna = array();
193
		foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
193
		foreach ($this->infosPourTpl['noms'] as $categorie => $valeurs) {
194
			$verna += $this->classerAlphabetiquement('nomSci', $valeurs);
194
			$verna += $this->classerAlphabetiquement('nomSci', $valeurs);
195
		}
195
		}
196
		$this->infosPourTpl['noms'] = $verna;
196
		$this->infosPourTpl['noms'] = $verna;
197
	}
197
	}
198
	
198
	
199
	private function classerAlphabetiquement($champs, $valeurs) {
199
	private function classerAlphabetiquement($champs, $valeurs) {
200
		$this->trieur->setTableau($valeurs);
200
		$this->trieur->setTableau($valeurs);
201
		$this->trieur->setChampsEtOrdres(array($champs => 'nat'));
201
		$this->trieur->setChampsEtOrdres(array($champs => 'nat'));
202
		return $this->trieur->trier();
202
		return $this->trieur->trier();
203
	}
203
	}
204
	
204
	
205
	
205
	
206
 
206
 
207
	public function surligner() {
207
	public function surligner() {
208
		$this->definirMotsASurligner();
208
		$this->definirMotsASurligner();
209
		foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
209
		foreach ($this->infosPourTpl['noms'] as $idNom => $nom) {
210
			foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
210
			foreach ($nom['nomVerna'] as $idVerna => $nomVerna) {
211
				$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
211
				$nom['nomVerna'][$idVerna]['nom_vernaculaire'] = $this->surlignerMotsMasqueRecherche($nomVerna['nom_vernaculaire']);
212
			}
212
			}
213
			$this->infosPourTpl['noms'][$idNom] = $nom;
213
			$this->infosPourTpl['noms'][$idNom] = $nom;
214
		}
214
		}
215
	}
215
	}
216
 
216
 
217
	private function definirMotsASurligner() {
217
	private function definirMotsASurligner() {
218
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
218
		$this->motsASurligner = explode(' ', $this->parametres->masqueRecherche);
219
 
219
 
220
	}
220
	}
221
	
221
	
222
	private function surlignerMotsMasqueRecherche($nom) {
222
	private function surlignerMotsMasqueRecherche($nom) {
223
		$this->surligneur->setTexte($nom);
223
		$this->surligneur->setTexte($nom);
224
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
224
		$nom = $this->surligneur->surlignerMots($this->motsASurligner);
225
		return $nom;
225
		return $nom;
226
	}
226
	}
227
}
227
}
228
?>
228
?>