Subversion Repositories eFlore/Applications.moissonnage

Rev

Rev 34 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34 Rev 43
1
<?php
1
<?php
2
 
2
 
3
class FormateurWfs {
3
class FormateurWfs {
4
	
4
	
5
	const TYPE_MIME = 'text/xml';
5
	const TYPE_MIME = 'text/xml';
6
	private $bbox = null;
6
	private $bbox = null;
7
	
7
	
8
	public function formaterGetCapabilities() {
8
	public function formaterGetCapabilities() {
9
		$nomFichierWfs = dirname(__FILE__).DS."squelettes".DS."GetCapabilities.tpl.xml";
9
		$nomFichierWfs = dirname(__FILE__).DS."squelettes".DS."GetCapabilities.tpl.xml";
10
		return SquelettePhp::analyser($nomFichierWfs);
10
		return SquelettePhp::analyser($nomFichierWfs);
11
	}
11
	}
12
	
12
	
13
	public function formaterDescribeFeatureType($sources) {
13
	public function formaterDescribeFeatureType($sources) {
14
		$nomFichierWfs = dirname(__FILE__).DS."squelettes".DS."DescribeFeatureType.tpl.xml";
14
		$nomFichierWfs = dirname(__FILE__).DS."squelettes".DS."DescribeFeatureType.tpl.xml";
15
		if (is_null($sources)) {
15
		if (is_null($sources)) {
16
			$sources = Config::get('sources_dispo');
16
			$sources = Config::get('sources_dispo');
17
		}
17
		}
18
		$listeSources = is_array($sources) == 1 ? $sources : explode(',', $sources);
18
		$listeSources = is_array($sources) == 1 ? $sources : explode(',', $sources);
19
		$item = array('listeSources' => $listeSources);
19
		$item = array('listeSources' => $listeSources);
20
		return SquelettePhp::analyser($nomFichierWfs, $item);
20
		return SquelettePhp::analyser($nomFichierWfs, $item);
21
	}
21
	}
22
	
22
	
23
	public function formaterGetFeature(& $stations, $sources) {
23
	public function formaterGetFeature(& $stations, $sources) {
24
		$nomFichierWfs = dirname(__FILE__).DS."squelettes".DS."GetFeature.tpl.xml";
24
		$nomFichierWfs = dirname(__FILE__).DS."squelettes".DS."GetFeature.tpl.xml";
25
		$this->bbox = array('ouest' => null, 'est' => null, 'sud' => null, 'nord'=> null);
25
		$this->bbox = array('ouest' => null, 'est' => null, 'sud' => null, 'nord'=> null);
26
		$stationsRetour = $this->mettreEnPageStations($stations);
26
		$stationsRetour = $this->mettreEnPageStations($stations);
27
		$listeSources = implode(',', $sources);
27
		$listeSources = implode(',', $sources);
28
		$item = array('enveloppe' => $this->bbox, 'stations' => $stationsRetour, 'listeSources' => $listeSources);
28
		$item = array('enveloppe' => $this->bbox, 'stations' => $stationsRetour, 'listeSources' => $listeSources);
29
		return SquelettePhp::analyser($nomFichierWfs, $item);
29
		return SquelettePhp::analyser($nomFichierWfs, $item);
30
	}
30
	}
31
	
31
	
32
	private function mettreEnPageStations(& $stations) {
32
	private function mettreEnPageStations(& $stations) {
33
		$station = array('longitude' => null, 'latitude' => null);
33
		$station = array('longitude' => null, 'latitude' => null);
34
		$stationsRetour = array();
34
		$stationsRetour = array();
35
		foreach ($stations as $stationBdd) {
35
		foreach ($stations as $stationBdd) {
36
			if ($this->estNonNul($stationBdd['longitude']) && $this->estNonNul($stationBdd['latitude'])
36
			if ($this->estNonNul($stationBdd['longitude']) && $this->estNonNul($stationBdd['latitude'])
37
			&& ($stationBdd['longitude'] != $station['longitude'] || $stationBdd['latitude'] != $station['latitude'])) {
37
			&& ($stationBdd['longitude'] != $station['longitude'] || $stationBdd['latitude'] != $station['latitude'])) {
38
				if (isset($station['source'])) {
38
				if (isset($station['source'])) {
39
					if ($station['source'] == 'floradata') {
39
					if ($station['source'] == 'floradata') {
40
						$this->mettreEnPageStationFloradata($station);
40
						$this->mettreEnPageStationFloradata($station);
41
					} else {
41
					} else {
42
						$this->mettreEnPageStationMoissonnage($station);
42
						$this->mettreEnPageStationMoissonnage($station);
43
					}
43
					}
44
					$stationsRetour[] = $station;
44
					$stationsRetour[] = $station;
45
				}
45
				}
46
				
46
				
47
				foreach ($stationBdd as $cle => $valeur) {
47
				foreach ($stationBdd as $cle => $valeur) {
48
					if ($cle != 'taxon') {
48
					if ($cle != 'taxon' && $cle != 'auteur') {
49
						$station[$cle] = $valeur;
49
						$station[$cle] = $valeur;
50
					}
50
					}
51
				}
51
				}
52
				$station['taxons'] = array(trim($stationBdd['taxon']));
52
				$station['taxons'] = array(trim($stationBdd['taxon']));
-
 
53
				$station['auteurs'] = array(trim($stationBdd['auteur']));
53
				$this->mettreAJourBbox($station);
54
				$this->mettreAJourBbox($station);
54
			} else {
55
			} else {
55
				$station['taxons'][] = trim($stationBdd['taxon']);
56
				$station['taxons'][] = trim($stationBdd['taxon']);
-
 
57
				$station['auteurs'][] = trim($stationBdd['auteur']);
56
			}
58
			}
57
		}
59
		}
58
		return $stationsRetour;
60
		return $stationsRetour;
59
	}
61
	}
60
	
62
	
61
	private function estNonNul($valeur) {
63
	private function estNonNul($valeur) {
62
		return (!is_null($valeur) && strlen(trim($valeur)) > 0);
64
		return (!is_null($valeur) && strlen(trim($valeur)) > 0);
63
	}
65
	}
64
	
66
	
65
	private function mettreAJourBbox($station) {
67
	private function mettreAJourBbox($station) {
66
		if (is_null($this->bbox['sud']) || floatval($station['latitude']) < floatval($this->bbox['sud'])) {
68
		if (is_null($this->bbox['sud']) || floatval($station['latitude']) < floatval($this->bbox['sud'])) {
67
			$this->bbox['sud'] = $station['latitude'];
69
			$this->bbox['sud'] = $station['latitude'];
68
		} elseif (is_null($this->bbox['nord']) || floatval($station['latitude']) > floatval($this->bbox['nord'])) {
70
		} elseif (is_null($this->bbox['nord']) || floatval($station['latitude']) > floatval($this->bbox['nord'])) {
69
			$this->bbox['nord'] = $station['latitude'];
71
			$this->bbox['nord'] = $station['latitude'];
70
		}
72
		}
71
		if (is_null($this->bbox['ouest']) || floatval($station['longitude']) < floatval($this->bbox['ouest'])) {
73
		if (is_null($this->bbox['ouest']) || floatval($station['longitude']) < floatval($this->bbox['ouest'])) {
72
			$this->bbox['ouest'] = $station['longitude'];
74
			$this->bbox['ouest'] = $station['longitude'];
73
		} elseif (is_null($this->bbox['est']) || floatval($station['longitude']) > floatval($this->bbox['est'])) {
75
		} elseif (is_null($this->bbox['est']) || floatval($station['longitude']) > floatval($this->bbox['est'])) {
74
			$this->bbox['est'] = $station['longitude'];
76
			$this->bbox['est'] = $station['longitude'];
75
		}
77
		}
76
	}
78
	}
77
	
79
	
78
	private function mettreEnPageStationFloradata(& $station) {
80
	private function mettreEnPageStationFloradata(& $station) {
79
		$station['nom_station'] = trim($station['station']);
81
		$station['nom_station'] = trim($station['station']);
80
		if ($this->estNonNul($station['zone_geo'])) {
82
		if ($this->estNonNul($station['zone_geo'])) {
81
			$station['nom_station'] .= ", ".$station['zone_geo'];
83
			$station['nom_station'] .= ", ".$station['zone_geo'];
82
		}
84
		}
83
		$station['nom_station'] = str_replace("&", "&amp;", trim($station['nom_station']));
85
		$station['nom_station'] = str_replace("&", "&amp;", trim($station['nom_station']));
84
		$station['departement'] = '';
86
		$station['departement'] = '';
85
		$station['code_insee'] = '';
87
		$station['code_insee'] = '';
86
		if ($this->estNonNul($station['ce_zone_geo'])) {
88
		if ($this->estNonNul($station['ce_zone_geo'])) {
87
			$station['code_insee'] = substr($station['ce_zone_geo'], 8);
89
			$station['code_insee'] = substr($station['ce_zone_geo'], 8);
88
			$station['departement'] = substr($station['code_insee'],0, 2);
90
			$station['departement'] = substr($station['code_insee'],0, 2);
89
			if (intval($station['departement']) > 95) {
91
			if (intval($station['departement']) > 95) {
90
				$station['departement'] = substr($station['code_insee'],0, 2);
92
				$station['departement'] = substr($station['code_insee'],0, 2);
91
			}
93
			}
92
		}
94
		}
93
		unset($station['station']);
95
		unset($station['station']);
94
		unset($station['zone_geo']);
96
		unset($station['zone_geo']);
95
		unset($station['ce_zone_geo']);
97
		unset($station['ce_zone_geo']);
96
		$station['taxons'] = str_replace("&", "&amp;", implode(',', $station['taxons']));
98
		$station['taxons'] = str_replace("&", "&amp;", implode(', ', $station['taxons']));
-
 
99
		$station['auteurs'] = str_replace("&", "&amp;", implode(', ', array_unique($station['auteurs'])));
97
	}
100
	}
98
	
101
	
99
	private function mettreEnPageStationMoissonnage(& $station) {
102
	private function mettreEnPageStationMoissonnage(& $station) {
100
		$station['nom_station'] = str_replace("&", "&amp;", trim($station['nom']));
103
		$station['nom_station'] = str_replace("&", "&amp;", trim($station['nom']));
101
		$station['departement'] = '';
104
		$station['departement'] = '';
102
		if ($this->estNonNul($station['code_insee'])) {
105
		if ($this->estNonNul($station['code_insee'])) {
103
			$station['departement'] = substr($station['code_insee'],0, 2);
106
			$station['departement'] = substr($station['code_insee'],0, 2);
104
			if (intval($station['departement']) > 95) {
107
			if (intval($station['departement']) > 95) {
105
				$station['departement'] = substr($station['code_insee'],0, 2);
108
				$station['departement'] = substr($station['code_insee'],0, 2);
106
			}
109
			}
107
		}
110
		}
108
		unset($station['nom']);
111
		unset($station['nom']);
109
		$station['taxons'] = str_replace("&", "&amp;", implode(',', $station['taxons']));
112
		$station['taxons'] = str_replace("&", "&amp;", implode(', ', $station['taxons']));
-
 
113
		$station['auteurs'] = str_replace("&", "&amp;", implode(', ', array_unique($station['auteurs'])));
110
	}
114
	}
111
	
115
	
112
	public function formaterException(Exception $erreur) {
116
	public function formaterException(Exception $erreur) {
113
		$nomFichierWfs = dirname(__FILE__).DS."squelettes".DS."Exception.tpl.xml";
117
		$nomFichierWfs = dirname(__FILE__).DS."squelettes".DS."Exception.tpl.xml";
114
		$item = array('message' => $erreur->getMessage());
118
		$item = array('message' => $erreur->getMessage());
115
		return SquelettePhp::analyser($nomFichierWfs, $item);
119
		return SquelettePhp::analyser($nomFichierWfs, $item);
116
	}
120
	}
117
	
121
	
118
}
122
}
119
 
123
 
120
?>
124
?>