Subversion Repositories eFlore/Applications.eflore-consultation

Rev

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

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