From 34c0549ac81f928f09b6aae79d812ade56cec3aa Mon Sep 17 00:00:00 2001 From: stubbfel Date: Wed, 26 Jun 2013 14:00:16 +0200 Subject: [PATCH] add pss #62 --- geoapi/api/PisApi.php | 18 +----- geoapi/api/PssApi.php | 64 +++++++++++++++++++++ geoapi/api/SpsApi.php | 11 ++-- geoapi/database/PisSqlManager.php | 37 ++---------- geoapi/database/PssSqlManager.php | 95 +++++++++++++++++++++++++++++++ geoapi/database/SpsSqlManager.php | 34 +++++------ geoapi/database/SqlManager.php | 13 ----- geoapi/service/pss/.htaccess | 2 + geoapi/service/pss/index.php | 14 +++++ geoapi/utility/ArrayManager.php | 58 +++++++++++++++++++ geoapi/utility/StringManager.php | 12 ++++ geoapi/utility/XmlManager.php | 78 ++++++++++++++++++++----- 12 files changed, 338 insertions(+), 98 deletions(-) create mode 100644 geoapi/api/PssApi.php create mode 100644 geoapi/database/PssSqlManager.php create mode 100644 geoapi/service/pss/.htaccess create mode 100644 geoapi/service/pss/index.php create mode 100644 geoapi/utility/ArrayManager.php diff --git a/geoapi/api/PisApi.php b/geoapi/api/PisApi.php index 085bbcd..ff072d2 100644 --- a/geoapi/api/PisApi.php +++ b/geoapi/api/PisApi.php @@ -5,6 +5,7 @@ namespace api; include_once "../../global.inc.php"; include_once PATH_DATABASE . "/PisSqlManager.php"; include_once PATH_UTILITTY . "/XmlManager.php"; +include_once PATH_UTILITTY . "/ArrayManager.php"; require_once PATH_API . "/Api.php"; /** @@ -47,28 +48,13 @@ class PisApi extends Api { * @return query result as xml */ public function sendPisQuery($queryArgs) { - $pidList = $this->removeEmptyItmes($queryArgs); + $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs); if (count($pidList) < $this->maxPid) { $result = $this->sqlManager->sendPisQuery($pidList); return \utiliy\XmlManager::arrayToPisXml($result); } return NULL; } - - /** - * Method remove all empty string - * @param array $queryArgs - * @return array - */ - private function removeEmptyItmes($queryArgs) { - foreach ($queryArgs as $key => $value) { - if (empty($value)) { - unset($queryArgs[$key]); - } - } - return $queryArgs; - } - } ?> diff --git a/geoapi/api/PssApi.php b/geoapi/api/PssApi.php new file mode 100644 index 0000000..a531207 --- /dev/null +++ b/geoapi/api/PssApi.php @@ -0,0 +1,64 @@ +sqlManager = new \database\PssSqlManager(); + parent::__construct(); + } + + /** + * Default-DeConstructor + */ + public function __destruct() { + parent::__destruct(); + } + + /** + * Method start a pis-query + * @param array $queryArgs + * @return query result as xml + */ + public function sendPssQuery($queryArgs) { + $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs); + + if (count($pidList) < $this->maxPid) { + $result = $this->sqlManager->sendPssQuery($pidList); + if ($result) { + return \utiliy\XmlManager::arrayToPssXml($result); + } + } + return NULL; + } + +} + +?> diff --git a/geoapi/api/SpsApi.php b/geoapi/api/SpsApi.php index 0cf23de..8925f44 100644 --- a/geoapi/api/SpsApi.php +++ b/geoapi/api/SpsApi.php @@ -25,12 +25,12 @@ class SpsApi extends Api { * @var string */ public static $routeParameterDomain = "/domain/:domain"; - - /** + + /** * Route string for the Longitude paramter * @var string */ - public static $routeParameterLongitude= "/longitude/:longitude"; + public static $routeParameterLongitude = "/longitude/:longitude"; /** * Route string for the latitude paramter @@ -154,7 +154,10 @@ class SpsApi extends Api { $queryArgs[SpsApi::$keyPoly] = $this->createPolygon($latitude, $longitude, $this->range); $result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs); - return \utiliy\XmlManager::arrayToSpsXml($result); + if ($result) { + return \utiliy\XmlManager::arrayToSpsXml($result); + } + return null; } /** diff --git a/geoapi/database/PisSqlManager.php b/geoapi/database/PisSqlManager.php index 4ff6a58..97e9cb4 100644 --- a/geoapi/database/PisSqlManager.php +++ b/geoapi/database/PisSqlManager.php @@ -42,7 +42,7 @@ class PisSqlManager extends SQLManager { * String for the orderby part of the query * @var string */ - private $orderByTerm = " ORDER BY pid"; + private $orderByTerm = " ORDER BY pid, iName"; /** * String for the pid part of the query @@ -73,44 +73,15 @@ class PisSqlManager extends SQLManager { // build query string $query = $this->selectTerm; - if ($this->validPidList($queryArgs)) { - $query .= $this->createPidWhereString($queryArgs) . $this->orderByTerm; + if (\utiliy\ArrayManager::validIntList($queryArgs)) { + $query .= \utiliy\ArrayManager::toSqlWhereString($queryArgs, $this->orTerm, $this->pidTerm) . $this->orderByTerm; } else { return null; } + // send query return $this->query($query); } - - /** - * Method check if all items of the pidlist are orly digits - * @param array $poly - * @return boolean - */ - private function validPidList($pidList) { - foreach ($pidList as $value) { - - 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; - } - } ?> diff --git a/geoapi/database/PssSqlManager.php b/geoapi/database/PssSqlManager.php new file mode 100644 index 0000000..5fc243d --- /dev/null +++ b/geoapi/database/PssSqlManager.php @@ -0,0 +1,95 @@ +selectTerm; + + if (\utiliy\ArrayManager::validIntList($queryArgs)) { + $query .= \utiliy\ArrayManager::toSqlWhereString($queryArgs, $this->orTerm, $this->pidTerm) . $this->orderByTerm; + } else { + return null; + }; + + // send query + return $this->query($query); + } + +} + +?> diff --git a/geoapi/database/SpsSqlManager.php b/geoapi/database/SpsSqlManager.php index 83845ea..85c66b4 100644 --- a/geoapi/database/SpsSqlManager.php +++ b/geoapi/database/SpsSqlManager.php @@ -14,20 +14,6 @@ require_once PATH_DATABASE . "/SqlManager.php"; */ class SpsSqlManager extends SQLManager { - /** - * Default-Constructor - */ - public function __construct() { - parent::__construct(); - } - - /** - * Default-DEConstructor - */ - public function __destruct() { - parent::__destruct(); - } - /** * Fieldname of the placeID * @var string @@ -100,6 +86,20 @@ class SpsSqlManager extends SQLManager { */ private $domainMaxLenght = 32; + /** + * Default-Constructor + */ + public function __construct() { + parent::__construct(); + } + + /** + * Default-DEConstructor + */ + public function __destruct() { + parent::__destruct(); + } + /** * Methods send an query for the sps-service depends of alias * @param array $queryArgs @@ -185,7 +185,7 @@ class SpsSqlManager extends SQLManager { * @return boolean */ private function validAliasString($alias) { - if ($this->validString($alias) && ctype_alnum($alias) && strlen($alias) <= $this->aliasMaxLenght) { + if (\utiliy\StringManager::validSQLString($alias) && ctype_alnum($alias) && strlen($alias) <= $this->aliasMaxLenght) { return TRUE; } return FALSE; @@ -197,7 +197,7 @@ class SpsSqlManager extends SQLManager { * @return boolean */ private function validDomainString($domain) { - if ($this->validString($domain) && ctype_alnum($domain) && strlen($domain) <= $this->domainMaxLenght) { + if (\utiliy\StringManager::validSQLString($domain) && ctype_alnum($domain) && strlen($domain) <= $this->domainMaxLenght) { return TRUE; } return FALSE; @@ -209,7 +209,7 @@ class SpsSqlManager extends SQLManager { * @return boolean */ private function validPolyString($poly) { - if ($this->validString($poly) && \utiliy\StringManager::startsWith($poly, $this->polyStartStr) && \utiliy\StringManager::endsWith($poly, $this->polyEndStr)) { + if (\utiliy\StringManager::validSQLString($poly) && \utiliy\StringManager::startsWith($poly, $this->polyStartStr) && \utiliy\StringManager::endsWith($poly, $this->polyEndStr)) { return TRUE; } return FALSE; diff --git a/geoapi/database/SqlManager.php b/geoapi/database/SqlManager.php index 2c10710..bc28073 100644 --- a/geoapi/database/SqlManager.php +++ b/geoapi/database/SqlManager.php @@ -129,19 +129,6 @@ abstract class SqlManager { mysql_free_result($mysqlResult); 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; - } - return FALSE; - } - } ?> diff --git a/geoapi/service/pss/.htaccess b/geoapi/service/pss/.htaccess new file mode 100644 index 0000000..450c0d1 --- /dev/null +++ b/geoapi/service/pss/.htaccess @@ -0,0 +1,2 @@ +RewriteEngine on +RewriteRule ^ index.php [QSA,L] \ No newline at end of file diff --git a/geoapi/service/pss/index.php b/geoapi/service/pss/index.php new file mode 100644 index 0000000..0bf0278 --- /dev/null +++ b/geoapi/service/pss/index.php @@ -0,0 +1,14 @@ +get(\api\PssApi::$routeParameterPids, function ($pid) use ($app) { + echo $app->sendPssQuery($pid); + }); + +$app->run(); +?> diff --git a/geoapi/utility/ArrayManager.php b/geoapi/utility/ArrayManager.php new file mode 100644 index 0000000..ad18f21 --- /dev/null +++ b/geoapi/utility/ArrayManager.php @@ -0,0 +1,58 @@ + $value) { + if (empty($value)) { + unset($array[$key]); + } + } + return $array; + } + + /** + * Method convert a pidList to a where-string + * @param array $pidList + * @return string + */ + public static function toSqlWhereString($array, $operator = "", $fieldname = "") { + $arrayStr = StringManager::$emptyString; + foreach ($array as $value) { + $arrayStr .= $fieldname . $value . $operator; + } + $result = substr($arrayStr, 0, strlen($arrayStr) - strlen($operator)); + return $result; + } + + /** + * Method check if all items of the pidlist are only digits + * @param array $poly + * @return boolean + */ + public static function validIntList($list) { + foreach ($list as $value) { + + if (!ctype_digit($value) || PHP_INT_MAX < $value) { + return FALSE; + } + } + return TRUE; + } +} + +?> diff --git a/geoapi/utility/StringManager.php b/geoapi/utility/StringManager.php index 4a3e75a..f276d59 100644 --- a/geoapi/utility/StringManager.php +++ b/geoapi/utility/StringManager.php @@ -37,6 +37,18 @@ class StringManager { public static function endsWith($haystack, $needle) { return (substr($haystack, -strlen($needle)) === $needle); } + + /** + * Method if the string is not a empty String (not only spaces and controlls) + * @param string $string + * @return boolean + */ + public static function validSQLString($string) { + if (!ctype_space($string) && !ctype_cntrl($string)) { + return TRUE; + } + return FALSE; + } } ?> diff --git a/geoapi/utility/XmlManager.php b/geoapi/utility/XmlManager.php index 1e6d84a..0b737c5 100644 --- a/geoapi/utility/XmlManager.php +++ b/geoapi/utility/XmlManager.php @@ -15,50 +15,68 @@ class XmlManager { * a default xml document * @var xml-string */ - public static $defaultXmlDoc = ""; + private static $defaultXmlDoc = ""; /** * Name for the place element * @var string */ - public static $placeElementName = "place"; + private static $placeElementName = "place"; /** * Name for the placeinformation element * @var string */ - public static $placeInfoElementName = "placeInformation"; + private static $placeInfoElementName = "placeInformation"; + + /** + * Name for the placeserviceelement + * @var string + */ + private static $placeServiceElementName = "placeService"; + + /** + * Name for the placesap element + * @var string + */ + private static $placeSapElementName = "sap"; + + /** + * Name for the placerequest element + * @var string + */ + private static $placeRequestElementName = "request"; /** * Name for the placeInfoName attribute * @var string */ - public static $placeInfoName = "placeInformationName"; + private static $placeInfoName = "placeInformationName"; /** - * Name for the place element + * Name for the placeServiceName attribute * @var string */ - public static $placeInfoValue = "placeInformationValue"; + private static $placeServiceName = "placeServiceName"; /** * Name for the placeid attribute * @var string */ - public static $placeIdAttrName = "id"; + private static $placeIdAttrName = "id"; /** * Name for the parent attribute * @var string */ - public static $parentIdAttrName = "parentId"; + private static $parentIdAttrName = "parentId"; /** * Method convert an array to a response xml for the sps service * @param array[num][assoc] $result * @return xml-string */ - public static function arrayToSpsXml($result = array()) { + public static function arrayToSpsXml($result) { $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); foreach ($result as $row) { @@ -70,26 +88,26 @@ class XmlManager { } /** - * Method convert an array to a response xml for the sps service + * Method convert an array to a response xml for the pis service * @param array[num][assoc] $result * @return xml-string */ - public static function arrayToPisXml($result = array()) { + public static function arrayToPisXml($result) { $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]); @@ -97,6 +115,36 @@ class XmlManager { return $xml->asXML(); } + /** + * Method convert an array to a response xml for the pss service + * @param array[num][assoc] $result + * @return xml-string + */ + public static function arrayToPssXml($result) { + $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); + $actPlace = 0; + + foreach ($result as $row) { + + // fetch the place id of the row + $placeId = $row[\database\PssSqlManager::$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 placeservice elment + $placeSrv = $place->addChild(XmlManager::$placeServiceElementName); + $placeSrv->addAttribute(XmlManager::$placeServiceName, $row[\database\PssSqlManager::$srvName]); + $placeSrv->addChild(XmlManager::$placeSapElementName, $row[\database\PssSqlManager::$srvSap]); + $placeSrv->addChild(XmlManager::$placeRequestElementName, $row[\database\PssSqlManager::$srvRequest]); + } + return $xml->asXML(); + } + } ?>