Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 31 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31 alex 1
<?php
2
 
3
abstract class Formateur {
4
 
5
	protected $criteresRecherche;
34 alex 6
	protected $bdd = null;
31 alex 7
	protected $nomSource = '';
8
 
9
 
34 alex 10
	public function __construct($criteresRecherche, $source) {
31 alex 11
		$this->criteresRecherche = $criteresRecherche;
34 alex 12
		$this->nomSource = $source;
31 alex 13
	}
14
 
34 alex 15
	protected function getBdd() {
16
		if (is_null($this->bdd)) {
17
			$this->bdd = new Bdd();
18
			$nomBdd = $this->nomSource == 'floradata' ? Config::get('bdd_nom_floradata') : Config::get('bdd_nom_eflore');
19
			$this->bdd->requeter("USE {$nomBdd}");
31 alex 20
		}
34 alex 21
		return $this->bdd;
31 alex 22
	}
23
 
34 alex 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);
32
				$maillage->genererMaillesVides();
33
				$maillage->ajouterStations($stations);
34
				$stations = $maillage->formaterSortie();
35
			}
36
		} else {
37
			$nombreStations = $this->obtenirNombreStationsDansBbox();
38
			if ($this->determinerFormatRetour($nombreStations) == 'maille') {
39
				$stations = $this->recupererMaillesDansBbox();
40
			} else {
41
				$requeteSql = $this->construireRequeteStations();
42
				$stations = $this->getBdd()->recupererTous($requeteSql);
43
			}
31 alex 44
		}
45
		return $stations;
46
	}
47
 
34 alex 48
	public function recupererWfs() {
49
		$requeteSql = $this->construireRequeteWfs();
50
		return $this->getBdd()->recupererTous($requeteSql);
31 alex 51
	}
52
 
34 alex 53
	protected function determinerFormatRetour($nombreStations) {
54
		$formatRetour = 'point';
55
		$zoomMaxMaillage = Config::get('zoom_maximal_maillage');
56
		if (isset($this->criteresRecherche->format) && $this->criteresRecherche->format == 'maille'
57
			&& $this->criteresRecherche->zoom <= $zoomMaxMaillage) {
58
			$formatRetour = 'maille';
31 alex 59
		} else {
34 alex 60
			$seuilMaillage   = Config::get('seuil_maillage');
61
			if ($this->criteresRecherche->zoom <= $zoomMaxMaillage && $nombreStations > $seuilMaillage) {
62
				$formatRetour = 'maille';
31 alex 63
			}
64
		}
34 alex 65
		return $formatRetour;
31 alex 66
	}
67
 
68
	protected function calculerNombreCriteresNonSpatiaux() {
69
		$nombreParametresNonSpatiaux = 0;
34 alex 70
		$criteresAIgnorer = array('zoom', 'bbox', 'stations', 'referentiel', 'format');
31 alex 71
		foreach ($this->criteresRecherche as $nomCritere => $valeur) {
72
			if (!in_array($nomCritere, $criteresAIgnorer)) {
73
				$nombreParametresNonSpatiaux ++;
74
			}
75
		}
76
		return $nombreParametresNonSpatiaux;
77
	}
78
 
34 alex 79
	abstract protected function construireRequeteStations();
80
 
81
	protected function obtenirNombreStationsDansBbox() {}
82
 
83
	protected function recupererMaillesDansBbox() {}
84
 
85
	public function recupererObservations() {
86
		$requeteSql = $this->construireRequeteObservations();
87
		$observations = $this->getBdd()->recupererTous($requeteSql);
88
		if ($this->nomSource != 'floradata') {
89
			$this->recupererNumeroNomenclaturauxTaxons($observations);
31 alex 90
		}
34 alex 91
		$nomStation = $this->obtenirNomsStationsSurPoint();
92
		if (strlen($nomStation) == 0) {
93
			$nomStation = 'station sans nom';
94
		}
31 alex 95
		for ($index = 0; $index < count($observations);  $index ++) {
34 alex 96
			$observations[$index]['nom_station'] = $nomStation;
31 alex 97
		}
34 alex 98
		return $observations;
31 alex 99
	}
100
 
34 alex 101
	abstract protected function construireRequeteObservations();
31 alex 102
 
34 alex 103
	protected function recupererNumeroNomenclaturauxTaxons(& $observations) {
104
		for ($index = 0; $index < count($observations); $index ++) {
105
			if (strlen (trim($observations[$index]['nomSci'])) == 0) {
106
				continue;
107
			}
108
			$numeroNomenclatural = isset($observations[$index]['nn']) ? $observations[$index]['nn'] : null;
109
			$referentiels = Referentiel::recupererListeReferentielsDisponibles();
110
			$taxon = null;
111
			$indexRef = 0;
112
			while ($indexRef < count($referentiels) && is_null($taxon)) {
113
				$referentiel = new Referentiel($referentiels[$indexRef]);
114
				$taxon = $referentiel->obtenirNumeroNomenclatural($observations[$index]['nomSci'],
115
					$numeroNomenclatural);
116
				$indexRef ++;
117
			}
31 alex 118
			if (!is_null($taxon)) {
34 alex 119
				$observations[$index]['nn'] = $taxon['nn'];
120
				$observations[$index]['nom_referentiel'] = $taxon['referentiel'];
121
			} else {
122
				$observations[$index]['nn'] = '';
31 alex 123
			}
124
		}
125
	}
126
 
34 alex 127
	abstract protected function obtenirNomsStationsSurPoint();
128
 
31 alex 129
}
130
 
131
?>