Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 2564 Rev 2914
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 = array();
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 ($this->estUneRequeteReverseGeocoding($params)) {
31
		if ($this->estUneRequeteReverseGeocoding($params)) {
32
 
32
 
33
			$coordonnees = array('latitude' => $params['lat'], 'longitude' => $params['lon']);
33
			$coordonnees = array('latitude' => $params['lat'], 'longitude' => $params['lon']);
34
			$informations_zones = $recherche_zones_geo->obtenirInfosPourCoordonnees($coordonnees);
34
			$informations_zones = $recherche_zones_geo->obtenirInfosPourCoordonnees($coordonnees);
35
			$header = 'Content-Type: application/json; charset=UTF-8';
35
			$header = 'Content-Type: application/json; charset=UTF-8';
36
			$retour = json_encode($informations_zones);	
36
			$retour = json_encode($informations_zones);	
37
				
37
				
38
		} elseif ($this->estUneRequeteGeocoding($params)) {	
38
		} elseif ($this->estUneRequeteGeocoding($params)) {	
39
				
-
 
40
			$informations_coord = $recherche_zones_geo->obtenirInfosPourNoms($params['zone'], $params['pays'], $params['code']);
39
			$informations_coord = $recherche_zones_geo->obtenirInfosPourNom($params['zone'], $params['pays'], $params['code']);
41
			$header = 'Content-Type: application/json; charset=UTF-8';
40
			$header = 'Content-Type: application/json; charset=UTF-8';
42
			$retour = json_encode($informations_coord);
41
			$retour = json_encode($informations_coord);
-
 
42
			
-
 
43
		} elseif ($this->estUneRequeteGeocodingGroupe($params)) {
-
 
44
			// renvoie des infos sur un groupes de zones géographiques, si celui-ci
-
 
45
			// est décrit dans la table cel_groupes_zones_geo
-
 
46
			$informations_groupe = $recherche_zones_geo->obtenirInfosPourGroupeZonesFrance($params['groupe_zones']);
-
 
47
			$header = 'Content-Type: application/json; charset=UTF-8';
-
 
48
			$retour = json_encode($informations_groupe);
43
			
49
			
44
		} else {
50
		} else {
45
			$header = 'HTTP/1.0 400 Bad Request';
51
			$header = 'HTTP/1.0 400 Bad Request';
46
			$retour = 'zone ou Coordonnées non spécifiées';
52
			$retour = 'zone ou Coordonnées non spécifiées';
47
		}
53
		}
48
		
54
		
49
		header($header);
55
		header($header);
50
		echo $retour;
56
		echo $retour;
51
	}
57
	}
52
 
58
 
53
	protected function traiterParametres() {
59
	protected function traiterParametres() {
54
		$lat = !empty($_GET['lat']) ? $_GET['lat'] : '';
60
		$params = array('lon', 'lat', 'zone', 'groupe_zones', 'code', 'pays');
55
		$lon = !empty($_GET['lon']) ? $_GET['lon'] : '';
61
		$parametresTraites = array();
-
 
62
 
56
		$zone = !empty($_GET['zone']) ? $_GET['zone'] : '';
63
		foreach($params as $p) {
57
		$code = !empty($_GET['code']) ? $_GET['code'] : '';
64
			$val = ''; // @TODO plutôt null ?
58
		$pays = !empty($_GET['pays']) ? $_GET['pays'] : '';
65
			if (!empty($_REQUEST[$p])) {
59
		return array(
-
 
60
			'lat' => $lat,
66
				$val = $_REQUEST[$p];
61
			'lon' => $lon,
67
			}
62
			'zone' => $zone,
68
			$parametresTraites[$p] = $val;
63
			'code' => $code,
69
		}
-
 
70
 
64
			'pays' => $pays);
71
		return $parametresTraites;
65
	}
72
	}
66
	
73
	
67
	private function estUneRequeteReverseGeocoding($params) {
74
	protected function estUneRequeteReverseGeocoding($params) {
68
		return ($params['lat'] != '' && $params['lon'] != '');
75
		return ($params['lat'] != '' && $params['lon'] != '');
69
	}
76
	}
70
 
77
 
71
	private function estUneRequeteGeocoding($params) {
78
	protected function estUneRequeteGeocoding($params) {
72
		return ($params['zone'] != '');
79
		return ($params['zone'] != '');
-
 
80
	}
-
 
81
 
-
 
82
	protected function estUneRequeteGeocodingGroupe($params) {
-
 
83
		return ($params['groupe_zones'] != '');
73
	}
84
	}
74
}
85
}