Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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