78 lines
2.0 KiB
PHP
78 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace api;
|
|
|
|
include_once "../../global.inc.php";
|
|
include_once PATH_DATABASE . "/SpsSqlManager.php";
|
|
require_once PATH_API . "/Api.php";
|
|
|
|
/**
|
|
* This class provides some spezial SpsAPI methods
|
|
* @author stubbfel
|
|
* @since 20.06.2013
|
|
*/
|
|
class SpsApi extends Api {
|
|
|
|
/**
|
|
* Default-Constructor
|
|
*/
|
|
public function __construct() {
|
|
$this->sqlManager = new \database\SpsSqlManager();
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Default-DeConstructor
|
|
*/
|
|
public function __destruct() {
|
|
parent::__destruct();
|
|
}
|
|
|
|
/**
|
|
* Method start a sps-query(alias)
|
|
* @param array $queryArgs
|
|
* @return array[num] [assoc]
|
|
*/
|
|
public function sendSpsAliasQuery($queryArgs = array()) {
|
|
|
|
return $this->sqlManager->sendSpsAliasQuery($queryArgs);
|
|
}
|
|
|
|
private $range = 1;
|
|
|
|
public function sendSpsCoordinateQuery($queryArgs = array()) {
|
|
if (!array_key_exists("longitude", $queryArgs) || !array_key_exists("latitude", $queryArgs)) {
|
|
return null;
|
|
}
|
|
$latitude = $queryArgs["latitude"];
|
|
$longitude = $queryArgs["longitude"];
|
|
|
|
if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) {
|
|
return null;
|
|
}
|
|
|
|
$queryArgs["poly"] = $this->createPolygon($latitude, $longitude, $this->range);
|
|
return $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
|
|
}
|
|
|
|
private function validLongitude($string) {
|
|
|
|
return ctype_digit(str_replace(".", "", $string));
|
|
}
|
|
|
|
private function validLatitude($string) {
|
|
return ctype_digit(str_replace(".", "", $string));
|
|
}
|
|
|
|
private function createPolygon($latitude, $longitude, $range) {
|
|
$minLat = $latitude - $range;
|
|
$minLong = $longitude - $range;
|
|
$maxLat = $latitude + $range;
|
|
$maxLong = $longitude + $range;
|
|
return "GeomFromText('Polygon(($minLat $minLong,$minLat $maxLong,$maxLat $maxLong,$maxLat $minLong,$minLat $minLong))'";
|
|
}
|
|
|
|
}
|
|
|
|
?>
|