Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3422 Rev 3843
1
<?php
1
<?php
2
// declare(encoding='UTF-8');
2
// declare(encoding='UTF-8');
3
/**
3
/**
4
 * Service recherche de zone par coordonnées et vice versa.
4
 * Service recherche de zone par coordonnées et vice versa.
5
 *
5
 *
6
 * @internal   Mininum PHP version : 5.2
6
 * @internal   Mininum PHP version : 5.2
7
 * @category   CEL
7
 * @category   CEL
8
 * @package    Services
8
 * @package    Services
9
 * @subpackage Cartes
9
 * @subpackage Cartes
10
 * @version    0.1
10
 * @version    0.1
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
11
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
17
 */
17
 */
18
class CoordSearch extends Cel {
18
class CoordSearch extends Cel {
19
	
19
 
20
	public function getRessource() {
20
	public function getRessource() {
21
		return $this->getElement(array());
21
		return $this->getElement(array());
22
	}
22
	}
23
	
23
 
24
	public function getElement($uid){
24
	public function getElement($uid){
25
		$header = '';
25
		$header = '';
26
		$retour = array();
26
		$retour = [];
27
 
27
 
28
		$params = $this->traiterParametres();
28
		$params = $this->traiterParametres();
29
		$recherche_zones_geo = new RechercheInfosZoneGeo($this->config);
29
		$recherche_zones_geo = new RechercheInfosZoneGeo($this->config);
-
 
30
 
30
 
31
		if( !empty($params)) {
-
 
32
			if ($this->estUneRequeteReverseGeocoding($params)) {
-
 
33
				$informations = $recherche_zones_geo->obtenirInfosPourCoordonnees([
-
 
34
					'latitude' => $params['lat'],
-
 
35
					'longitude' => $params['lon'],
-
 
36
				]);
-
 
37
			} elseif ($this->estUneRequeteGeocodingCodeInseeCommune($params)) {
-
 
38
	 			$informations = $recherche_zones_geo->obtenirInfosPourCodeInseeCommune($params['code']);
-
 
39
			} elseif ($this->estUneRequeteGeocoding($params)) {
-
 
40
				$informations = $recherche_zones_geo->obtenirInfosPourNom(
-
 
41
					$params['zone'],
-
 
42
					$params['pays'],
-
 
43
					$params['code']
-
 
44
				);
-
 
45
			} elseif ($this->estUneRequeteGeocodingGroupe($params)) {
-
 
46
				// renvoie des infos sur un groupes de zones géographiques, si celui-ci
-
 
47
				// est décrit dans la table cel_groupes_zones_geo
-
 
48
				$informations = $recherche_zones_geo->obtenirInfosPourGroupeZonesFrance($params['groupe_zones']);
-
 
49
			}
-
 
50
 
-
 
51
			$altitude = $recherche_zones_geo->obtenirAltitude($informations);
31
		if ($this->estUneRequeteReverseGeocoding($params)) {
-
 
32
 
-
 
33
			$coordonnees = array('latitude' => $params['lat'], 'longitude' => $params['lon']);
-
 
34
			$informations_zones = $recherche_zones_geo->obtenirInfosPourCoordonnees($coordonnees);
-
 
35
			$header = 'Content-Type: application/json; charset=UTF-8';
-
 
36
			$retour = json_encode($informations_zones);	
-
 
37
		}  elseif ($this->estUneRequeteGeocodingCodeInseeCommune($params)) {
-
 
38
 			$informations_coord = $recherche_zones_geo->obtenirInfosPourCodeInseeCommune($params['code']);
-
 
39
			$header = 'Content-Type: application/json; charset=UTF-8';
-
 
40
			$retour = json_encode($informations_coord);
-
 
41
		} elseif ($this->estUneRequeteGeocoding($params)) {	
-
 
42
			$informations_coord = $recherche_zones_geo->obtenirInfosPourNom($params['zone'], $params['pays'], $params['code']);
-
 
43
			$header = 'Content-Type: application/json; charset=UTF-8';
-
 
44
			$retour = json_encode($informations_coord);
-
 
45
			
-
 
46
		} elseif ($this->estUneRequeteGeocodingGroupe($params)) {
-
 
47
			// renvoie des infos sur un groupes de zones géographiques, si celui-ci
-
 
48
			// est décrit dans la table cel_groupes_zones_geo
52
			$informations = array_merge($informations, $altitude);
49
			$informations_groupe = $recherche_zones_geo->obtenirInfosPourGroupeZonesFrance($params['groupe_zones']);
53
 
50
			$header = 'Content-Type: application/json; charset=UTF-8';
54
			$header = 'Content-Type: application/json; charset=UTF-8';
51
			$retour = json_encode($informations_groupe);
55
			$retour = json_encode($informations);
52
			
56
 
53
		} else {
57
		} else {
54
			$header = 'HTTP/1.0 400 Bad Request';
58
			$header = 'HTTP/1.0 400 Bad Request';
55
			$retour = 'zone ou Coordonnées ou code INSEE non spécifié.e';
59
			$retour = 'zone ou Coordonnées ou code INSEE non spécifié.e';
56
		}
60
		}
57
		
61
 
58
		header($header);
62
		header($header);
59
		echo $retour;
63
		echo $retour;
60
	}
64
	}
61
 
65
 
62
	protected function traiterParametres() {
66
	protected function traiterParametres() {
63
		$params = array('lon', 'lat', 'zone', 'groupe_zones', 'code', 'pays');
67
		$params = array('lon', 'lat', 'zone', 'groupe_zones', 'code', 'pays');
64
		$parametresTraites = array();
68
		$parametresTraites = array();
65
 
69
 
66
		foreach($params as $p) {
70
		foreach($params as $p) {
67
			$val = ''; // @TODO plutôt null ?
71
			$val = ''; // @TODO plutôt null ?
68
			if (!empty($_REQUEST[$p])) {
72
			if (!empty($_REQUEST[$p])) {
69
				$val = $_REQUEST[$p];
73
				$val = $_REQUEST[$p];
70
			}
74
			}
71
			$parametresTraites[$p] = $val;
75
			$parametresTraites[$p] = $val;
72
		}
76
		}
73
 
77
 
74
		return $parametresTraites;
78
		return $parametresTraites;
75
	}
79
	}
76
	
80
 
77
	protected function estUneRequeteReverseGeocoding($params) {
81
	protected function estUneRequeteReverseGeocoding($params) {
78
		return ($params['lat'] != '' && $params['lon'] != '');
82
		return ($params['lat'] != '' && $params['lon'] != '');
79
	}
83
	}
80
 
84
 
81
	protected function estUneRequeteGeocoding($params) {
85
	protected function estUneRequeteGeocoding($params) {
82
		return ($params['zone'] != '');
86
		return ($params['zone'] != '');
83
	}
87
	}
84
 
88
 
85
	protected function estUneRequeteGeocodingCodeInseeCommune($params) {
89
	protected function estUneRequeteGeocodingCodeInseeCommune($params) {
86
		return ($params['code'] != '' && 5 === strlen($params['code']));
90
		return ($params['code'] != '' && 5 === strlen($params['code']));
87
	}
91
	}
88
 
92
 
89
	protected function estUneRequeteGeocodingGroupe($params) {
93
	protected function estUneRequeteGeocodingGroupe($params) {
90
		return ($params['groupe_zones'] != '');
94
		return ($params['groupe_zones'] != '');
91
	}
95
	}
92
}
96
}