| 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 {
|
| 3843 |
idir |
19 |
|
| 2564 |
aurelien |
20 |
public function getRessource() {
|
|
|
21 |
return $this->getElement(array());
|
|
|
22 |
}
|
| 3843 |
idir |
23 |
|
| 2458 |
jpm |
24 |
public function getElement($uid){
|
| 766 |
aurelien |
25 |
$header = '';
|
| 3843 |
idir |
26 |
$retour = [];
|
| 416 |
aurelien |
27 |
|
| 2564 |
aurelien |
28 |
$params = $this->traiterParametres();
|
| 2557 |
aurelien |
29 |
$recherche_zones_geo = new RechercheInfosZoneGeo($this->config);
|
| 2143 |
jpm |
30 |
|
| 3843 |
idir |
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 |
}
|
| 2143 |
jpm |
50 |
|
| 3843 |
idir |
51 |
$altitude = $recherche_zones_geo->obtenirAltitude($informations);
|
|
|
52 |
$informations = array_merge($informations, $altitude);
|
|
|
53 |
|
| 766 |
aurelien |
54 |
$header = 'Content-Type: application/json; charset=UTF-8';
|
| 3843 |
idir |
55 |
$retour = json_encode($informations);
|
|
|
56 |
|
| 2458 |
jpm |
57 |
} else {
|
|
|
58 |
$header = 'HTTP/1.0 400 Bad Request';
|
| 3422 |
killian |
59 |
$retour = 'zone ou Coordonnées ou code INSEE non spécifié.e';
|
| 2458 |
jpm |
60 |
}
|
| 3843 |
idir |
61 |
|
| 766 |
aurelien |
62 |
header($header);
|
|
|
63 |
echo $retour;
|
|
|
64 |
}
|
| 2143 |
jpm |
65 |
|
| 2564 |
aurelien |
66 |
protected function traiterParametres() {
|
| 2914 |
mathias |
67 |
$params = array('lon', 'lat', 'zone', 'groupe_zones', 'code', 'pays');
|
|
|
68 |
$parametresTraites = array();
|
|
|
69 |
|
|
|
70 |
foreach($params as $p) {
|
|
|
71 |
$val = ''; // @TODO plutôt null ?
|
|
|
72 |
if (!empty($_REQUEST[$p])) {
|
|
|
73 |
$val = $_REQUEST[$p];
|
|
|
74 |
}
|
|
|
75 |
$parametresTraites[$p] = $val;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
return $parametresTraites;
|
| 766 |
aurelien |
79 |
}
|
| 3843 |
idir |
80 |
|
| 2914 |
mathias |
81 |
protected function estUneRequeteReverseGeocoding($params) {
|
| 2564 |
aurelien |
82 |
return ($params['lat'] != '' && $params['lon'] != '');
|
| 766 |
aurelien |
83 |
}
|
| 2143 |
jpm |
84 |
|
| 2914 |
mathias |
85 |
protected function estUneRequeteGeocoding($params) {
|
| 2564 |
aurelien |
86 |
return ($params['zone'] != '');
|
| 766 |
aurelien |
87 |
}
|
| 2914 |
mathias |
88 |
|
| 3422 |
killian |
89 |
protected function estUneRequeteGeocodingCodeInseeCommune($params) {
|
|
|
90 |
return ($params['code'] != '' && 5 === strlen($params['code']));
|
|
|
91 |
}
|
|
|
92 |
|
| 2914 |
mathias |
93 |
protected function estUneRequeteGeocodingGroupe($params) {
|
|
|
94 |
return ($params['groupe_zones'] != '');
|
|
|
95 |
}
|
| 3422 |
killian |
96 |
}
|