add sps service

This commit is contained in:
stubbfel
2013-06-26 12:12:10 +02:00
parent 658987ba53
commit 1678b94dd5
10 changed files with 202 additions and 359 deletions

View File

@@ -12,7 +12,43 @@ require_once PATH_DATABASE . "/SqlManager.php";
* @author stubbfel
* @since 20.06.2013
*/
class SpsSqlManager extends SQLManager {
class PisSqlManager extends SQLManager {
/**
* Fieldname of the placeID
* @var string
*/
public static $placeId = "pid";
/**
* Fieldname of the name of the information
* @var string
*/
public static $infName = "iName";
/**
* Fieldname of the value of the information
* @var string
*/
public static $infValue = "iValue";
/**
* String for the select part of the query
* @var string
*/
private $selectTerm = "SELECT pid, iName, iValue FROM pis WHERE ";
/**
* String for the orderby part of the query
* @var string
*/
private $orderByTerm = " ORDER BY pid";
/**
* String for the pid part of the query
* @var string
*/
private $pidTerm = "pid = ";
/**
* Default-Constructor
@@ -29,201 +65,52 @@ class SpsSqlManager extends SQLManager {
}
/**
* 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 ";
/**
* 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 = ";
/**
* 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 = "))'";
/**
* 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
* Methods send an query for the pis-service
* @param array $queryArgs
* @return array [num][assoc]
*/
public function sendSpsAliasQuery($queryArgs = array()) {
// 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(\api\SpsApi::$keyDomain, $queryArgs)) {
$domain = $queryArgs[\api\SpsApi::$keyDomain];
}
public function sendPisQuery($queryArgs) {
// build query string
$query = $this->selectTerm;
if ($this->validAliasString($alias)) {
$query .= $this->aliasTerm . $this->quoteTerm . $alias . $this->quoteTerm . $this->addDomainTerm($domain);
if ($this->validPidList($queryArgs)) {
$query .= $this->createPidWhereString($queryArgs) . $this->orderByTerm;
} 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]
* Method check if all items of the pidlist are orly digits
* @param array $poly
* @return boolean
*/
public function sendSpsCoordinateQuery($queryArgs = array()) {
private function validPidList($pidList) {
foreach ($pidList as $value) {
// 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(\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)) {
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;
if (!ctype_digit($value) || PHP_INT_MAX < $value) {
return FALSE;
}
}
return TRUE;
}
/**
* Method convert a pidList to a where-string
* @param array $pidList
* @return string
*/
private function createPidWhereString($pidList) {
$pidListStr = \utiliy\StringManager::$emptyString;
foreach ($pidList as $value) {
$pidListStr .= $this->pidTerm . $value . $this->orTerm;
}
$result = substr($pidListStr, 0, strlen($pidListStr) - strlen($this->orTerm));
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) && 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) && 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) && \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);
}
}
?>

View File

@@ -105,7 +105,7 @@ class SpsSqlManager extends SQLManager {
* @param array $queryArgs
* @return array [num][assoc]
*/
public function sendSpsAliasQuery($queryArgs = array()) {
public function sendSpsAliasQuery($queryArgs) {
// check arguments of the query
if (array_key_exists(\api\SpsApi::$keyAlias, $queryArgs)) {
@@ -136,7 +136,7 @@ class SpsSqlManager extends SQLManager {
* @param array $queryArgs
* @return array [num][assoc]
*/
public function sendSpsCoordinateQuery($queryArgs = array()) {
public function sendSpsCoordinateQuery($queryArgs) {
// check arguments of the query
if (array_key_exists(\api\SpsApi::$keyPoly, $queryArgs)) {

View File

@@ -43,11 +43,17 @@ abstract class SqlManager {
private $link;
/**
* String for a and operrator
* String for an and-operrator
* @var string
*/
protected $andTerm = " and ";
/**
* String for an or-operrator
* @var string
*/
protected $orTerm = " or ";
/**
* String for quotes in a query
* @var string
@@ -69,6 +75,10 @@ abstract class SqlManager {
*/
public function __destruct() {
$this->closeConnection();
unset($this->serverAddress);
unset($this->dbName);
unset($this->userName);
unset($this->userPW);
$this->serverAddress = null;
$this->dbName = null;
$this->userName = null;
@@ -95,6 +105,7 @@ abstract class SqlManager {
public function closeConnection() {
if ($this->link) {
mysql_close($this->link);
unset($this->link);
$this->link = null;
}
}