Subversion Repositories eFlore/Applications.cel

Rev

Rev 2564 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
// declare(encoding='UTF-8');
/**
 * Service recherche de zone par coordonnées et vice versa.
 *
 * @internal   Mininum PHP version : 5.2
 * @category   CEL
 * @package    Services
 * @subpackage Cartes
 * @version    0.1
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
 */
class CoordSearch extends Cel {
        
        public function getRessource() {
                return $this->getElement(array());
        }
        
        public function getElement($uid){
                $header = '';
                $retour = array();

                $params = $this->traiterParametres();
                $recherche_zones_geo = new RechercheInfosZoneGeo($this->config);

                if ($this->estUneRequeteReverseGeocoding($params)) {

                        $coordonnees = array('latitude' => $params['lat'], 'longitude' => $params['lon']);
                        $informations_zones = $recherche_zones_geo->obtenirInfosPourCoordonnees($coordonnees);
                        $header = 'Content-Type: application/json; charset=UTF-8';
                        $retour = json_encode($informations_zones);     
                                
                } elseif ($this->estUneRequeteGeocoding($params)) {     
                                
                        $informations_coord = $recherche_zones_geo->obtenirInfosPourNoms($params['zone'], $params['pays'], $params['code']);
                        $header = 'Content-Type: application/json; charset=UTF-8';
                        $retour = json_encode($informations_coord);
                        
                } else {
                        $header = 'HTTP/1.0 400 Bad Request';
                        $retour = 'zone ou Coordonnées non spécifiées';
                }
                
                header($header);
                echo $retour;
        }

        protected function traiterParametres() {
                $lat = !empty($_GET['lat']) ? $_GET['lat'] : '';
                $lon = !empty($_GET['lon']) ? $_GET['lon'] : '';
                $zone = !empty($_GET['zone']) ? $_GET['zone'] : '';
                $code = !empty($_GET['code']) ? $_GET['code'] : '';
                $pays = !empty($_GET['pays']) ? $_GET['pays'] : '';
                return array(
                        'lat' => $lat,
                        'lon' => $lon,
                        'zone' => $zone,
                        'code' => $code,
                        'pays' => $pays);
        }
        
        private function estUneRequeteReverseGeocoding($params) {
                return ($params['lat'] != '' && $params['lon'] != '');
        }

        private function estUneRequeteGeocoding($params) {
                return ($params['zone'] != '');
        }
}