Merge branch 'release/r#62'
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
64
geoapi/api/PssApi.php
Normal file
64
geoapi/api/PssApi.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace api;
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
include_once PATH_DATABASE . "/PssSqlManager.php";
|
||||
include_once PATH_UTILITTY . "/XmlManager.php";
|
||||
include_once PATH_UTILITTY . "/ArrayManager.php";
|
||||
require_once PATH_API . "/Api.php";
|
||||
|
||||
/**
|
||||
* This class provides some spezial SpsAPI methods
|
||||
* @author stubbfel
|
||||
* @since 20.06.2013
|
||||
*/
|
||||
class PssApi extends Api {
|
||||
|
||||
/**
|
||||
* Route string for the alias paramter
|
||||
* @var string
|
||||
*/
|
||||
public static $routeParameterPids = "/pid/:pid+";
|
||||
|
||||
/**
|
||||
* max number of pid for each query
|
||||
* @var int
|
||||
*/
|
||||
private $maxPid = 10;
|
||||
|
||||
/**
|
||||
* Default-Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -26,11 +26,11 @@ class SpsApi extends Api {
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
95
geoapi/database/PssSqlManager.php
Normal file
95
geoapi/database/PssSqlManager.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace database;
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
include_once PATH_UTILITTY . "/ArrayManager.php";
|
||||
require_once PATH_DATABASE . "/SqlManager.php";
|
||||
|
||||
/**
|
||||
* Description of ZisSqlManager
|
||||
*
|
||||
* @author stubbfel
|
||||
* @since 20.06.2013
|
||||
*/
|
||||
class PssSqlManager extends SQLManager {
|
||||
|
||||
/**
|
||||
* Fieldname of the placeID
|
||||
* @var string
|
||||
*/
|
||||
public static $placeId = "pid";
|
||||
|
||||
/**
|
||||
* Fieldname of the name of the service
|
||||
* @var string
|
||||
*/
|
||||
public static $srvName = "sName";
|
||||
|
||||
/**
|
||||
* Fieldname of the value of the information
|
||||
* @var string
|
||||
*/
|
||||
public static $srvSap = "sap";
|
||||
|
||||
/**
|
||||
* Fieldname of the value of the information
|
||||
* @var string
|
||||
*/
|
||||
public static $srvRequest = "request";
|
||||
|
||||
/**
|
||||
* String for the select part of the query
|
||||
* @var string
|
||||
*/
|
||||
private $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";
|
||||
|
||||
/**
|
||||
* String for the pid part of the query
|
||||
* @var string
|
||||
*/
|
||||
private $pidTerm = "pid = ";
|
||||
|
||||
/**
|
||||
* Default-Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Default-DEConstructor
|
||||
*/
|
||||
public function __destruct() {
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Methods send an query for the pis-service
|
||||
* @param array $queryArgs
|
||||
* @return array [num][assoc]
|
||||
*/
|
||||
public function sendPssQuery($queryArgs) {
|
||||
|
||||
// build query string
|
||||
$query = $this->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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
2
geoapi/service/pss/.htaccess
Normal file
2
geoapi/service/pss/.htaccess
Normal file
@@ -0,0 +1,2 @@
|
||||
RewriteEngine on
|
||||
RewriteRule ^ index.php [QSA,L]
|
||||
14
geoapi/service/pss/index.php
Normal file
14
geoapi/service/pss/index.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
require_once PATH_API . "/PssApi.php";
|
||||
|
||||
// instance a new api
|
||||
$app = new \api\PssApi();
|
||||
|
||||
$app->get(\api\PssApi::$routeParameterPids, function ($pid) use ($app) {
|
||||
echo $app->sendPssQuery($pid);
|
||||
});
|
||||
|
||||
$app->run();
|
||||
?>
|
||||
58
geoapi/utility/ArrayManager.php
Normal file
58
geoapi/utility/ArrayManager.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace utiliy;
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
include_once PATH_UTILITTY . "/StringManager.php";
|
||||
|
||||
/**
|
||||
* The ArrayManager provides some array-methods
|
||||
* @author stubbfel
|
||||
* @since 26.06.2013
|
||||
*/
|
||||
class ArrayManager {
|
||||
|
||||
/**
|
||||
* Method remove all empty itmes
|
||||
* @param array $queryArgs
|
||||
* @return array
|
||||
*/
|
||||
public static function removeEmptyItmes($array) {
|
||||
foreach ($array as $key => $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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -15,50 +15,68 @@ class XmlManager {
|
||||
* a default xml document
|
||||
* @var xml-string
|
||||
*/
|
||||
public static $defaultXmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
|
||||
private static $defaultXmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
|
||||
|
||||
/**
|
||||
* 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,11 +88,11 @@ 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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user