From aa03fdcd1b8967cccfd01a3b4e90535e836216a2 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Mon, 1 Jul 2013 17:47:45 +0200 Subject: [PATCH 1/2] add seiralmanager #66 --- geoapi/api/Api.php | 27 ++++++++++++++++++++++----- geoapi/api/PisApi.php | 8 ++++---- geoapi/api/PssApi.php | 6 +++--- geoapi/api/SpsApi.php | 9 ++++----- geoapi/service/pis/index.php | 3 ++- geoapi/service/pss/index.php | 3 ++- geoapi/service/sps/index.php | 3 ++- geoapi/utility/JsonManager.php | 17 +++++++++++++++-- geoapi/utility/SerialManager.php | 15 +++++++++++++++ geoapi/utility/XmlManager.php | 15 ++++++++++++++- 10 files changed, 83 insertions(+), 23 deletions(-) create mode 100644 geoapi/utility/SerialManager.php diff --git a/geoapi/api/Api.php b/geoapi/api/Api.php index fa8abc2..958dddb 100644 --- a/geoapi/api/Api.php +++ b/geoapi/api/Api.php @@ -4,7 +4,10 @@ namespace api; include_once "../../global.inc.php"; include_once PATH_DATABASE . "/SQLManager.php"; +include_once PATH_UTILITTY . "/XmlManager.php"; +include_once PATH_UTILITTY . "/JsonManager.php"; require_once PATH_3PARTY . "/Slim/Slim.php"; + \Slim\Slim::registerAutoloader(); /** @@ -20,15 +23,29 @@ abstract class Api extends \Slim\Slim { */ protected $sqlManager; + /** + * Variable for the serialazarion manager of the api + * @var :SqlManager + */ + protected $serialManager; + protected static $contentypeXML = "application/xml;charset=utf-8"; + protected static $contentypeJson = "application/json;charset=utf-8"; + /** * Default-Constructor */ - public function __construct() { + public function __construct($headers = array()) { $this->connect(); parent::__construct(); - // set content type td xml - $this->contentType("Content-type: application/xml;charset=utf-8"); +// set content type td xml + if ($headers && preg_match('/json/', $headers["Accept"])) { + $this->serialManager = new \utiliy\JsonManager(); + $this->contentType(self::$contentypeJson); + } else { + $this->serialManager = new \utiliy\XmlManager(); + $this->contentType(self::$contentypeXML); + } } /** @@ -36,10 +53,10 @@ abstract class Api extends \Slim\Slim { */ public function __destruct() { - // destroy the sqlManager +// destroy the sqlManager $this->sqlManager->closeConnection(); unset($this->sqlManager); - $this->sqlManager = null; + unset($this->serialManager); } /** diff --git a/geoapi/api/PisApi.php b/geoapi/api/PisApi.php index 7fa43e8..eacc8f3 100644 --- a/geoapi/api/PisApi.php +++ b/geoapi/api/PisApi.php @@ -4,7 +4,6 @@ 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"; @@ -30,9 +29,9 @@ class PisApi extends Api { /** * Default-Constructor */ - public function __construct() { + public function __construct($headers = array()) { $this->sqlManager = new \database\PisSqlManager(); - parent::__construct(); + parent::__construct($headers); } /** @@ -51,7 +50,8 @@ class PisApi extends Api { $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs); if (count($pidList) < $this->maxPid) { $result = $this->sqlManager->sendPisQuery($pidList); - return \utiliy\XmlManager::arrayToPisXml($result); + + return $this->serialManager->arrayToPis($result); } return NULL; } diff --git a/geoapi/api/PssApi.php b/geoapi/api/PssApi.php index f35dcd8..c39ff21 100644 --- a/geoapi/api/PssApi.php +++ b/geoapi/api/PssApi.php @@ -30,9 +30,9 @@ class PssApi extends Api { /** * Default-Constructor */ - public function __construct() { + public function __construct($headers = array()) { $this->sqlManager = new \database\PssSqlManager(); - parent::__construct(); + parent::__construct($headers); } /** @@ -52,7 +52,7 @@ class PssApi extends Api { if (count($pidList) < $this->maxPid) { $result = $this->sqlManager->sendPssQuery($pidList); - return \utiliy\XmlManager::arrayToPssXml($result); + return $this->serialManager->arrayTopis($result); } return NULL; } diff --git a/geoapi/api/SpsApi.php b/geoapi/api/SpsApi.php index 65c53ff..c25b7a1 100644 --- a/geoapi/api/SpsApi.php +++ b/geoapi/api/SpsApi.php @@ -4,7 +4,6 @@ namespace api; include_once "../../global.inc.php"; include_once PATH_DATABASE . "/SpsSqlManager.php"; -include_once PATH_UTILITTY . "/XmlManager.php"; require_once PATH_API . "/Api.php"; /** @@ -113,9 +112,9 @@ class SpsApi extends Api { /** * Default-Constructor */ - public function __construct() { + public function __construct($headers = array()) { $this->sqlManager = new \database\SpsSqlManager(); - parent::__construct(); + parent::__construct($headers); } /** @@ -132,7 +131,7 @@ class SpsApi extends Api { */ public function sendSpsAliasQuery($queryArgs) { $result = $this->sqlManager->sendSpsAliasQuery($queryArgs); - return \utiliy\XmlManager::arrayToSpsXml($result); + return $this->serialManager->arrayToSps($result); } /** @@ -158,7 +157,7 @@ class SpsApi extends Api { // send querry $result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs); - return \utiliy\XmlManager::arrayToSpsXml($result); + return $this->serialManager->arrayToSps($result); } /** diff --git a/geoapi/service/pis/index.php b/geoapi/service/pis/index.php index 5d66718..d130870 100644 --- a/geoapi/service/pis/index.php +++ b/geoapi/service/pis/index.php @@ -3,8 +3,9 @@ include_once "../../global.inc.php"; require_once PATH_API . "/PisApi.php"; +$headers = apache_request_headers(); // instance a new api -$app = new \api\PisApi(); +$app = new \api\PisApi($headers); // HTTP-Get-Method $app->get(\api\PisApi::$routeParameterPids, function ($pid) use ($app) { diff --git a/geoapi/service/pss/index.php b/geoapi/service/pss/index.php index 61bcbab..e6b37bb 100644 --- a/geoapi/service/pss/index.php +++ b/geoapi/service/pss/index.php @@ -3,8 +3,9 @@ include_once "../../global.inc.php"; require_once PATH_API . "/PssApi.php"; +$headers = apache_request_headers(); // instance a new api -$app = new \api\PssApi(); +$app = new \api\PssApi($headers); // HTTP-Get-Method $app->get(\api\PssApi::$routeParameterPids, function ($pid) use ($app) { diff --git a/geoapi/service/sps/index.php b/geoapi/service/sps/index.php index 9e33d0f..cb1d191 100644 --- a/geoapi/service/sps/index.php +++ b/geoapi/service/sps/index.php @@ -2,9 +2,10 @@ include_once "../../global.inc.php"; require_once PATH_API . "/SpsApi.php"; +$headers = apache_request_headers(); // instance a new api -$app = new \api\SpsApi(); +$app = new \api\SpsApi($headers); // HTTP-Get-Methods $app->get(\api\SpsApi::$routeParameterAlias, function ($alias) use ($app) { diff --git a/geoapi/utility/JsonManager.php b/geoapi/utility/JsonManager.php index 6874b8d..2f77641 100644 --- a/geoapi/utility/JsonManager.php +++ b/geoapi/utility/JsonManager.php @@ -3,13 +3,14 @@ namespace utiliy; include_once "../../global.inc.php"; +require_once PATH_UTILITTY . "/SerialManager.php"; /** * The XmlManager provides some xml-methods * @author stubbfel * @since 25.06.2013 */ -class JsonManager { +class JsonManager implements SerialManager { /** * Name for the sap item @@ -93,7 +94,7 @@ class JsonManager { // add placeinformation item $placeInfo = array(JsonManager::$placeInfoName => $row[\database\PisSqlManager::$infName], - JsonManager::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue])); + JsonManager::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue])); array_push($place, $placeInfo); } return json_encode($infos); @@ -130,6 +131,18 @@ class JsonManager { return json_encode($services); } + public function arrayToSps($result) { + return JsonManager::arrayToSpsJson($result); + } + + public function arrayToPss($result) { + return JsonManager::arrayToPssJson($result); + } + + public function arrayToPis($result) { + return JsonManager::arrayToPisJson($result); + } + } ?> diff --git a/geoapi/utility/SerialManager.php b/geoapi/utility/SerialManager.php new file mode 100644 index 0000000..55068d6 --- /dev/null +++ b/geoapi/utility/SerialManager.php @@ -0,0 +1,15 @@ + diff --git a/geoapi/utility/XmlManager.php b/geoapi/utility/XmlManager.php index 8465a44..edac86d 100644 --- a/geoapi/utility/XmlManager.php +++ b/geoapi/utility/XmlManager.php @@ -3,13 +3,14 @@ namespace utiliy; include_once "../../global.inc.php"; +require_once PATH_UTILITTY . "/SerialManager.php"; /** * The XmlManager provides some xml-methods * @author stubbfel * @since 25.06.2013 */ -class XmlManager { +class XmlManager implements SerialManager{ /** * a default xml document @@ -157,6 +158,18 @@ class XmlManager { } return $xml->asXML(); } + + public function arrayToSps($result) { + return XmlManager::arrayToSpsXml($result); + } + + public function arrayToPis($result){ + return XmlManager::arrayToPisXml($result); + } + + public function arrayToPss($result) { + return XmlManager::arrayToPssXml($result); + } } From 7851ee7e3b24f38e5b9eb9ba82f392b1dddf94b8 Mon Sep 17 00:00:00 2001 From: stubbfel Date: Mon, 1 Jul 2013 18:54:59 +0200 Subject: [PATCH 2/2] finish #66 --- geoapi/api/Api.php | 29 +++++++++++++-- geoapi/api/PisApi.php | 7 ++-- geoapi/api/PssApi.php | 7 ++-- geoapi/api/SpsApi.php | 31 ++++++++-------- geoapi/database/PisSqlManager.php | 10 +++--- geoapi/database/PssSqlManager.php | 10 +++--- geoapi/database/SpsSqlManager.php | 38 ++++++++++---------- geoapi/database/SqlManager.php | 6 ++-- geoapi/insert/loadcvs.php | 5 +++ geoapi/service/pis/index.php | 1 + geoapi/service/pss/index.php | 1 + geoapi/service/sps/index.php | 2 ++ geoapi/utility/JsonManager.php | 60 ++++++++++++++++++++++--------- geoapi/utility/SerialManager.php | 29 ++++++++++++--- geoapi/utility/XmlManager.php | 38 ++++++++++---------- 15 files changed, 177 insertions(+), 97 deletions(-) diff --git a/geoapi/api/Api.php b/geoapi/api/Api.php index 958dddb..9e9848a 100644 --- a/geoapi/api/Api.php +++ b/geoapi/api/Api.php @@ -28,18 +28,41 @@ abstract class Api extends \Slim\Slim { * @var :SqlManager */ protected $serialManager; + + /** + * Variable for the contentype of XML + * @var string + */ protected static $contentypeXML = "application/xml;charset=utf-8"; + + /** + * Variable for the contentype of Json + * @var string + */ protected static $contentypeJson = "application/json;charset=utf-8"; /** - * Default-Constructor + * Variable for the regex−string to search json-contenttype + * @var string + */ + private static $jsonRegStr = '/json/'; + + /** + * Keyword for the accept parameter of the requestheader + * @var string + */ + private static $keyReqHeaderAccept = "Accept"; + + /** + * Constructor + * @param array[assoc] $headers - RequestHeader */ public function __construct($headers = array()) { $this->connect(); parent::__construct(); -// set content type td xml - if ($headers && preg_match('/json/', $headers["Accept"])) { + // set content type + if ($headers && array_key_exists(self::$keyReqHeaderAccept, $headers) && preg_match(self::$jsonRegStr, $headers[self::$keyReqHeaderAccept])) { $this->serialManager = new \utiliy\JsonManager(); $this->contentType(self::$contentypeJson); } else { diff --git a/geoapi/api/PisApi.php b/geoapi/api/PisApi.php index eacc8f3..9ce27d5 100644 --- a/geoapi/api/PisApi.php +++ b/geoapi/api/PisApi.php @@ -24,10 +24,11 @@ class PisApi extends Api { * max number of pid for each query * @var int */ - private $maxPid = 10; + private static $maxPid = 10; /** - * Default-Constructor + * Constructor + * @param array[assoc] $headers - RequestHeader */ public function __construct($headers = array()) { $this->sqlManager = new \database\PisSqlManager(); @@ -48,7 +49,7 @@ class PisApi extends Api { */ public function sendPisQuery($queryArgs) { $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs); - if (count($pidList) < $this->maxPid) { + if (count($pidList) < self::$maxPid) { $result = $this->sqlManager->sendPisQuery($pidList); return $this->serialManager->arrayToPis($result); diff --git a/geoapi/api/PssApi.php b/geoapi/api/PssApi.php index c39ff21..a1a071c 100644 --- a/geoapi/api/PssApi.php +++ b/geoapi/api/PssApi.php @@ -25,10 +25,11 @@ class PssApi extends Api { * max number of pid for each query * @var int */ - private $maxPid = 10; + private static $maxPid = 10; /** - * Default-Constructor + * Constructor + * @param array[assoc] $headers - RequestHeader */ public function __construct($headers = array()) { $this->sqlManager = new \database\PssSqlManager(); @@ -50,7 +51,7 @@ class PssApi extends Api { public function sendPssQuery($queryArgs) { $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs); - if (count($pidList) < $this->maxPid) { + if (count($pidList) < self::$maxPid) { $result = $this->sqlManager->sendPssQuery($pidList); return $this->serialManager->arrayTopis($result); } diff --git a/geoapi/api/SpsApi.php b/geoapi/api/SpsApi.php index c25b7a1..c395a06 100644 --- a/geoapi/api/SpsApi.php +++ b/geoapi/api/SpsApi.php @@ -71,46 +71,47 @@ class SpsApi extends Api { * Varible for the range of the searchpolygon * @var float */ - private $range = 1; + private static $range = 1; /* * Varible for the fist chars of the string for a Polygon * @var string */ - private $polyStartStr = "GeomFromText('Polygon(("; + private static $polyStartStr = "GeomFromText('Polygon(("; /* * Varible for the last chars of the string for a Polygon * @var string */ - private $polyEndStr = "))'"; + private static $polyEndStr = "))'"; /** * maximum value of latitude * @var float */ - private $maxLat = 180; + private static $maxLat = 180; /** * minimum value of latitude * @var float */ - private $minLat = -180; + private static $minLat = -180; /** * maximum value of longitude * @var float */ - private $maxLong = 180; + private static $maxLong = 180; /** * minimum value of longitude * @var float */ - private $minLong = -180; + private static $minLong = -180; /** - * Default-Constructor + * Constructor + * @param array[assoc] $headers - RequestHeader */ public function __construct($headers = array()) { $this->sqlManager = new \database\SpsSqlManager(); @@ -142,18 +143,18 @@ class SpsApi extends Api { public function sendSpsCoordinateQuery($queryArgs) { // check arguments of the query - if (!array_key_exists(SpsApi::$keyLong, $queryArgs) || !array_key_exists(SpsApi::$keyLat, $queryArgs)) { + if (!array_key_exists(self::$keyLong, $queryArgs) || !array_key_exists(self::$keyLat, $queryArgs)) { return null; } - $latitude = $queryArgs[SpsApi::$keyLat]; - $longitude = $queryArgs[SpsApi::$keyLong]; + $latitude = $queryArgs[self::$keyLat]; + $longitude = $queryArgs[self::$keyLong]; if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) { return null; } // build a request polygon - $queryArgs[SpsApi::$keyPoly] = $this->createPolygon($latitude, $longitude, $this->range); + $queryArgs[self::$keyPoly] = $this->createPolygon($latitude, $longitude, self::$range); // send querry $result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs); @@ -169,7 +170,7 @@ class SpsApi extends Api { $digitLessPoint = str_replace(".", "", $string); $digit = str_replace("-", "", $digitLessPoint); if (ctype_digit($digit)) { - if ($string <= $this->maxLong && $string >= $this->minLong) { + if ($string <= self::$maxLong && $string >= self::$minLong) { return TRUE; } }; @@ -185,7 +186,7 @@ class SpsApi extends Api { $digitLessPoint = str_replace(".", "", $string); $digit = str_replace("-", "", $digitLessPoint); if (ctype_digit($digit)) { - if ($string <= $this->maxLat && $string >= $this->minLat) { + if ($string <= self::$maxLat && $string >= self::$minLat) { return TRUE; } }; @@ -204,7 +205,7 @@ class SpsApi extends Api { $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 self::$polyStartStr . "$minLat $minLong,$minLat $maxLong,$maxLat $maxLong,$maxLat $minLong,$minLat $minLong" . self::$polyEndStr; } } diff --git a/geoapi/database/PisSqlManager.php b/geoapi/database/PisSqlManager.php index 0ea9f49..9f7d3f5 100644 --- a/geoapi/database/PisSqlManager.php +++ b/geoapi/database/PisSqlManager.php @@ -36,19 +36,19 @@ class PisSqlManager extends SQLManager { * String for the select part of the query * @var string */ - private $selectTerm = "SELECT pid, iName, iValue FROM pis WHERE "; + private static $selectTerm = "SELECT pid, iName, iValue FROM pis WHERE "; /** * String for the orderby part of the query * @var string */ - private $orderByTerm = " ORDER BY pid, iName"; + private static $orderByTerm = " ORDER BY pid, iName"; /** * String for the pid part of the query * @var string */ - private $pidTerm = "pid = "; + private static $pidTerm = "pid = "; /** * Default-Constructor @@ -72,9 +72,9 @@ class PisSqlManager extends SQLManager { public function sendPisQuery($queryArgs) { // build query string - $query = $this->selectTerm; + $query = self::$selectTerm; if (\utiliy\ArrayManager::validIntList($queryArgs)) { - $query .= \utiliy\ArrayManager::toSqlWhereString($queryArgs, $this->orTerm, $this->pidTerm) . $this->orderByTerm; + $query .= \utiliy\ArrayManager::toSqlWhereString($queryArgs, self::$orTerm, self::$pidTerm) . self::$orderByTerm; } else { return null; } diff --git a/geoapi/database/PssSqlManager.php b/geoapi/database/PssSqlManager.php index b55f325..eac7745 100644 --- a/geoapi/database/PssSqlManager.php +++ b/geoapi/database/PssSqlManager.php @@ -42,19 +42,19 @@ class PssSqlManager extends SQLManager { * String for the select part of the query * @var string */ - private $selectTerm = "SELECT pid, sName, sap, request FROM pss WHERE "; + private static $selectTerm = "SELECT pid, sName, sap, request FROM pss WHERE "; /** * String for the orderby part of the query * @var string */ - private $orderByTerm = " ORDER BY pid, sName"; + private static $orderByTerm = " ORDER BY pid, sName"; /** * String for the pid part of the query * @var string */ - private $pidTerm = "pid = "; + private static $pidTerm = "pid = "; /** * Default-Constructor @@ -78,10 +78,10 @@ class PssSqlManager extends SQLManager { public function sendPssQuery($queryArgs) { // build query string - $query = $this->selectTerm; + $query = self::$selectTerm; if (\utiliy\ArrayManager::validIntList($queryArgs)) { - $query .= \utiliy\ArrayManager::toSqlWhereString($queryArgs, $this->orTerm, $this->pidTerm) . $this->orderByTerm; + $query .= \utiliy\ArrayManager::toSqlWhereString($queryArgs, self::$orTerm, self::$pidTerm) . self::$orderByTerm; } else { return null; }; diff --git a/geoapi/database/SpsSqlManager.php b/geoapi/database/SpsSqlManager.php index cb3c1ca..38f64a1 100644 --- a/geoapi/database/SpsSqlManager.php +++ b/geoapi/database/SpsSqlManager.php @@ -30,61 +30,61 @@ class SpsSqlManager extends SQLManager { * String for the select part of the query * @var string */ - private $selectTerm = "SELECT DISTINCT id, parent FROM sps WHERE "; + private static $selectTerm = "SELECT DISTINCT id, parent FROM sps WHERE "; /** * String for the alias part of the query * @var string */ - private $aliasTerm = "alias = "; + private static $aliasTerm = "alias = "; /** * String for the did part of the query * @var string */ - private $domainTerm = "did = "; + private static $domainTerm = "did = "; /** * String for the dNamet part of the query * @var string */ - private $domainNameTerm = "dName = "; + private static $domainNameTerm = "dName = "; /** * first part of intersect-function * @var string */ - private $interSectTermStart = "Intersects("; + private static $interSectTermStart = "Intersects("; /** * last part of intersect-function * @var string */ - private $interSectTermEnd = "),plan)"; + private static $interSectTermEnd = "),plan)"; /** * first part of GeomFromText('Polygon-function * @var string */ - private $polyStartStr = "GeomFromText('Polygon(("; + private static $polyStartStr = "GeomFromText('Polygon(("; /** * last part of GeomFromText('Polygon-function * @var string */ - private $polyEndStr = "))'"; + private static $polyEndStr = "))'"; /** * maximium length of the value-string for an aliasname * @var int */ - private $aliasMaxLenght = 32; + private static $aliasMaxLenght = 32; /** * maximium length of the value-string for a domainname * @var int */ - private $domainMaxLenght = 32; + private static $domainMaxLenght = 32; /** * Default-Constructor @@ -120,9 +120,9 @@ class SpsSqlManager extends SQLManager { } // build query string - $query = $this->selectTerm; + $query = self::$selectTerm; if ($this->validAliasString($alias)) { - $query .= $this->aliasTerm . $this->quoteTerm . $alias . $this->quoteTerm . $this->addDomainTerm($domain); + $query .= self::$aliasTerm . self::$quoteTerm . $alias . self::$quoteTerm . self::$addDomainTerm($domain); } else { return null; } @@ -152,7 +152,7 @@ class SpsSqlManager extends SQLManager { // build query string if ($this->validPolyString($poly)) { - $query = $this->selectTerm . $this->interSectTermStart . $poly . $this->interSectTermEnd . $this->addDomainTerm($domain); + $query = self::$selectTerm . self::$interSectTermStart . $poly . self::$interSectTermEnd . $this->addDomainTerm($domain); } else { return null; } @@ -171,9 +171,9 @@ class SpsSqlManager extends SQLManager { $result = null; if ($domain != null && $this->validDomainString($domain)) { if ($this->isDid($domain)) { - $result .= $this->andTerm . $this->domainTerm . $this->quoteTerm . $domain . $this->quoteTerm; + $result .= self::$andTerm . self::$domainTerm . self::$quoteTerm . $domain . self::$quoteTerm; } else { - $result .= $this->andTerm . $this->domainNameTerm . $this->quoteTerm . $domain . $this->quoteTerm; + $result .= self::$andTerm . self::$domainNameTerm . self::$quoteTerm . $domain . self::$quoteTerm; } } return $result; @@ -185,7 +185,7 @@ class SpsSqlManager extends SQLManager { * @return boolean */ private function validAliasString($alias) { - if (\utiliy\StringManager::validSQLString($alias) && ctype_alnum($alias) && strlen($alias) <= $this->aliasMaxLenght) { + if (\utiliy\StringManager::validSQLString($alias) && ctype_alnum($alias) && strlen($alias) <= self::$aliasMaxLenght) { return TRUE; } return FALSE; @@ -197,7 +197,7 @@ class SpsSqlManager extends SQLManager { * @return boolean */ private function validDomainString($domain) { - if (\utiliy\StringManager::validSQLString($domain) && ctype_alnum($domain) && strlen($domain) <= $this->domainMaxLenght) { + if (\utiliy\StringManager::validSQLString($domain) && ctype_alnum($domain) && strlen($domain) <= self::$domainMaxLenght) { return TRUE; } return FALSE; @@ -209,8 +209,8 @@ class SpsSqlManager extends SQLManager { * @return boolean */ private function validPolyString($poly) { - if (\utiliy\StringManager::validSQLString($poly) && \utiliy\StringManager::startsWith($poly, $this->polyStartStr) - && \utiliy\StringManager::endsWith($poly, $this->polyEndStr)) { + if (\utiliy\StringManager::validSQLString($poly) && \utiliy\StringManager::startsWith($poly, self::$polyStartStr) + && \utiliy\StringManager::endsWith($poly, self::$polyEndStr)) { return TRUE; } return FALSE; diff --git a/geoapi/database/SqlManager.php b/geoapi/database/SqlManager.php index c5a54a9..ddaec35 100644 --- a/geoapi/database/SqlManager.php +++ b/geoapi/database/SqlManager.php @@ -46,19 +46,19 @@ abstract class SqlManager { * String for an and-operrator * @var string */ - protected $andTerm = " and "; + protected static $andTerm = " and "; /** * String for an or-operrator * @var string */ - protected $orTerm = " or "; + protected static $orTerm = " or "; /** * String for quotes in a query * @var string */ - protected $quoteTerm = "\""; + protected static $quoteTerm = "\""; /** * Default-Constructor diff --git a/geoapi/insert/loadcvs.php b/geoapi/insert/loadcvs.php index adbd9ca..79a7e32 100644 --- a/geoapi/insert/loadcvs.php +++ b/geoapi/insert/loadcvs.php @@ -1,4 +1,9 @@ $row[\database\SpsSqlManager::$placeId], - JsonManager::$parentIdName => $row[\database\SpsSqlManager::$parentId]); + $place = array(self::$placeIdName => $row[\database\SpsSqlManager::$placeId], + self::$parentIdName => $row[\database\SpsSqlManager::$parentId]); array_push($places, $place); } return json_encode($places); @@ -72,7 +72,7 @@ class JsonManager implements SerialManager { /** * Method convert an array to a response json for the pis service like - * + * @example [{"id":"127003463","0":{"placeInformationName":"name","placeInformationValue":"Informations-, Kommunikations- und Medienzentrum"},"1":{"placeInformationName":"typ","placeInformationValue":"library"}}] * @param array[num][assoc] $result * @return json-string */ @@ -80,6 +80,8 @@ class JsonManager implements SerialManager { $actPlace = 0; $infos = array(); + $place = null; + foreach ($result as $row) { // fetch the place id of the row @@ -87,16 +89,20 @@ class JsonManager implements SerialManager { // if the id is new -> add new place item if ($actPlace != $placeId) { + if ($place) { + array_push($infos, $place); + } + $actPlace = $placeId; - $place = array(JsonManager::$placeIdName => $placeId); - array_push($infos, $place); + $place = array(self::$placeIdName => $placeId); } // add placeinformation item - $placeInfo = array(JsonManager::$placeInfoName => $row[\database\PisSqlManager::$infName], - JsonManager::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue])); + $placeInfo = array(self::$placeInfoName => $row[\database\PisSqlManager::$infName], self::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue])); array_push($place, $placeInfo); } + + array_push($infos, $place); return json_encode($infos); } @@ -110,6 +116,7 @@ class JsonManager implements SerialManager { $actPlace = 0; $services = array(); + $place = null; foreach ($result as $row) { // fetch the place id of the row @@ -117,30 +124,49 @@ class JsonManager implements SerialManager { // if the id is new -> add new place item if ($actPlace != $placeId) { + if ($place) { + array_push($services, $place); + } + $actPlace = $placeId; - $place = array(JsonManager::$placeIdName => $placeId); - array_push($services, $place); + $place = array(self::$placeIdName => $placeId); } // add placeservice items - $placeSrv = array(JsonManager::$placeServiceName => $row[\database\PisSqlManager::$srvName], - JsonManager::$placeSapName => $row[\database\PisSqlManager::$srvSap], - JsonManager::$placeRequestName => $row[\database\PisSqlManager::$srvRequest]); + $placeSrv = array(self::$placeServiceName => $row[\database\PisSqlManager::$srvName], + self::$placeSapName => $row[\database\PisSqlManager::$srvSap], + self::$placeRequestName => $row[\database\PisSqlManager::$srvRequest]); array_push($place, $placeSrv); } + array_push($services, $place); return json_encode($services); } + /** + * Implement the arrayToSps from @see SerialManager + * @param array [num] [assoc] $result + * @return string + */ public function arrayToSps($result) { - return JsonManager::arrayToSpsJson($result); + return self::arrayToSpsJson($result); } + /** + * Implement the arrayToPss from @see SerialManager + * @param array [num] [assoc] $result + * @return string + */ public function arrayToPss($result) { - return JsonManager::arrayToPssJson($result); + return self::arrayToPssJson($result); } + /** + * Implement the arrayToPis from @see SerialManager + * @param array [num] [assoc] $result + * @return string + */ public function arrayToPis($result) { - return JsonManager::arrayToPisJson($result); + return self::arrayToPisJson($result); } } diff --git a/geoapi/utility/SerialManager.php b/geoapi/utility/SerialManager.php index 55068d6..1979027 100644 --- a/geoapi/utility/SerialManager.php +++ b/geoapi/utility/SerialManager.php @@ -1,15 +1,34 @@ diff --git a/geoapi/utility/XmlManager.php b/geoapi/utility/XmlManager.php index edac86d..c4904cf 100644 --- a/geoapi/utility/XmlManager.php +++ b/geoapi/utility/XmlManager.php @@ -80,12 +80,12 @@ class XmlManager implements SerialManager{ * @return xml-string */ public static function arrayToSpsXml($result) { - $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); + $xml = new \SimpleXMLElement(self::$defaultXmlDoc); foreach ($result as $row) { - $place = $xml->addChild(XmlManager::$placeElementName); - $place->addAttribute(XmlManager::$placeIdAttrName, $row[\database\SpsSqlManager::$placeId]); - $place->addAttribute(XmlManager::$parentIdAttrName, $row[\database\SpsSqlManager::$parentId]); + $place = $xml->addChild(self::$placeElementName); + $place->addAttribute(self::$placeIdAttrName, $row[\database\SpsSqlManager::$placeId]); + $place->addAttribute(self::$parentIdAttrName, $row[\database\SpsSqlManager::$parentId]); } return $xml->asXML(); } @@ -100,7 +100,7 @@ class XmlManager implements SerialManager{ * @return xml-string */ public static function arrayToPisXml($result) { - $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); + $xml = new \SimpleXMLElement(self::$defaultXmlDoc); $actPlace = 0; foreach ($result as $row) { @@ -111,13 +111,13 @@ class XmlManager implements SerialManager{ // if the id is new -> add new place element if ($actPlace != $placeId) { $actPlace = $placeId; - $place = $xml->addChild(XmlManager::$placeElementName); - $place->addAttribute(XmlManager::$placeIdAttrName, $placeId); + $place = $xml->addChild(self::$placeElementName); + $place->addAttribute(self::$placeIdAttrName, $placeId); } // add placeinformation elment - $placeInfo = $place->addChild(XmlManager::$placeInfoElementName, utf8_encode($row[\database\PisSqlManager::$infValue])); - $placeInfo->addAttribute(XmlManager::$placeInfoAttrName, $row[\database\PisSqlManager::$infName]); + $placeInfo = $place->addChild(self::$placeInfoElementName, utf8_encode($row[\database\PisSqlManager::$infValue])); + $placeInfo->addAttribute(self::$placeInfoAttrName, $row[\database\PisSqlManager::$infName]); } return $xml->asXML(); } @@ -135,7 +135,7 @@ class XmlManager implements SerialManager{ * @return xml-string */ public static function arrayToPssXml($result) { - $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); + $xml = new \SimpleXMLElement(self::$defaultXmlDoc); $actPlace = 0; foreach ($result as $row) { @@ -146,29 +146,29 @@ class XmlManager implements SerialManager{ // if the id is new -> add new place element if ($actPlace != $placeId) { $actPlace = $placeId; - $place = $xml->addChild(XmlManager::$placeElementName); - $place->addAttribute(XmlManager::$placeIdAttrName, $placeId); + $place = $xml->addChild(self::$placeElementName); + $place->addAttribute(self::$placeIdAttrName, $placeId); } // add placeservice elment - $placeSrv = $place->addChild(XmlManager::$placeServiceElementName); - $placeSrv->addAttribute(XmlManager::$placeServiceAttrName, $row[\database\PssSqlManager::$srvName]); - $placeSrv->addChild(XmlManager::$placeSapElementName, $row[\database\PssSqlManager::$srvSap]); - $placeSrv->addChild(XmlManager::$placeRequestElementName, $row[\database\PssSqlManager::$srvRequest]); + $placeSrv = $place->addChild(self::$placeServiceElementName); + $placeSrv->addAttribute(self::$placeServiceAttrName, $row[\database\PssSqlManager::$srvName]); + $placeSrv->addChild(self::$placeSapElementName, $row[\database\PssSqlManager::$srvSap]); + $placeSrv->addChild(self::$placeRequestElementName, $row[\database\PssSqlManager::$srvRequest]); } return $xml->asXML(); } public function arrayToSps($result) { - return XmlManager::arrayToSpsXml($result); + return self::arrayToSpsXml($result); } public function arrayToPis($result){ - return XmlManager::arrayToPisXml($result); + return self::arrayToPisXml($result); } public function arrayToPss($result) { - return XmlManager::arrayToPssXml($result); + return self::arrayToPssXml($result); } }