128 lines
3.4 KiB
PHP
128 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace database;
|
|
|
|
include_once "../../global.inc.php";
|
|
include_once PATH_DATABASE . "/SqlManager.php";
|
|
|
|
/**
|
|
* Description of SpsSqlManager
|
|
*
|
|
* @author stubbfel
|
|
* @since 20.06.2013
|
|
*/
|
|
class SpsSqlManager extends SQLManager {
|
|
|
|
/**
|
|
* Default-Constructor
|
|
*/
|
|
public function __construct() {
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Default-DEConstructor
|
|
*/
|
|
public function __destruct() {
|
|
parent::__destruct();
|
|
}
|
|
|
|
private $selectTerm = "SELECT DISTINCT id, parent FROM sps WHERE ";
|
|
private $andTerm = " and ";
|
|
private $aliasTerm = "alias = ";
|
|
private $domainTerm = "did = ";
|
|
private $domainNameTerm = "name = ";
|
|
private $quoteTerm = "\"";
|
|
private $interSectTermStart = "Intersects(";
|
|
private $interSectTermEnd = "),plan)";
|
|
private $polyStartStr = "GeomFromText('Polygon((";
|
|
private $polyEndStr = "))'";
|
|
|
|
/**
|
|
* Methods send an query for the sps-service
|
|
* @param array $queryArgs
|
|
* @return array [num][assoc]
|
|
*/
|
|
public function sendSpsAliasQuery($queryArgs = array()) {
|
|
|
|
if (array_key_exists("alias", $queryArgs)) {
|
|
$alias = $queryArgs["alias"];
|
|
} else {
|
|
return null;
|
|
}
|
|
|
|
$domain = null;
|
|
if (array_key_exists("domain", $queryArgs)) {
|
|
$domain = $queryArgs["domain"];
|
|
}
|
|
|
|
$query = $this->selectTerm;
|
|
|
|
if ($this->validAliasString($alias)) {
|
|
$query .= $this->aliasTerm . $this->quoteTerm . $alias . $this->quoteTerm . $this->addDomainTerm($domain);
|
|
} else {
|
|
return null;
|
|
}
|
|
return $this->query($query);
|
|
}
|
|
|
|
public function sendSpsCoordinateQuery($queryArgs = array()) {
|
|
if (array_key_exists("poly", $queryArgs)) {
|
|
$poly = $queryArgs["poly"];
|
|
} else {
|
|
return null;
|
|
}
|
|
|
|
$domain = null;
|
|
if (array_key_exists("domain", $queryArgs)) {
|
|
$domain = $queryArgs["domain"];
|
|
}
|
|
|
|
if ($this->validPolyString($poly)) {
|
|
$query = $this->selectTerm . $this->interSectTermStart . $poly . $this->interSectTermEnd . $this->addDomainTerm($domain);
|
|
} else {
|
|
return null;
|
|
}
|
|
return $this->query($query);
|
|
}
|
|
|
|
private function addDomainTerm($domain) {
|
|
$result = null;
|
|
if ($domain != null && $this->validDomainString($domain)) {
|
|
if ($this->isDid($domain)) {
|
|
$result .= $this->andTerm . $this->domainTerm . $this->quoteTerm . $domain . $this->quoteTerm;
|
|
} else {
|
|
$result .= $this->andTerm . $this->domainNameTerm . $this->quoteTerm . $domain . $this->quoteTerm;
|
|
}
|
|
}
|
|
return $result;
|
|
}
|
|
|
|
private function validAliasString($alias) {
|
|
if ($this->validString($alias) && ctype_alnum($alias)) {
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
private function validDomainString($domain) {
|
|
if ($this->validString($domain) && ctype_alnum($domain)) {
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
private function validPolyString($poly) {
|
|
if ($this->validString($poly) && $this->startsWith($poly, $this->polyStartStr) && $this->endsWith($poly, $this->polyEndStr)) {
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
private function isDid($string) {
|
|
return ctype_digit($string);
|
|
}
|
|
|
|
}
|
|
?>
|