Merge branch 'release/r#62'

This commit is contained in:
stubbfel
2013-06-26 14:05:25 +02:00
12 changed files with 338 additions and 98 deletions

View File

@@ -5,6 +5,7 @@ namespace api;
include_once "../../global.inc.php"; include_once "../../global.inc.php";
include_once PATH_DATABASE . "/PisSqlManager.php"; include_once PATH_DATABASE . "/PisSqlManager.php";
include_once PATH_UTILITTY . "/XmlManager.php"; include_once PATH_UTILITTY . "/XmlManager.php";
include_once PATH_UTILITTY . "/ArrayManager.php";
require_once PATH_API . "/Api.php"; require_once PATH_API . "/Api.php";
/** /**
@@ -47,28 +48,13 @@ class PisApi extends Api {
* @return query result as xml * @return query result as xml
*/ */
public function sendPisQuery($queryArgs) { public function sendPisQuery($queryArgs) {
$pidList = $this->removeEmptyItmes($queryArgs); $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs);
if (count($pidList) < $this->maxPid) { if (count($pidList) < $this->maxPid) {
$result = $this->sqlManager->sendPisQuery($pidList); $result = $this->sqlManager->sendPisQuery($pidList);
return \utiliy\XmlManager::arrayToPisXml($result); return \utiliy\XmlManager::arrayToPisXml($result);
} }
return NULL; 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
View 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;
}
}
?>

View File

@@ -30,7 +30,7 @@ class SpsApi extends Api {
* Route string for the Longitude paramter * Route string for the Longitude paramter
* @var string * @var string
*/ */
public static $routeParameterLongitude= "/longitude/:longitude"; public static $routeParameterLongitude = "/longitude/:longitude";
/** /**
* Route string for the latitude paramter * Route string for the latitude paramter
@@ -154,8 +154,11 @@ class SpsApi extends Api {
$queryArgs[SpsApi::$keyPoly] = $this->createPolygon($latitude, $longitude, $this->range); $queryArgs[SpsApi::$keyPoly] = $this->createPolygon($latitude, $longitude, $this->range);
$result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs); $result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
if ($result) {
return \utiliy\XmlManager::arrayToSpsXml($result); return \utiliy\XmlManager::arrayToSpsXml($result);
} }
return null;
}
/** /**
* Method check if a string is a valid Longitude * Method check if a string is a valid Longitude

View File

@@ -42,7 +42,7 @@ class PisSqlManager extends SQLManager {
* String for the orderby part of the query * String for the orderby part of the query
* @var string * @var string
*/ */
private $orderByTerm = " ORDER BY pid"; private $orderByTerm = " ORDER BY pid, iName";
/** /**
* String for the pid part of the query * String for the pid part of the query
@@ -73,44 +73,15 @@ class PisSqlManager extends SQLManager {
// build query string // build query string
$query = $this->selectTerm; $query = $this->selectTerm;
if ($this->validPidList($queryArgs)) { if (\utiliy\ArrayManager::validIntList($queryArgs)) {
$query .= $this->createPidWhereString($queryArgs) . $this->orderByTerm; $query .= \utiliy\ArrayManager::toSqlWhereString($queryArgs, $this->orTerm, $this->pidTerm) . $this->orderByTerm;
} else { } else {
return null; return null;
} }
// send query // send query
return $this->query($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;
}
} }
?> ?>

View 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);
}
}
?>

View File

@@ -14,20 +14,6 @@ require_once PATH_DATABASE . "/SqlManager.php";
*/ */
class SpsSqlManager extends SQLManager { class SpsSqlManager extends SQLManager {
/**
* Default-Constructor
*/
public function __construct() {
parent::__construct();
}
/**
* Default-DEConstructor
*/
public function __destruct() {
parent::__destruct();
}
/** /**
* Fieldname of the placeID * Fieldname of the placeID
* @var string * @var string
@@ -100,6 +86,20 @@ class SpsSqlManager extends SQLManager {
*/ */
private $domainMaxLenght = 32; 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 * Methods send an query for the sps-service depends of alias
* @param array $queryArgs * @param array $queryArgs
@@ -185,7 +185,7 @@ class SpsSqlManager extends SQLManager {
* @return boolean * @return boolean
*/ */
private function validAliasString($alias) { 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 TRUE;
} }
return FALSE; return FALSE;
@@ -197,7 +197,7 @@ class SpsSqlManager extends SQLManager {
* @return boolean * @return boolean
*/ */
private function validDomainString($domain) { 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 TRUE;
} }
return FALSE; return FALSE;
@@ -209,7 +209,7 @@ class SpsSqlManager extends SQLManager {
* @return boolean * @return boolean
*/ */
private function validPolyString($poly) { 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 TRUE;
} }
return FALSE; return FALSE;

View File

@@ -129,19 +129,6 @@ abstract class SqlManager {
mysql_free_result($mysqlResult); mysql_free_result($mysqlResult);
return $result; 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;
}
} }
?> ?>

View File

@@ -0,0 +1,2 @@
RewriteEngine on
RewriteRule ^ index.php [QSA,L]

View 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();
?>

View 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;
}
}
?>

View File

@@ -37,6 +37,18 @@ class StringManager {
public static function endsWith($haystack, $needle) { public static function endsWith($haystack, $needle) {
return (substr($haystack, -strlen($needle)) === $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;
}
} }
?> ?>

View File

@@ -15,50 +15,68 @@ class XmlManager {
* a default xml document * a default xml document
* @var xml-string * @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 * Name for the place element
* @var string * @var string
*/ */
public static $placeElementName = "place"; private static $placeElementName = "place";
/** /**
* Name for the placeinformation element * Name for the placeinformation element
* @var string * @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 * Name for the placeInfoName attribute
* @var string * @var string
*/ */
public static $placeInfoName = "placeInformationName"; private static $placeInfoName = "placeInformationName";
/** /**
* Name for the place element * Name for the placeServiceName attribute
* @var string * @var string
*/ */
public static $placeInfoValue = "placeInformationValue"; private static $placeServiceName = "placeServiceName";
/** /**
* Name for the placeid attribute * Name for the placeid attribute
* @var string * @var string
*/ */
public static $placeIdAttrName = "id"; private static $placeIdAttrName = "id";
/** /**
* Name for the parent attribute * Name for the parent attribute
* @var string * @var string
*/ */
public static $parentIdAttrName = "parentId"; private static $parentIdAttrName = "parentId";
/** /**
* Method convert an array to a response xml for the sps service * Method convert an array to a response xml for the sps service
* @param array[num][assoc] $result * @param array[num][assoc] $result
* @return xml-string * @return xml-string
*/ */
public static function arrayToSpsXml($result = array()) { public static function arrayToSpsXml($result) {
$xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc);
foreach ($result as $row) { 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 * @param array[num][assoc] $result
* @return xml-string * @return xml-string
*/ */
public static function arrayToPisXml($result = array()) { public static function arrayToPisXml($result) {
$xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc);
$actPlace = 0; $actPlace = 0;
@@ -97,6 +115,36 @@ class XmlManager {
return $xml->asXML(); 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();
}
} }
?> ?>