add xml response, add doc and refactor
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
namespace database;
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
include_once PATH_DATABASE . "/SqlManager.php";
|
||||
include_once PATH_UTILITTY . "/StringManager.php";
|
||||
require_once PATH_DATABASE . "/SqlManager.php";
|
||||
|
||||
/**
|
||||
* Description of SpsSqlManager
|
||||
@@ -27,65 +28,145 @@ class SpsSqlManager extends SQLManager {
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fieldname of the placeID
|
||||
* @var string
|
||||
*/
|
||||
public static $placeId = "id";
|
||||
|
||||
/**
|
||||
* Fieldname of the parendId
|
||||
* @var string
|
||||
*/
|
||||
public static $parentId = "parent";
|
||||
|
||||
/**
|
||||
* String for the select part of the query
|
||||
* @var string
|
||||
*/
|
||||
private $selectTerm = "SELECT DISTINCT id, parent FROM sps WHERE ";
|
||||
private $andTerm = " and ";
|
||||
|
||||
/**
|
||||
* String for the alias part of the query
|
||||
* @var string
|
||||
*/
|
||||
private $aliasTerm = "alias = ";
|
||||
|
||||
/**
|
||||
* String for the did part of the query
|
||||
* @var string
|
||||
*/
|
||||
private $domainTerm = "did = ";
|
||||
private $domainNameTerm = "name = ";
|
||||
private $quoteTerm = "\"";
|
||||
|
||||
/**
|
||||
* String for the dNamet part of the query
|
||||
* @var string
|
||||
*/
|
||||
private $domainNameTerm = "dName = ";
|
||||
|
||||
/**
|
||||
* first part of intersect-function
|
||||
* @var string
|
||||
*/
|
||||
private $interSectTermStart = "Intersects(";
|
||||
|
||||
/**
|
||||
* last part of intersect-function
|
||||
* @var string
|
||||
*/
|
||||
private $interSectTermEnd = "),plan)";
|
||||
|
||||
/**
|
||||
* first part of GeomFromText('Polygon-function
|
||||
* @var string
|
||||
*/
|
||||
private $polyStartStr = "GeomFromText('Polygon((";
|
||||
|
||||
/**
|
||||
* last part of GeomFromText('Polygon-function
|
||||
* @var string
|
||||
*/
|
||||
private $polyEndStr = "))'";
|
||||
|
||||
/**
|
||||
* Methods send an query for the sps-service
|
||||
* maximium length of the value-string for an aliasname
|
||||
* @var int
|
||||
*/
|
||||
private $aliasMaxLenght = 32;
|
||||
|
||||
/**
|
||||
* maximium length of the value-string for a domainname
|
||||
* @var int
|
||||
*/
|
||||
private $domainMaxLenght = 32;
|
||||
|
||||
/**
|
||||
* Methods send an query for the sps-service depends of alias
|
||||
* @param array $queryArgs
|
||||
* @return array [num][assoc]
|
||||
*/
|
||||
public function sendSpsAliasQuery($queryArgs = array()) {
|
||||
|
||||
if (array_key_exists("alias", $queryArgs)) {
|
||||
$alias = $queryArgs["alias"];
|
||||
// check arguments of the query
|
||||
if (array_key_exists(\api\SpsApi::$keyAlias, $queryArgs)) {
|
||||
$alias = $queryArgs[\api\SpsApi::$keyAlias];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
$domain = null;
|
||||
if (array_key_exists("domain", $queryArgs)) {
|
||||
$domain = $queryArgs["domain"];
|
||||
if (array_key_exists(\api\SpsApi::$keyDomain, $queryArgs)) {
|
||||
$domain = $queryArgs[\api\SpsApi::$keyDomain];
|
||||
}
|
||||
|
||||
// build query string
|
||||
$query = $this->selectTerm;
|
||||
|
||||
if ($this->validAliasString($alias)) {
|
||||
$query .= $this->aliasTerm . $this->quoteTerm . $alias . $this->quoteTerm . $this->addDomainTerm($domain);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// send query
|
||||
return $this->query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods send an query for the sps-service depends of coordinates
|
||||
* @param array $queryArgs
|
||||
* @return array [num][assoc]
|
||||
*/
|
||||
public function sendSpsCoordinateQuery($queryArgs = array()) {
|
||||
if (array_key_exists("poly", $queryArgs)) {
|
||||
$poly = $queryArgs["poly"];
|
||||
|
||||
// check arguments of the query
|
||||
if (array_key_exists(\api\SpsApi::$keyPoly, $queryArgs)) {
|
||||
$poly = $queryArgs[\api\SpsApi::$keyPoly];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
$domain = null;
|
||||
if (array_key_exists("domain", $queryArgs)) {
|
||||
$domain = $queryArgs["domain"];
|
||||
if (array_key_exists(\api\SpsApi::$keyDomain, $queryArgs)) {
|
||||
$domain = $queryArgs[\api\SpsApi::$keyDomain];
|
||||
}
|
||||
|
||||
// build query string
|
||||
if ($this->validPolyString($poly)) {
|
||||
$query = $this->selectTerm . $this->interSectTermStart . $poly . $this->interSectTermEnd . $this->addDomainTerm($domain);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// send query
|
||||
return $this->query($query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method create the correct domain part depends of $domain. If it is a number => did
|
||||
* otherwise => dName
|
||||
* @param string $domain
|
||||
* @return string
|
||||
*/
|
||||
private function addDomainTerm($domain) {
|
||||
$result = null;
|
||||
if ($domain != null && $this->validDomainString($domain)) {
|
||||
@@ -98,30 +179,51 @@ class SpsSqlManager extends SQLManager {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method check if the input value for the alias is valid
|
||||
* @param string $alias
|
||||
* @return boolean
|
||||
*/
|
||||
private function validAliasString($alias) {
|
||||
if ($this->validString($alias) && ctype_alnum($alias)) {
|
||||
if ($this->validString($alias) && ctype_alnum($alias) && strlen($alias) <= $this->aliasMaxLenght) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method check if the input value for the alias is valid
|
||||
* @param string $domain
|
||||
* @return boolean
|
||||
*/
|
||||
private function validDomainString($domain) {
|
||||
if ($this->validString($domain) && ctype_alnum($domain)) {
|
||||
if ($this->validString($domain) && ctype_alnum($domain) && strlen($domain) <= $this->domainMaxLenght) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method check if the input value for the polygon is valid
|
||||
* @param string $poly
|
||||
* @return boolean
|
||||
*/
|
||||
private function validPolyString($poly) {
|
||||
if ($this->validString($poly) && $this->startsWith($poly, $this->polyStartStr) && $this->endsWith($poly, $this->polyEndStr)) {
|
||||
if ($this->validString($poly) && \utiliy\StringManager::startsWith($poly, $this->polyStartStr) && \utiliy\StringManager::endsWith($poly, $this->polyEndStr)) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method check if the ntring is a did
|
||||
* @param string $string
|
||||
* @return boolean
|
||||
*/
|
||||
private function isDid($string) {
|
||||
return ctype_digit($string);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -42,11 +42,22 @@ abstract class SqlManager {
|
||||
*/
|
||||
private $link;
|
||||
|
||||
/**
|
||||
* String for a and operrator
|
||||
* @var string
|
||||
*/
|
||||
protected $andTerm = " and ";
|
||||
|
||||
/**
|
||||
* String for quotes in a query
|
||||
* @var string
|
||||
*/
|
||||
protected $quoteTerm = "\"";
|
||||
|
||||
/**
|
||||
* Default-Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->serverAddress = \config\DBConfig::$sqlServer;
|
||||
$this->dbName = \config\DBConfig::$sqlDBName;
|
||||
$this->userName = \config\DBConfig::$sqlDBUser;
|
||||
@@ -108,6 +119,11 @@ abstract class SqlManager {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method if the string is not a empty String (not only spaces and controlls)
|
||||
* @param string $string
|
||||
* @return boolean
|
||||
*/
|
||||
protected function validString($string) {
|
||||
if (!ctype_space($string) && !ctype_cntrl($string)) {
|
||||
return TRUE;
|
||||
@@ -115,14 +131,6 @@ abstract class SqlManager {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
protected function startsWith($haystack, $needle) {
|
||||
return !strncmp($haystack, $needle, strlen($needle));
|
||||
}
|
||||
|
||||
protected function endsWith($haystack, $needle) {
|
||||
return (substr($haystack, -strlen($needle)) === $needle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user