Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 31 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 31 Rev 34
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
2
 
2
 
Line 3... Line 3...
3
abstract class Formateur {
3
abstract class Formateur {
4
	
4
	
5
	protected $criteresRecherche;
5
	protected $criteresRecherche;
Line 6... Line 6...
6
	protected $bdd;
6
	protected $bdd = null;
7
	protected $nomSource = '';
7
	protected $nomSource = '';
8
	
8
	
9
	
9
	
Line 10... Line 10...
10
	public function __construct($criteresRecherche) {
10
	public function __construct($criteresRecherche, $source) {
-
 
11
		$this->criteresRecherche = $criteresRecherche;
11
		$this->criteresRecherche = $criteresRecherche;
12
		$this->nomSource = $source;
12
		$this->nomSource = Config::get('nom_source');
13
	}
13
	}
14
	
14
	
15
	protected function getBdd() {
15
	public function recupererStations() {
16
		if (is_null($this->bdd)) {
16
		$stations = null;
17
			$this->bdd = new Bdd();
Line 17... Line 18...
17
		if ($this->estTraitementRecuperationAutorise()) {
18
			$nomBdd = $this->nomSource == 'floradata' ? Config::get('bdd_nom_floradata') : Config::get('bdd_nom_eflore');
18
			$stations = $this->traiterRecupererStations();
19
			$this->bdd->requeter("USE {$nomBdd}");
-
 
20
		}
-
 
21
		return $this->bdd;
-
 
22
	}
-
 
23
	
-
 
24
	public function recupererStations() {
-
 
25
		$stations = array();
-
 
26
		if ($this->nomSource == 'floradata' || $this->calculerNombreCriteresNonSpatiaux() > 0) {
-
 
27
			$requeteSql = $this->construireRequeteStations();
-
 
28
			$stations = $this->getBdd()->recupererTous($requeteSql);
-
 
29
			if ($this->determinerFormatRetour(count($stations)) == 'maille') {
-
 
30
				$maillage = new Maillage($this->criteresRecherche->bbox,
-
 
31
				$this->criteresRecherche->zoom, $this->nomSource);
19
		}
32
				$maillage->genererMaillesVides();
20
		return $stations;
33
				$maillage->ajouterStations($stations);
-
 
34
				$stations = $maillage->formaterSortie();
-
 
35
			}
-
 
36
		} else {
-
 
37
			$nombreStations = $this->obtenirNombreStationsDansBbox();
21
	}
38
			if ($this->determinerFormatRetour($nombreStations) == 'maille') {
22
	
39
				$stations = $this->recupererMaillesDansBbox();
23
	public function recupererObservations() {
40
			} else {
Line 24... Line 41...
24
		$stations = null;
41
				$requeteSql = $this->construireRequeteStations();
25
		if ($this->estTraitementRecuperationAutorise()) {
-
 
26
			$stations = $this->traiterRecupererObservations();
42
				$stations = $this->getBdd()->recupererTous($requeteSql);
27
		}
43
			}
28
		return $stations;
-
 
29
	}
-
 
30
	
44
		}
Line 31... Line 45...
31
	protected function estTraitementRecuperationAutorise() {
45
		return $stations;
32
		return (!(
46
	}
33
			isset($this->criteresRecherche->nbJours) ||
-
 
34
			(isset($this->criteresRecherche->referentiel) &&
-
 
35
			$this->criteresRecherche->referentiel != Config::get('referentiel_source'))
-
 
36
		));
-
 
37
	}
-
 
38
	
-
 
39
	protected function traiterRecupererStations() {
-
 
40
		$stations = array();
-
 
41
		$nombreStations = $this->obtenirNombreStationsDansBbox();
-
 
42
		$seuilMaillage   = Config::get('seuil_maillage');
-
 
43
		$nombreParametresNonSpatiaux = $this->calculerNombreCriteresNonSpatiaux();
-
 
44
		if ($nombreStations >= $seuilMaillage && $nombreParametresNonSpatiaux == 0) {
47
	
45
			// pas besoin de rechercher les stations correspondant a ces criteres
48
	public function recupererWfs() {
46
			// recuperer les mailles se trouvant dans l'espace de recherche demande
49
		$requeteSql = $this->construireRequeteWfs();
47
			$stations = $this->recupererMaillesDansBbox();
50
		return $this->getBdd()->recupererTous($requeteSql);
-
 
51
	}
48
		} else {
52
	
-
 
53
	protected function determinerFormatRetour($nombreStations) {
49
		$requeteSql = $this->construireRequeteStations();
54
		$formatRetour = 'point';
50
		$stations = $this->getBdd()->recupererTous($requeteSql);
55
		$zoomMaxMaillage = Config::get('zoom_maximal_maillage');
51
		$zoom = $this->criteresRecherche->zoom;
56
		if (isset($this->criteresRecherche->format) && $this->criteresRecherche->format == 'maille'
52
		$zoomMaxMaillage = Config::get('zoom_maximal_maillage');
-
 
53
		if ($zoom <= $zoomMaxMaillage && count($stations) >= $seuilMaillage) {
-
 
54
				$maillage = new Maillage($this->criteresRecherche->bbox, $zoom, $this->nomSource);
57
			&& $this->criteresRecherche->zoom <= $zoomMaxMaillage) {
55
				$maillage->genererMaillesVides();
-
 
56
				$maillage->ajouterPoints($stations);
-
 
57
				$stations = $maillage->formaterSortie();
-
 
58
			}
-
 
59
		}
-
 
60
		$formateurJSON = new FormateurJson($this->nomSource);
-
 
61
		$donneesFormatees = $formateurJSON->formaterStations($stations);
-
 
62
		return $donneesFormatees;
-
 
63
	}
-
 
64
	
-
 
65
	protected function traiterRecupererObservations() {
58
			$formatRetour = 'maille';
Line 66... Line 59...
66
		$requeteSql = $this->construireRequeteObservations();
59
		} else {
67
		$observations = $this->getBdd()->recupererTous($requeteSql);
60
			$seuilMaillage   = Config::get('seuil_maillage');
68
		$this->recupererNumeroNomenclaturauxTaxons($observations);
61
			if ($this->criteresRecherche->zoom <= $zoomMaxMaillage && $nombreStations > $seuilMaillage) {
69
		$nomStation = $this->obtenirNomsStationsSurPoint();
62
				$formatRetour = 'maille';
70
		$formateurJSON = new FormateurJson($this->nomSource);
63
			}
71
		$donneesFormatees = $formateurJSON->formaterObservations($observations, $nomStation);
-
 
72
		return $donneesFormatees;
64
		}
73
	}
65
		return $formatRetour;
74
	
66
	}
75
	protected function calculerNombreCriteresNonSpatiaux() {
67
	
76
		$nombreParametresNonSpatiaux = 0;
68
	protected function calculerNombreCriteresNonSpatiaux() {
Line 77... Line 69...
77
		$criteresAIgnorer = array('zoom', 'bbox', 'longitude', 'latitude', 'referentiel');
69
		$nombreParametresNonSpatiaux = 0;
78
		foreach ($this->criteresRecherche as $nomCritere => $valeur) {
-
 
79
			if (!in_array($nomCritere, $criteresAIgnorer)) {
-
 
80
				echo $nomCritere.chr(13);
-
 
81
				$nombreParametresNonSpatiaux ++;
-
 
82
			}
-
 
83
		}
-
 
Line 84... Line 70...
84
		return $nombreParametresNonSpatiaux;
70
		$criteresAIgnorer = array('zoom', 'bbox', 'stations', 'referentiel', 'format');
-
 
71
		foreach ($this->criteresRecherche as $nomCritere => $valeur) {
85
	}
72
			if (!in_array($nomCritere, $criteresAIgnorer)) {
-
 
73
				$nombreParametresNonSpatiaux ++;
86
	
74
			}
87
	protected function getBdd() {
75
		}
88
		if (!isset($this->bdd)) {
76
		return $nombreParametresNonSpatiaux;
89
			$this->bdd = new Bdd();
77
	}
-
 
78
	
90
		}
79
	abstract protected function construireRequeteStations();
91
		$this->bdd->requeter("USE ".Config::get('bdd_nom'));
-
 
92
		return $this->bdd;
80
	
-
 
81
	protected function obtenirNombreStationsDansBbox() {}
-
 
82
	
-
 
83
	protected function recupererMaillesDansBbox() {}
93
	}
84
	
94
	
-
 
95
	protected function getNomRang($taxon) {
-
 
96
		$nomsRangs = array('famille', 'genre', 'espece', 'sous_espece');
-
 
97
		for ($index = 0; $index < count($nomsRangs)
-
 
98
			&& Config::get("rang.".$nomsRangs[$index]) != $taxon['rang']; $index ++);
-
 
99
		$position = $index == count($nomsRangs) ? count($nomsRangs)-1 : $index;
-
 
100
		return $nomsRangs[$position];
-
 
101
	}
-
 
102
 
-
 
103
	protected function recupererNumeroNomenclaturauxTaxons(& $observations) {
-
 
104
		for ($index = 0; $index < count($observations);  $index ++) {
-
 
105
			$taxons = isset($this->criteresRecherche->taxon) ? $this->criteresRecherche->taxon : null;
-
 
106
			if (!is_null($taxons)) {
-
 
107
				foreach ($taxons as $taxon) {
85
	public function recupererObservations() {
108
					if ($observations[$index]['nomSci'] == 0) {
-
 
109
						continue;
-
 
110
					}
-
 
111
					if (isset($this->criteresRecherche->taxon)) {
-
 
112
						$taxon = $this->rechercherTaxonDansReferentiel($observations[$index]['nomSci'],
-
 
113
								$this->criteresRecherche->referentiel);
-
 
114
					} else {
86
		$requeteSql = $this->construireRequeteObservations();
-
 
87
		$observations = $this->getBdd()->recupererTous($requeteSql);
115
						$taxon = $this->obtenirNumeroTaxon($observations[$index]['nomSci']);
88
		if ($this->nomSource != 'floradata') {
Line -... Line 89...
-
 
89
			$this->recupererNumeroNomenclaturauxTaxons($observations);
-
 
90
		}
116
					}
91
		$nomStation = $this->obtenirNomsStationsSurPoint();
117
					if (!is_null($taxon)) {
92
		if (strlen($nomStation) == 0) {
118
						$observations[$index]['nn'] = $taxon['nn'];
93
			$nomStation = 'station sans nom';
119
						$observations[$index]['num_referentiel'] = $taxon['referentiel'];
94
		}
120
					} else {
95
		for ($index = 0; $index < count($observations);  $index ++) {
121
						$observations[$index]['nn'] = '';
-
 
-
 
96
			$observations[$index]['nom_station'] = $nomStation; 	
122
					}
97
		}
123
				}
98
		return $observations;
-
 
99
	}
124
			}
100
	
125
		}
101
	abstract protected function construireRequeteObservations();
126
	}
102
	
-
 
103
	protected function recupererNumeroNomenclaturauxTaxons(& $observations) {
-
 
104
		for ($index = 0; $index < count($observations); $index ++) {
-
 
105
			if (strlen (trim($observations[$index]['nomSci'])) == 0) {
127
	
106
				continue;
128
	protected function rechercherTaxonDansReferentiel($nomScientifique, $nomReferentiel) {
107
			}
-
 
108
			$numeroNomenclatural = isset($observations[$index]['nn']) ? $observations[$index]['nn'] : null;
129
		$referentiel = new Referentiel($nomReferentiel);
109
			$referentiels = Referentiel::recupererListeReferentielsDisponibles();
-
 
110
			$taxon = null;
130
		$taxon = $referentiel->obtenirNumeroNomenclatural($nomScientifique);
111
			$indexRef = 0;
131
		return $taxon;
112
			while ($indexRef < count($referentiels) && is_null($taxon)) {
132
	}
-
 
133
	
113
				$referentiel = new Referentiel($referentiels[$indexRef]);
Line -... Line 114...
-
 
114
				$taxon = $referentiel->obtenirNumeroNomenclatural($observations[$index]['nomSci'],
-
 
115
					$numeroNomenclatural);
134
	protected function obtenirNumeroTaxon($nomScientifique) {
116
				$indexRef ++;
Line 135... Line 117...
135
		$taxonTrouve = null;
117
			}
136
		$listeReferentiels = Referentiel::recupererListeReferentielsDisponibles();
118
			if (!is_null($taxon)) {