Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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