This commit is contained in:
stubbfel
2013-07-01 18:54:59 +02:00
parent aa03fdcd1b
commit 7851ee7e3b
15 changed files with 177 additions and 97 deletions

View File

@@ -28,18 +28,41 @@ abstract class Api extends \Slim\Slim {
* @var <T>:SqlManager * @var <T>:SqlManager
*/ */
protected $serialManager; protected $serialManager;
/**
* Variable for the contentype of XML
* @var string
*/
protected static $contentypeXML = "application/xml;charset=utf-8"; protected static $contentypeXML = "application/xml;charset=utf-8";
/**
* Variable for the contentype of Json
* @var string
*/
protected static $contentypeJson = "application/json;charset=utf-8"; protected static $contentypeJson = "application/json;charset=utf-8";
/** /**
* Default-Constructor * Variable for the regexstring 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()) { public function __construct($headers = array()) {
$this->connect(); $this->connect();
parent::__construct(); parent::__construct();
// set content type td xml // set content type
if ($headers && preg_match('/json/', $headers["Accept"])) { if ($headers && array_key_exists(self::$keyReqHeaderAccept, $headers) && preg_match(self::$jsonRegStr, $headers[self::$keyReqHeaderAccept])) {
$this->serialManager = new \utiliy\JsonManager(); $this->serialManager = new \utiliy\JsonManager();
$this->contentType(self::$contentypeJson); $this->contentType(self::$contentypeJson);
} else { } else {

View File

@@ -24,10 +24,11 @@ class PisApi extends Api {
* max number of pid for each query * max number of pid for each query
* @var int * @var int
*/ */
private $maxPid = 10; private static $maxPid = 10;
/** /**
* Default-Constructor * Constructor
* @param array[assoc] $headers - RequestHeader
*/ */
public function __construct($headers = array()) { public function __construct($headers = array()) {
$this->sqlManager = new \database\PisSqlManager(); $this->sqlManager = new \database\PisSqlManager();
@@ -48,7 +49,7 @@ class PisApi extends Api {
*/ */
public function sendPisQuery($queryArgs) { public function sendPisQuery($queryArgs) {
$pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs); $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs);
if (count($pidList) < $this->maxPid) { if (count($pidList) < self::$maxPid) {
$result = $this->sqlManager->sendPisQuery($pidList); $result = $this->sqlManager->sendPisQuery($pidList);
return $this->serialManager->arrayToPis($result); return $this->serialManager->arrayToPis($result);

View File

@@ -25,10 +25,11 @@ class PssApi extends Api {
* max number of pid for each query * max number of pid for each query
* @var int * @var int
*/ */
private $maxPid = 10; private static $maxPid = 10;
/** /**
* Default-Constructor * Constructor
* @param array[assoc] $headers - RequestHeader
*/ */
public function __construct($headers = array()) { public function __construct($headers = array()) {
$this->sqlManager = new \database\PssSqlManager(); $this->sqlManager = new \database\PssSqlManager();
@@ -50,7 +51,7 @@ class PssApi extends Api {
public function sendPssQuery($queryArgs) { public function sendPssQuery($queryArgs) {
$pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs); $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs);
if (count($pidList) < $this->maxPid) { if (count($pidList) < self::$maxPid) {
$result = $this->sqlManager->sendPssQuery($pidList); $result = $this->sqlManager->sendPssQuery($pidList);
return $this->serialManager->arrayTopis($result); return $this->serialManager->arrayTopis($result);
} }

View File

@@ -71,46 +71,47 @@ class SpsApi extends Api {
* Varible for the range of the searchpolygon * Varible for the range of the searchpolygon
* @var float * @var float
*/ */
private $range = 1; private static $range = 1;
/* /*
* Varible for the fist chars of the string for a Polygon * Varible for the fist chars of the string for a Polygon
* @var string * @var string
*/ */
private $polyStartStr = "GeomFromText('Polygon(("; private static $polyStartStr = "GeomFromText('Polygon((";
/* /*
* Varible for the last chars of the string for a Polygon * Varible for the last chars of the string for a Polygon
* @var string * @var string
*/ */
private $polyEndStr = "))'"; private static $polyEndStr = "))'";
/** /**
* maximum value of latitude * maximum value of latitude
* @var float * @var float
*/ */
private $maxLat = 180; private static $maxLat = 180;
/** /**
* minimum value of latitude * minimum value of latitude
* @var float * @var float
*/ */
private $minLat = -180; private static $minLat = -180;
/** /**
* maximum value of longitude * maximum value of longitude
* @var float * @var float
*/ */
private $maxLong = 180; private static $maxLong = 180;
/** /**
* minimum value of longitude * minimum value of longitude
* @var float * @var float
*/ */
private $minLong = -180; private static $minLong = -180;
/** /**
* Default-Constructor * Constructor
* @param array[assoc] $headers - RequestHeader
*/ */
public function __construct($headers = array()) { public function __construct($headers = array()) {
$this->sqlManager = new \database\SpsSqlManager(); $this->sqlManager = new \database\SpsSqlManager();
@@ -142,18 +143,18 @@ class SpsApi extends Api {
public function sendSpsCoordinateQuery($queryArgs) { public function sendSpsCoordinateQuery($queryArgs) {
// check arguments of the query // 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; return null;
} }
$latitude = $queryArgs[SpsApi::$keyLat]; $latitude = $queryArgs[self::$keyLat];
$longitude = $queryArgs[SpsApi::$keyLong]; $longitude = $queryArgs[self::$keyLong];
if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) { if (!$this->validLatitude($latitude) || !$this->validLongitude($longitude)) {
return null; return null;
} }
// build a request polygon // build a request polygon
$queryArgs[SpsApi::$keyPoly] = $this->createPolygon($latitude, $longitude, $this->range); $queryArgs[self::$keyPoly] = $this->createPolygon($latitude, $longitude, self::$range);
// send querry // send querry
$result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs); $result = $this->sqlManager->sendSpsCoordinateQuery($queryArgs);
@@ -169,7 +170,7 @@ class SpsApi extends Api {
$digitLessPoint = str_replace(".", "", $string); $digitLessPoint = str_replace(".", "", $string);
$digit = str_replace("-", "", $digitLessPoint); $digit = str_replace("-", "", $digitLessPoint);
if (ctype_digit($digit)) { if (ctype_digit($digit)) {
if ($string <= $this->maxLong && $string >= $this->minLong) { if ($string <= self::$maxLong && $string >= self::$minLong) {
return TRUE; return TRUE;
} }
}; };
@@ -185,7 +186,7 @@ class SpsApi extends Api {
$digitLessPoint = str_replace(".", "", $string); $digitLessPoint = str_replace(".", "", $string);
$digit = str_replace("-", "", $digitLessPoint); $digit = str_replace("-", "", $digitLessPoint);
if (ctype_digit($digit)) { if (ctype_digit($digit)) {
if ($string <= $this->maxLat && $string >= $this->minLat) { if ($string <= self::$maxLat && $string >= self::$minLat) {
return TRUE; return TRUE;
} }
}; };
@@ -204,7 +205,7 @@ class SpsApi extends Api {
$minLong = $longitude - $range; $minLong = $longitude - $range;
$maxLat = $latitude + $range; $maxLat = $latitude + $range;
$maxLong = $longitude + $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;
} }
} }

View File

@@ -36,19 +36,19 @@ class PisSqlManager extends SQLManager {
* String for the select part of the query * String for the select part of the query
* @var string * @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 * String for the orderby part of the query
* @var string * @var string
*/ */
private $orderByTerm = " ORDER BY pid, iName"; private static $orderByTerm = " ORDER BY pid, iName";
/** /**
* String for the pid part of the query * String for the pid part of the query
* @var string * @var string
*/ */
private $pidTerm = "pid = "; private static $pidTerm = "pid = ";
/** /**
* Default-Constructor * Default-Constructor
@@ -72,9 +72,9 @@ class PisSqlManager extends SQLManager {
public function sendPisQuery($queryArgs) { public function sendPisQuery($queryArgs) {
// build query string // build query string
$query = $this->selectTerm; $query = self::$selectTerm;
if (\utiliy\ArrayManager::validIntList($queryArgs)) { 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 { } else {
return null; return null;
} }

View File

@@ -42,19 +42,19 @@ class PssSqlManager extends SQLManager {
* String for the select part of the query * String for the select part of the query
* @var string * @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 * String for the orderby part of the query
* @var string * @var string
*/ */
private $orderByTerm = " ORDER BY pid, sName"; private static $orderByTerm = " ORDER BY pid, sName";
/** /**
* String for the pid part of the query * String for the pid part of the query
* @var string * @var string
*/ */
private $pidTerm = "pid = "; private static $pidTerm = "pid = ";
/** /**
* Default-Constructor * Default-Constructor
@@ -78,10 +78,10 @@ class PssSqlManager extends SQLManager {
public function sendPssQuery($queryArgs) { public function sendPssQuery($queryArgs) {
// build query string // build query string
$query = $this->selectTerm; $query = self::$selectTerm;
if (\utiliy\ArrayManager::validIntList($queryArgs)) { 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 { } else {
return null; return null;
}; };

View File

@@ -30,61 +30,61 @@ class SpsSqlManager extends SQLManager {
* String for the select part of the query * String for the select part of the query
* @var string * @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 * String for the alias part of the query
* @var string * @var string
*/ */
private $aliasTerm = "alias = "; private static $aliasTerm = "alias = ";
/** /**
* String for the did part of the query * String for the did part of the query
* @var string * @var string
*/ */
private $domainTerm = "did = "; private static $domainTerm = "did = ";
/** /**
* String for the dNamet part of the query * String for the dNamet part of the query
* @var string * @var string
*/ */
private $domainNameTerm = "dName = "; private static $domainNameTerm = "dName = ";
/** /**
* first part of intersect-function * first part of intersect-function
* @var string * @var string
*/ */
private $interSectTermStart = "Intersects("; private static $interSectTermStart = "Intersects(";
/** /**
* last part of intersect-function * last part of intersect-function
* @var string * @var string
*/ */
private $interSectTermEnd = "),plan)"; private static $interSectTermEnd = "),plan)";
/** /**
* first part of GeomFromText('Polygon-function * first part of GeomFromText('Polygon-function
* @var string * @var string
*/ */
private $polyStartStr = "GeomFromText('Polygon(("; private static $polyStartStr = "GeomFromText('Polygon((";
/** /**
* last part of GeomFromText('Polygon-function * last part of GeomFromText('Polygon-function
* @var string * @var string
*/ */
private $polyEndStr = "))'"; private static $polyEndStr = "))'";
/** /**
* maximium length of the value-string for an aliasname * maximium length of the value-string for an aliasname
* @var int * @var int
*/ */
private $aliasMaxLenght = 32; private static $aliasMaxLenght = 32;
/** /**
* maximium length of the value-string for a domainname * maximium length of the value-string for a domainname
* @var int * @var int
*/ */
private $domainMaxLenght = 32; private static $domainMaxLenght = 32;
/** /**
* Default-Constructor * Default-Constructor
@@ -120,9 +120,9 @@ class SpsSqlManager extends SQLManager {
} }
// build query string // build query string
$query = $this->selectTerm; $query = self::$selectTerm;
if ($this->validAliasString($alias)) { 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 { } else {
return null; return null;
} }
@@ -152,7 +152,7 @@ class SpsSqlManager extends SQLManager {
// build query string // build query string
if ($this->validPolyString($poly)) { 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 { } else {
return null; return null;
} }
@@ -171,9 +171,9 @@ class SpsSqlManager extends SQLManager {
$result = null; $result = null;
if ($domain != null && $this->validDomainString($domain)) { if ($domain != null && $this->validDomainString($domain)) {
if ($this->isDid($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 { } else {
$result .= $this->andTerm . $this->domainNameTerm . $this->quoteTerm . $domain . $this->quoteTerm; $result .= self::$andTerm . self::$domainNameTerm . self::$quoteTerm . $domain . self::$quoteTerm;
} }
} }
return $result; return $result;
@@ -185,7 +185,7 @@ class SpsSqlManager extends SQLManager {
* @return boolean * @return boolean
*/ */
private function validAliasString($alias) { 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 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 (\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 TRUE;
} }
return FALSE; return FALSE;
@@ -209,8 +209,8 @@ class SpsSqlManager extends SQLManager {
* @return boolean * @return boolean
*/ */
private function validPolyString($poly) { private function validPolyString($poly) {
if (\utiliy\StringManager::validSQLString($poly) && \utiliy\StringManager::startsWith($poly, $this->polyStartStr) if (\utiliy\StringManager::validSQLString($poly) && \utiliy\StringManager::startsWith($poly, self::$polyStartStr)
&& \utiliy\StringManager::endsWith($poly, $this->polyEndStr)) { && \utiliy\StringManager::endsWith($poly, self::$polyEndStr)) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;

View File

@@ -46,19 +46,19 @@ abstract class SqlManager {
* String for an and-operrator * String for an and-operrator
* @var string * @var string
*/ */
protected $andTerm = " and "; protected static $andTerm = " and ";
/** /**
* String for an or-operrator * String for an or-operrator
* @var string * @var string
*/ */
protected $orTerm = " or "; protected static $orTerm = " or ";
/** /**
* String for quotes in a query * String for quotes in a query
* @var string * @var string
*/ */
protected $quoteTerm = "\""; protected static $quoteTerm = "\"";
/** /**
* Default-Constructor * Default-Constructor

View File

@@ -1,4 +1,9 @@
<?php <?php
/**
* this script create from a csv the insertstatements
* @author stubbfel
* @since 01.07.2013
*/
if (($handle = fopen("campustest.csv", "r")) !== FALSE) { if (($handle = fopen("campustest.csv", "r")) !== FALSE) {
$firstRow = true; $firstRow = true;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {

View File

@@ -3,6 +3,7 @@
include_once "../../global.inc.php"; include_once "../../global.inc.php";
require_once PATH_API . "/PisApi.php"; require_once PATH_API . "/PisApi.php";
// get reguest header
$headers = apache_request_headers(); $headers = apache_request_headers();
// instance a new api // instance a new api
$app = new \api\PisApi($headers); $app = new \api\PisApi($headers);

View File

@@ -3,6 +3,7 @@
include_once "../../global.inc.php"; include_once "../../global.inc.php";
require_once PATH_API . "/PssApi.php"; require_once PATH_API . "/PssApi.php";
// get reguest header
$headers = apache_request_headers(); $headers = apache_request_headers();
// instance a new api // instance a new api
$app = new \api\PssApi($headers); $app = new \api\PssApi($headers);

View File

@@ -2,6 +2,8 @@
include_once "../../global.inc.php"; include_once "../../global.inc.php";
require_once PATH_API . "/SpsApi.php"; require_once PATH_API . "/SpsApi.php";
// get reguest header
$headers = apache_request_headers(); $headers = apache_request_headers();
// instance a new api // instance a new api

View File

@@ -34,7 +34,7 @@ class JsonManager implements SerialManager {
* Name for the value of the placeInfoName item * Name for the value of the placeInfoName item
* @var string * @var string
*/ */
private static $placeInfoValueName = "placeInformationName"; private static $placeInfoValueName = "placeInformationValue";
/** /**
* Name for the placeServiceName item * Name for the placeServiceName item
@@ -56,15 +56,15 @@ class JsonManager implements SerialManager {
/** /**
* Method convert an array to a response json for the sps service * Method convert an array to a response json for the sps service
* * @example [{"id":"121799787","parentId":null}]
* @param array[num][assoc] $result * @param array[num][assoc] $result
* @return json-string * @return json-string
*/ */
public static function arrayToSpsJson($result) { public static function arrayToSpsJson($result) {
$places = array(); $places = array();
foreach ($result as $row) { foreach ($result as $row) {
$place = array(JsonManager::$placeIdName => $row[\database\SpsSqlManager::$placeId], $place = array(self::$placeIdName => $row[\database\SpsSqlManager::$placeId],
JsonManager::$parentIdName => $row[\database\SpsSqlManager::$parentId]); self::$parentIdName => $row[\database\SpsSqlManager::$parentId]);
array_push($places, $place); array_push($places, $place);
} }
return json_encode($places); 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 * 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 * @param array[num][assoc] $result
* @return json-string * @return json-string
*/ */
@@ -80,6 +80,8 @@ class JsonManager implements SerialManager {
$actPlace = 0; $actPlace = 0;
$infos = array(); $infos = array();
$place = null;
foreach ($result as $row) { foreach ($result as $row) {
// fetch the place id of the 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 the id is new -> add new place item
if ($actPlace != $placeId) { if ($actPlace != $placeId) {
$actPlace = $placeId; if ($place) {
$place = array(JsonManager::$placeIdName => $placeId);
array_push($infos, $place); array_push($infos, $place);
} }
$actPlace = $placeId;
$place = array(self::$placeIdName => $placeId);
}
// add placeinformation item // add placeinformation item
$placeInfo = array(JsonManager::$placeInfoName => $row[\database\PisSqlManager::$infName], $placeInfo = array(self::$placeInfoName => $row[\database\PisSqlManager::$infName], self::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue]));
JsonManager::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue]));
array_push($place, $placeInfo); array_push($place, $placeInfo);
} }
array_push($infos, $place);
return json_encode($infos); return json_encode($infos);
} }
@@ -110,6 +116,7 @@ class JsonManager implements SerialManager {
$actPlace = 0; $actPlace = 0;
$services = array(); $services = array();
$place = null;
foreach ($result as $row) { foreach ($result as $row) {
// fetch the place id of the 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 the id is new -> add new place item
if ($actPlace != $placeId) { if ($actPlace != $placeId) {
$actPlace = $placeId; if ($place) {
$place = array(JsonManager::$placeIdName => $placeId);
array_push($services, $place); array_push($services, $place);
} }
$actPlace = $placeId;
$place = array(self::$placeIdName => $placeId);
}
// add placeservice items // add placeservice items
$placeSrv = array(JsonManager::$placeServiceName => $row[\database\PisSqlManager::$srvName], $placeSrv = array(self::$placeServiceName => $row[\database\PisSqlManager::$srvName],
JsonManager::$placeSapName => $row[\database\PisSqlManager::$srvSap], self::$placeSapName => $row[\database\PisSqlManager::$srvSap],
JsonManager::$placeRequestName => $row[\database\PisSqlManager::$srvRequest]); self::$placeRequestName => $row[\database\PisSqlManager::$srvRequest]);
array_push($place, $placeSrv); array_push($place, $placeSrv);
} }
array_push($services, $place);
return json_encode($services); return json_encode($services);
} }
/**
* Implement the arrayToSps from @see SerialManager
* @param array [num] [assoc] $result
* @return string
*/
public function arrayToSps($result) { 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) { 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) { public function arrayToPis($result) {
return JsonManager::arrayToPisJson($result); return self::arrayToPisJson($result);
} }
} }

View File

@@ -1,14 +1,33 @@
<?php <?php
namespace utiliy; namespace utiliy;
/** /**
* * This is an Interface for the serialpation from sql-result to formatted string
* @author stubbfel * @author stubbfel
* @since 01.07.2013
*/ */
interface SerialManager { interface SerialManager {
/**
* Convert an array from the SPS to a formatted string
* @param array [num] [assoc] $result
* @return string
*/
public function arrayToSps($result); public function arrayToSps($result);
/**
* Convert an array from the PIS to a formatted string
* @param array [num] [assoc] $result
* @return string
*/
public function arrayToPis($result); public function arrayToPis($result);
/**
* Convert an array from the PSS to a formatted string
* @param array [num] [assoc] $result
* @return string
*/
public function arrayToPss($result); public function arrayToPss($result);
} }

View File

@@ -80,12 +80,12 @@ class XmlManager implements SerialManager{
* @return xml-string * @return xml-string
*/ */
public static function arrayToSpsXml($result) { public static function arrayToSpsXml($result) {
$xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); $xml = new \SimpleXMLElement(self::$defaultXmlDoc);
foreach ($result as $row) { foreach ($result as $row) {
$place = $xml->addChild(XmlManager::$placeElementName); $place = $xml->addChild(self::$placeElementName);
$place->addAttribute(XmlManager::$placeIdAttrName, $row[\database\SpsSqlManager::$placeId]); $place->addAttribute(self::$placeIdAttrName, $row[\database\SpsSqlManager::$placeId]);
$place->addAttribute(XmlManager::$parentIdAttrName, $row[\database\SpsSqlManager::$parentId]); $place->addAttribute(self::$parentIdAttrName, $row[\database\SpsSqlManager::$parentId]);
} }
return $xml->asXML(); return $xml->asXML();
} }
@@ -100,7 +100,7 @@ class XmlManager implements SerialManager{
* @return xml-string * @return xml-string
*/ */
public static function arrayToPisXml($result) { public static function arrayToPisXml($result) {
$xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); $xml = new \SimpleXMLElement(self::$defaultXmlDoc);
$actPlace = 0; $actPlace = 0;
foreach ($result as $row) { foreach ($result as $row) {
@@ -111,13 +111,13 @@ class XmlManager implements SerialManager{
// if the id is new -> add new place element // if the id is new -> add new place element
if ($actPlace != $placeId) { if ($actPlace != $placeId) {
$actPlace = $placeId; $actPlace = $placeId;
$place = $xml->addChild(XmlManager::$placeElementName); $place = $xml->addChild(self::$placeElementName);
$place->addAttribute(XmlManager::$placeIdAttrName, $placeId); $place->addAttribute(self::$placeIdAttrName, $placeId);
} }
// add placeinformation elment // add placeinformation elment
$placeInfo = $place->addChild(XmlManager::$placeInfoElementName, utf8_encode($row[\database\PisSqlManager::$infValue])); $placeInfo = $place->addChild(self::$placeInfoElementName, utf8_encode($row[\database\PisSqlManager::$infValue]));
$placeInfo->addAttribute(XmlManager::$placeInfoAttrName, $row[\database\PisSqlManager::$infName]); $placeInfo->addAttribute(self::$placeInfoAttrName, $row[\database\PisSqlManager::$infName]);
} }
return $xml->asXML(); return $xml->asXML();
} }
@@ -135,7 +135,7 @@ class XmlManager implements SerialManager{
* @return xml-string * @return xml-string
*/ */
public static function arrayToPssXml($result) { public static function arrayToPssXml($result) {
$xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); $xml = new \SimpleXMLElement(self::$defaultXmlDoc);
$actPlace = 0; $actPlace = 0;
foreach ($result as $row) { foreach ($result as $row) {
@@ -146,29 +146,29 @@ class XmlManager implements SerialManager{
// if the id is new -> add new place element // if the id is new -> add new place element
if ($actPlace != $placeId) { if ($actPlace != $placeId) {
$actPlace = $placeId; $actPlace = $placeId;
$place = $xml->addChild(XmlManager::$placeElementName); $place = $xml->addChild(self::$placeElementName);
$place->addAttribute(XmlManager::$placeIdAttrName, $placeId); $place->addAttribute(self::$placeIdAttrName, $placeId);
} }
// add placeservice elment // add placeservice elment
$placeSrv = $place->addChild(XmlManager::$placeServiceElementName); $placeSrv = $place->addChild(self::$placeServiceElementName);
$placeSrv->addAttribute(XmlManager::$placeServiceAttrName, $row[\database\PssSqlManager::$srvName]); $placeSrv->addAttribute(self::$placeServiceAttrName, $row[\database\PssSqlManager::$srvName]);
$placeSrv->addChild(XmlManager::$placeSapElementName, $row[\database\PssSqlManager::$srvSap]); $placeSrv->addChild(self::$placeSapElementName, $row[\database\PssSqlManager::$srvSap]);
$placeSrv->addChild(XmlManager::$placeRequestElementName, $row[\database\PssSqlManager::$srvRequest]); $placeSrv->addChild(self::$placeRequestElementName, $row[\database\PssSqlManager::$srvRequest]);
} }
return $xml->asXML(); return $xml->asXML();
} }
public function arrayToSps($result) { public function arrayToSps($result) {
return XmlManager::arrayToSpsXml($result); return self::arrayToSpsXml($result);
} }
public function arrayToPis($result){ public function arrayToPis($result){
return XmlManager::arrayToPisXml($result); return self::arrayToPisXml($result);
} }
public function arrayToPss($result) { public function arrayToPss($result) {
return XmlManager::arrayToPssXml($result); return self::arrayToPssXml($result);
} }
} }