From 658987ba53249ddf8d7bda036c52bf3f958e9d7c Mon Sep 17 00:00:00 2001 From: stubbfel Date: Tue, 25 Jun 2013 14:41:01 +0200 Subject: [PATCH 1/3] add filestructur for pis --- geoapi/api/PisApi.php | 185 ++++++++++++++++++++++++ geoapi/database/PisSqlManager.php | 229 ++++++++++++++++++++++++++++++ geoapi/service/pis/.htaccess | 2 + geoapi/service/pis/index.php | 39 +++++ 4 files changed, 455 insertions(+) create mode 100644 geoapi/api/PisApi.php create mode 100644 geoapi/database/PisSqlManager.php create mode 100644 geoapi/service/pis/.htaccess create mode 100644 geoapi/service/pis/index.php diff --git a/geoapi/api/PisApi.php b/geoapi/api/PisApi.php new file mode 100644 index 0000000..0a8fb94 --- /dev/null +++ b/geoapi/api/PisApi.php @@ -0,0 +1,185 @@ +sqlManager = new \database\SpsSqlManager(); + parent::__construct(); + $this->contentType("Content-type: application/xml;charset=utf-8"); + } + + /** + * Default-DeConstructor + */ + public function __destruct() { + parent::__destruct(); + } + + /** + * Method start a sps-query(alias) + * @param array $queryArgs + * @return querry result as xml + */ + public function sendSpsAliasQuery($queryArgs = array()) { + $result = $this->sqlManager->sendSpsAliasQuery($queryArgs); + return \utiliy\XmlManager::arrayToSpsXml($result); + } + + /** + * Method start a sps-query(Coordinates) + * @param array $queryArgs + * @return querry result as xml + */ + public function sendSpsCoordinateQuery($queryArgs = array()) { + if (!array_key_exists(SpsApi::$keyLong, $queryArgs) || !array_key_exists(SpsApi::$keyLat, $queryArgs)) { + return null; + } + $latitude = $queryArgs[SpsApi::$keyLat]; + $longitude = $queryArgs[SpsApi::$keyLong]; + + if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) { + return null; + } + + $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) { + $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) { + $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 $this->polyStartStr . "$minLat $minLong,$minLat $maxLong,$maxLat $maxLong,$maxLat $minLong,$minLat $minLong" . $this->polyEndStr; + } + +} + +?> diff --git a/geoapi/database/PisSqlManager.php b/geoapi/database/PisSqlManager.php new file mode 100644 index 0000000..1019aa3 --- /dev/null +++ b/geoapi/database/PisSqlManager.php @@ -0,0 +1,229 @@ +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()) { + + // 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; + } + } + 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); + } + +} + +?> diff --git a/geoapi/service/pis/.htaccess b/geoapi/service/pis/.htaccess new file mode 100644 index 0000000..450c0d1 --- /dev/null +++ b/geoapi/service/pis/.htaccess @@ -0,0 +1,2 @@ +RewriteEngine on +RewriteRule ^ index.php [QSA,L] \ No newline at end of file diff --git a/geoapi/service/pis/index.php b/geoapi/service/pis/index.php new file mode 100644 index 0000000..21c139f --- /dev/null +++ b/geoapi/service/pis/index.php @@ -0,0 +1,39 @@ +get('/alias/:alias', function ($alias) use ($app) { + $args = array(); + $args[\api\SpsApi::$keyAlias] = $alias; + echo $app->sendSpsAliasQuery($args); + }); + +$app->get('/alias/:alias/domain/:domain', function ($alias, $domain) use ($app) { + $args = array(); + $args[\api\SpsApi::$keyAlias] = $alias; + $args[\api\SpsApi::$keyDomain] = $domain; + echo $app->sendSpsAliasQuery($args); + }); + +$app->get('/longitude/:longitude/latitude/:latitude', function ($longitude, $latitude) use ($app) { + $args = array(); + $args[\api\SpsApi::$keyLong] = $longitude; + $args[\api\SpsApi::$keyLat] = $latitude; + echo ($app->sendSpsCoordinateQuery($args)); + }); + +$app->get('/longitude/:longitude/latitude/:latitude/domain/:domain', function ($longitude, $latitude, $domain) use ($app) { + $args = array(); + $args[\api\SpsApi::$keyLong] = $longitude; + $args[\api\SpsApi::$keyLat] = $latitude; + $args[\api\SpsApi::$keyDomain] = $domain; + echo ($app->sendSpsCoordinateQuery($args)); + }); + +$app->run(); +?> From 1678b94dd5af8297e04e3a1318ce5e39a7dd1d0f Mon Sep 17 00:00:00 2001 From: stubbfel Date: Wed, 26 Jun 2013 12:12:10 +0200 Subject: [PATCH 2/3] add sps service --- geoapi/api/Api.php | 5 +- geoapi/api/PisApi.php | 161 ++++---------------- geoapi/api/SpsApi.php | 32 +++- geoapi/database/PisSqlManager.php | 237 ++++++++---------------------- geoapi/database/SpsSqlManager.php | 4 +- geoapi/database/SqlManager.php | 13 +- geoapi/service/pis/index.php | 33 +---- geoapi/service/sps/index.php | 21 +-- geoapi/utility/StringManager.php | 9 +- geoapi/utility/XmlManager.php | 46 ++++++ 10 files changed, 202 insertions(+), 359 deletions(-) diff --git a/geoapi/api/Api.php b/geoapi/api/Api.php index 0bb32b1..9e02459 100644 --- a/geoapi/api/Api.php +++ b/geoapi/api/Api.php @@ -23,15 +23,18 @@ abstract class Api extends \Slim\Slim { /** * Default-Constructor */ - public function __construct() { + public function __construct() { $this->connect(); parent::__construct(); + $this->contentType("Content-type: application/xml;charset=utf-8"); } /** * Default-DeConstructor */ public function __destruct() { + $this->sqlManager->closeConnection(); + unset($this->sqlManager); $this->sqlManager = null; } diff --git a/geoapi/api/PisApi.php b/geoapi/api/PisApi.php index 0a8fb94..085bbcd 100644 --- a/geoapi/api/PisApi.php +++ b/geoapi/api/PisApi.php @@ -3,7 +3,7 @@ namespace api; include_once "../../global.inc.php"; -include_once PATH_DATABASE . "/SpsSqlManager.php"; +include_once PATH_DATABASE . "/PisSqlManager.php"; include_once PATH_UTILITTY . "/XmlManager.php"; require_once PATH_API . "/Api.php"; @@ -12,87 +12,26 @@ require_once PATH_API . "/Api.php"; * @author stubbfel * @since 20.06.2013 */ -class SpsApi extends Api { +class PisApi extends Api { /** - * Keyword for alias arguments + * Route string for the alias paramter * @var string */ - public static $keyAlias = "alias"; + public static $routeParameterPids = "/pid/:pid+"; /** - * Keyword for domain arguments - * @var string + * max number of pid for each query + * @var int */ - 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; + private $maxPid = 10; /** * Default-Constructor */ public function __construct() { - $this->sqlManager = new \database\SpsSqlManager(); + $this->sqlManager = new \database\PisSqlManager(); parent::__construct(); - $this->contentType("Content-type: application/xml;charset=utf-8"); } /** @@ -103,81 +42,31 @@ class SpsApi extends Api { } /** - * Method start a sps-query(alias) + * Method start a pis-query * @param array $queryArgs - * @return querry result as xml + * @return query result as xml */ - public function sendSpsAliasQuery($queryArgs = array()) { - $result = $this->sqlManager->sendSpsAliasQuery($queryArgs); - return \utiliy\XmlManager::arrayToSpsXml($result); + public function sendPisQuery($queryArgs) { + $pidList = $this->removeEmptyItmes($queryArgs); + if (count($pidList) < $this->maxPid) { + $result = $this->sqlManager->sendPisQuery($pidList); + return \utiliy\XmlManager::arrayToPisXml($result); + } + return NULL; } /** - * Method start a sps-query(Coordinates) + * Method remove all empty string * @param array $queryArgs - * @return querry result as xml + * @return array */ - public function sendSpsCoordinateQuery($queryArgs = array()) { - if (!array_key_exists(SpsApi::$keyLong, $queryArgs) || !array_key_exists(SpsApi::$keyLat, $queryArgs)) { - return null; - } - $latitude = $queryArgs[SpsApi::$keyLat]; - $longitude = $queryArgs[SpsApi::$keyLong]; - - if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) { - return null; - } - - $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) { - $digitLessPoint = str_replace(".", "", $string); - $digit = str_replace("-", "", $digitLessPoint); - if (ctype_digit($digit)) { - if ($string <= $this->maxLong && $string >= $this->minLong) { - return TRUE; + private function removeEmptyItmes($queryArgs) { + foreach ($queryArgs as $key => $value) { + if (empty($value)) { + unset($queryArgs[$key]); } - }; - return FALSE; - } - - /** - * Method check if a string is a valid Latitude - * @param strinf $string - * @return bool - */ - private function validLatitude($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 $this->polyStartStr . "$minLat $minLong,$minLat $maxLong,$maxLat $maxLong,$maxLat $minLong,$minLat $minLong" . $this->polyEndStr; + } + return $queryArgs; } } diff --git a/geoapi/api/SpsApi.php b/geoapi/api/SpsApi.php index 0a8fb94..0cf23de 100644 --- a/geoapi/api/SpsApi.php +++ b/geoapi/api/SpsApi.php @@ -14,6 +14,30 @@ require_once PATH_API . "/Api.php"; */ class SpsApi extends Api { + /** + * Route string for the alias paramter + * @var string + */ + public static $routeParameterAlias = "/alias/:alias"; + + /** + * Route string for the alias paramter + * @var string + */ + public static $routeParameterDomain = "/domain/:domain"; + + /** + * Route string for the Longitude paramter + * @var string + */ + public static $routeParameterLongitude= "/longitude/:longitude"; + + /** + * Route string for the latitude paramter + * @var string + */ + public static $routeParameterLatitude = "/latitude/:latitude"; + /** * Keyword for alias arguments * @var string @@ -73,8 +97,8 @@ class SpsApi extends Api { * @var float */ private $minLat = -180; - - /** + + /** * maximum value of longitude * @var float */ @@ -107,7 +131,7 @@ class SpsApi extends Api { * @param array $queryArgs * @return querry result as xml */ - public function sendSpsAliasQuery($queryArgs = array()) { + public function sendSpsAliasQuery($queryArgs) { $result = $this->sqlManager->sendSpsAliasQuery($queryArgs); return \utiliy\XmlManager::arrayToSpsXml($result); } @@ -117,7 +141,7 @@ class SpsApi extends Api { * @param array $queryArgs * @return querry result as xml */ - public function sendSpsCoordinateQuery($queryArgs = array()) { + public function sendSpsCoordinateQuery($queryArgs) { if (!array_key_exists(SpsApi::$keyLong, $queryArgs) || !array_key_exists(SpsApi::$keyLat, $queryArgs)) { return null; } diff --git a/geoapi/database/PisSqlManager.php b/geoapi/database/PisSqlManager.php index 1019aa3..13430f4 100644 --- a/geoapi/database/PisSqlManager.php +++ b/geoapi/database/PisSqlManager.php @@ -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); - } - } ?> diff --git a/geoapi/database/SpsSqlManager.php b/geoapi/database/SpsSqlManager.php index 1019aa3..83845ea 100644 --- a/geoapi/database/SpsSqlManager.php +++ b/geoapi/database/SpsSqlManager.php @@ -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)) { diff --git a/geoapi/database/SqlManager.php b/geoapi/database/SqlManager.php index a1716b0..2c10710 100644 --- a/geoapi/database/SqlManager.php +++ b/geoapi/database/SqlManager.php @@ -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; } } diff --git a/geoapi/service/pis/index.php b/geoapi/service/pis/index.php index 21c139f..38f4def 100644 --- a/geoapi/service/pis/index.php +++ b/geoapi/service/pis/index.php @@ -1,38 +1,13 @@ get('/alias/:alias', function ($alias) use ($app) { - $args = array(); - $args[\api\SpsApi::$keyAlias] = $alias; - echo $app->sendSpsAliasQuery($args); - }); - -$app->get('/alias/:alias/domain/:domain', function ($alias, $domain) use ($app) { - $args = array(); - $args[\api\SpsApi::$keyAlias] = $alias; - $args[\api\SpsApi::$keyDomain] = $domain; - echo $app->sendSpsAliasQuery($args); - }); - -$app->get('/longitude/:longitude/latitude/:latitude', function ($longitude, $latitude) use ($app) { - $args = array(); - $args[\api\SpsApi::$keyLong] = $longitude; - $args[\api\SpsApi::$keyLat] = $latitude; - echo ($app->sendSpsCoordinateQuery($args)); - }); - -$app->get('/longitude/:longitude/latitude/:latitude/domain/:domain', function ($longitude, $latitude, $domain) use ($app) { - $args = array(); - $args[\api\SpsApi::$keyLong] = $longitude; - $args[\api\SpsApi::$keyLat] = $latitude; - $args[\api\SpsApi::$keyDomain] = $domain; - echo ($app->sendSpsCoordinateQuery($args)); +$app->get(\api\PisApi::$routeParameterPids, function ($pid = array()) use ($app) { + echo $app->sendPisQuery($pid); }); $app->run(); diff --git a/geoapi/service/sps/index.php b/geoapi/service/sps/index.php index 21c139f..8dddc5c 100644 --- a/geoapi/service/sps/index.php +++ b/geoapi/service/sps/index.php @@ -7,27 +7,28 @@ require_once PATH_API . "/SpsApi.php"; $app = new \api\SpsApi(); // declare the get-methods -$app->get('/alias/:alias', function ($alias) use ($app) { - $args = array(); - $args[\api\SpsApi::$keyAlias] = $alias; - echo $app->sendSpsAliasQuery($args); - }); - -$app->get('/alias/:alias/domain/:domain', function ($alias, $domain) use ($app) { +// declare the get-methods +$app->get(\api\SpsApi::$routeParameterAlias, function ($alias) use ($app) { $args = array(); $args[\api\SpsApi::$keyAlias] = $alias; - $args[\api\SpsApi::$keyDomain] = $domain; echo $app->sendSpsAliasQuery($args); }); -$app->get('/longitude/:longitude/latitude/:latitude', function ($longitude, $latitude) use ($app) { +$app->get(\api\SpsApi::$routeParameterAlias . \api\SpsApi::$routeParameterDomain, function ($alias, $domain) use ($app) { + $args = array(); + $args[\api\SpsApi::$keyAlias] = $alias; + $args[\api\SpsApi::$keyDomain] = $domain; + echo $app->sendSpsAliasQuery($args); + }); + +$app->get(\api\SpsApi::$routeParameterLongitude . \api\SpsApi::$routeParameterLatitude, function ($longitude, $latitude) use ($app) { $args = array(); $args[\api\SpsApi::$keyLong] = $longitude; $args[\api\SpsApi::$keyLat] = $latitude; echo ($app->sendSpsCoordinateQuery($args)); }); -$app->get('/longitude/:longitude/latitude/:latitude/domain/:domain', function ($longitude, $latitude, $domain) use ($app) { +$app->get(\api\SpsApi::$routeParameterLongitude . \api\SpsApi::$routeParameterLatitude . \api\SpsApi::$routeParameterDomain, function ($longitude, $latitude, $domain) use ($app) { $args = array(); $args[\api\SpsApi::$keyLong] = $longitude; $args[\api\SpsApi::$keyLat] = $latitude; diff --git a/geoapi/utility/StringManager.php b/geoapi/utility/StringManager.php index d83cdfe..4a3e75a 100644 --- a/geoapi/utility/StringManager.php +++ b/geoapi/utility/StringManager.php @@ -9,7 +9,14 @@ include_once "../../global.inc.php"; * @since 25.06.2013 */ class StringManager { - + + /** + * A Constant vor an emptystring like \"\" + * @var string + */ + public static $emptyString = ""; + + /** * Method check if a certain string start with a certain sustring * @param string $haystack diff --git a/geoapi/utility/XmlManager.php b/geoapi/utility/XmlManager.php index eca7472..1e6d84a 100644 --- a/geoapi/utility/XmlManager.php +++ b/geoapi/utility/XmlManager.php @@ -23,6 +23,24 @@ class XmlManager { */ public static $placeElementName = "place"; + /** + * Name for the placeinformation element + * @var string + */ + public static $placeInfoElementName = "placeInformation"; + + /** + * Name for the placeInfoName attribute + * @var string + */ + public static $placeInfoName = "placeInformationName"; + + /** + * Name for the place element + * @var string + */ + public static $placeInfoValue = "placeInformationValue"; + /** * Name for the placeid attribute * @var string @@ -51,6 +69,34 @@ class XmlManager { return $xml->asXML(); } + /** + * Method convert an array to a response xml for the sps service + * @param array[num][assoc] $result + * @return xml-string + */ + public static function arrayToPisXml($result = array()) { + $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); + $actPlace = 0; + + foreach ($result as $row) { + + // fetch the place id of the row + $placeId = $row[\database\PisSqlManager::$placeId]; + + // if the id is new -> add new place element + if ($actPlace != $placeId) { + $actPlace = $placeId; + $place = $xml->addChild(XmlManager::$placeElementName); + $place->addAttribute(XmlManager::$placeIdAttrName, $placeId); + } + + // add placeinformation elment + $placeInfo = $place->addChild(XmlManager::$placeInfoElementName, utf8_encode($row[\database\PisSqlManager::$infValue])); + $placeInfo->addAttribute(XmlManager::$placeInfoName, $row[\database\PisSqlManager::$infName]); + } + return $xml->asXML(); + } + } ?> From 186657be6a431a8876e1d09ca068a44e64d26763 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Wed, 26 Jun 2013 12:14:43 +0200 Subject: [PATCH 3/3] finish $61 --- geoapi/database/PisSqlManager.php | 2 +- geoapi/service/pis/index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/geoapi/database/PisSqlManager.php b/geoapi/database/PisSqlManager.php index 13430f4..4ff6a58 100644 --- a/geoapi/database/PisSqlManager.php +++ b/geoapi/database/PisSqlManager.php @@ -7,7 +7,7 @@ include_once PATH_UTILITTY . "/StringManager.php"; require_once PATH_DATABASE . "/SqlManager.php"; /** - * Description of SpsSqlManager + * Description of ZisSqlManager * * @author stubbfel * @since 20.06.2013 diff --git a/geoapi/service/pis/index.php b/geoapi/service/pis/index.php index 38f4def..bed4a17 100644 --- a/geoapi/service/pis/index.php +++ b/geoapi/service/pis/index.php @@ -6,7 +6,7 @@ require_once PATH_API . "/PisApi.php"; // instance a new api $app = new \api\PisApi(); -$app->get(\api\PisApi::$routeParameterPids, function ($pid = array()) use ($app) { +$app->get(\api\PisApi::$routeParameterPids, function ($pid) use ($app) { echo $app->sendPisQuery($pid); });