add xml response, add doc and refactor

This commit is contained in:
stubbfel
2013-06-25 13:32:00 +02:00
parent 8fb78ca082
commit 858758ccc9
8 changed files with 374 additions and 55 deletions

View File

@@ -4,6 +4,7 @@ namespace api;
include_once "../../global.inc.php";
include_once PATH_DATABASE . "/SpsSqlManager.php";
include_once PATH_UTILITTY . "/XmlManager.php";
require_once PATH_API . "/Api.php";
/**
@@ -13,12 +14,85 @@ require_once PATH_API . "/Api.php";
*/
class SpsApi extends Api {
/**
* Keyword for alias arguments
* @var string
*/
public static $keyAlias = "alias";
/**
* Keyword for domain arguments
* @var string
*/
public static $keyDomain = "domain";
/**
* Keyword for polygon arguments
* @var string
*/
public static $keyPoly = "poly";
/**
* Keyword for longitude arguments
* @var string
*/
public static $keyLong = "longitude";
/**
* Keyword for latitude arguments
* @var string
*/
public static $keyLat = "latitude";
/*
* Varible for the range of the searchpolygon
* @var float
*/
private $range = 1;
/*
* Varible for the fist chars of the string for a Polygon
* @var string
*/
private $polyStartStr = "GeomFromText('Polygon((";
/*
* Varible for the last chars of the string for a Polygon
* @var string
*/
private $polyEndStr = "))'";
/**
* maximum value of latitude
* @var float
*/
private $maxLat = 180;
/**
* minimum value of latitude
* @var float
*/
private $minLat = -180;
/**
* maximum value of longitude
* @var float
*/
private $maxLong = 180;
/**
* minimum value of longitude
* @var float
*/
private $minLong = -180;
/**
* Default-Constructor
*/
public function __construct() {
$this->sqlManager = new \database\SpsSqlManager();
parent::__construct();
$this->contentType("Content-type: application/xml;charset=utf-8");
}
/**
@@ -31,45 +105,79 @@ class SpsApi extends Api {
/**
* Method start a sps-query(alias)
* @param array $queryArgs
* @return array[num] [assoc]
* @return querry result as xml
*/
public function sendSpsAliasQuery($queryArgs = array()) {
return $this->sqlManager->sendSpsAliasQuery($queryArgs);
$result = $this->sqlManager->sendSpsAliasQuery($queryArgs);
return \utiliy\XmlManager::arrayToSpsXml($result);
}
private $range = 1;
/**
* Method start a sps-query(Coordinates)
* @param array $queryArgs
* @return querry result as xml
*/
public function sendSpsCoordinateQuery($queryArgs = array()) {
if (!array_key_exists("longitude", $queryArgs) || !array_key_exists("latitude", $queryArgs)) {
if (!array_key_exists(SpsApi::$keyLong, $queryArgs) || !array_key_exists(SpsApi::$keyLat, $queryArgs)) {
return null;
}
$latitude = $queryArgs["latitude"];
$longitude = $queryArgs["longitude"];
$latitude = $queryArgs[SpsApi::$keyLat];
$longitude = $queryArgs[SpsApi::$keyLong];
if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) {
return null;
}
$queryArgs["poly"] = $this->createPolygon($latitude, $longitude, $this->range);
return $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
$queryArgs[SpsApi::$keyPoly] = $this->createPolygon($latitude, $longitude, $this->range);
$result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
return \utiliy\XmlManager::arrayToSpsXml($result);
}
/**
* Method check if a string is a valid Longitude
* @param string $string
* @return bool
*/
private function validLongitude($string) {
return ctype_digit(str_replace(".", "", $string));
$digitLessPoint = str_replace(".", "", $string);
$digit = str_replace("-", "", $digitLessPoint);
if (ctype_digit($digit)) {
if ($string <= $this->maxLong && $string >= $this->minLong) {
return TRUE;
}
};
return FALSE;
}
/**
* Method check if a string is a valid Latitude
* @param strinf $string
* @return bool
*/
private function validLatitude($string) {
return ctype_digit(str_replace(".", "", $string));
$digitLessPoint = str_replace(".", "", $string);
$digit = str_replace("-", "", $digitLessPoint);
if (ctype_digit($digit)) {
if ($string <= $this->maxLat && $string >= $this->minLat) {
return TRUE;
}
};
return FALSE;
}
/**
* Method create a Polygon
* @param float $latitude
* @param float $longitude
* @param float $range
* @return 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))'";
return $this->polyStartStr . "$minLat $minLong,$minLat $maxLong,$maxLat $maxLong,$maxLat $minLong,$minLat $minLong" . $this->polyEndStr;
}
}