| 416 |
aurelien |
1 |
<?php
|
| 2458 |
jpm |
2 |
// declare(encoding='UTF-8');
|
| 766 |
aurelien |
3 |
/**
|
| 2564 |
aurelien |
4 |
* Service recherche de zone par coordonnées et vice versa.
|
| 766 |
aurelien |
5 |
*
|
| 2458 |
jpm |
6 |
* @internal Mininum PHP version : 5.2
|
|
|
7 |
* @category CEL
|
|
|
8 |
* @package Services
|
| 2462 |
jpm |
9 |
* @subpackage Cartes
|
| 2458 |
jpm |
10 |
* @version 0.1
|
|
|
11 |
* @author Mathias CHOUET <mathias@tela-botanica.org>
|
|
|
12 |
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
13 |
* @author Aurelien PERONNET <aurelien@tela-botanica.org>
|
|
|
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>
|
|
|
16 |
* @copyright 1999-2014 Tela Botanica <accueil@tela-botanica.org>
|
| 766 |
aurelien |
17 |
*/
|
| 772 |
aurelien |
18 |
class CoordSearch extends Cel {
|
| 2557 |
aurelien |
19 |
|
| 2564 |
aurelien |
20 |
public function getRessource() {
|
|
|
21 |
return $this->getElement(array());
|
|
|
22 |
}
|
|
|
23 |
|
| 2458 |
jpm |
24 |
public function getElement($uid){
|
| 766 |
aurelien |
25 |
$header = '';
|
|
|
26 |
$retour = array();
|
| 416 |
aurelien |
27 |
|
| 2564 |
aurelien |
28 |
$params = $this->traiterParametres();
|
| 2557 |
aurelien |
29 |
$recherche_zones_geo = new RechercheInfosZoneGeo($this->config);
|
| 2143 |
jpm |
30 |
|
| 766 |
aurelien |
31 |
if ($this->estUneRequeteReverseGeocoding($params)) {
|
| 2143 |
jpm |
32 |
|
| 2557 |
aurelien |
33 |
$coordonnees = array('latitude' => $params['lat'], 'longitude' => $params['lon']);
|
| 2564 |
aurelien |
34 |
$informations_zones = $recherche_zones_geo->obtenirInfosPourCoordonnees($coordonnees);
|
| 766 |
aurelien |
35 |
$header = 'Content-Type: application/json; charset=UTF-8';
|
| 2564 |
aurelien |
36 |
$retour = json_encode($informations_zones);
|
| 2557 |
aurelien |
37 |
|
|
|
38 |
} elseif ($this->estUneRequeteGeocoding($params)) {
|
| 2914 |
mathias |
39 |
$informations_coord = $recherche_zones_geo->obtenirInfosPourNom($params['zone'], $params['pays'], $params['code']);
|
| 766 |
aurelien |
40 |
$header = 'Content-Type: application/json; charset=UTF-8';
|
|
|
41 |
$retour = json_encode($informations_coord);
|
| 2557 |
aurelien |
42 |
|
| 2914 |
mathias |
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);
|
|
|
49 |
|
| 2458 |
jpm |
50 |
} else {
|
|
|
51 |
$header = 'HTTP/1.0 400 Bad Request';
|
| 2564 |
aurelien |
52 |
$retour = 'zone ou Coordonnées non spécifiées';
|
| 2458 |
jpm |
53 |
}
|
| 2557 |
aurelien |
54 |
|
| 766 |
aurelien |
55 |
header($header);
|
|
|
56 |
echo $retour;
|
|
|
57 |
}
|
| 2143 |
jpm |
58 |
|
| 2564 |
aurelien |
59 |
protected function traiterParametres() {
|
| 2914 |
mathias |
60 |
$params = array('lon', 'lat', 'zone', 'groupe_zones', 'code', 'pays');
|
|
|
61 |
$parametresTraites = array();
|
|
|
62 |
|
|
|
63 |
foreach($params as $p) {
|
|
|
64 |
$val = ''; // @TODO plutôt null ?
|
|
|
65 |
if (!empty($_REQUEST[$p])) {
|
|
|
66 |
$val = $_REQUEST[$p];
|
|
|
67 |
}
|
|
|
68 |
$parametresTraites[$p] = $val;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
return $parametresTraites;
|
| 766 |
aurelien |
72 |
}
|
| 2564 |
aurelien |
73 |
|
| 2914 |
mathias |
74 |
protected function estUneRequeteReverseGeocoding($params) {
|
| 2564 |
aurelien |
75 |
return ($params['lat'] != '' && $params['lon'] != '');
|
| 766 |
aurelien |
76 |
}
|
| 2143 |
jpm |
77 |
|
| 2914 |
mathias |
78 |
protected function estUneRequeteGeocoding($params) {
|
| 2564 |
aurelien |
79 |
return ($params['zone'] != '');
|
| 766 |
aurelien |
80 |
}
|
| 2914 |
mathias |
81 |
|
|
|
82 |
protected function estUneRequeteGeocodingGroupe($params) {
|
|
|
83 |
return ($params['groupe_zones'] != '');
|
|
|
84 |
}
|
| 2458 |
jpm |
85 |
}
|