diff --git a/geoapi/api/Api.php b/geoapi/api/Api.php index fa8abc2..9e9848a 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(); /** @@ -21,14 +24,51 @@ abstract class Api extends \Slim\Slim { protected $sqlManager; /** - * Default-Constructor + * Variable for the serialazarion manager of the api + * @var :SqlManager */ - public function __construct() { + 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"; + + /** + * 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 - $this->contentType("Content-type: application/xml;charset=utf-8"); + // 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 { + $this->serialManager = new \utiliy\XmlManager(); + $this->contentType(self::$contentypeXML); + } } /** @@ -36,10 +76,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..9ce27d5 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"; @@ -25,14 +24,15 @@ 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() { + public function __construct($headers = array()) { $this->sqlManager = new \database\PisSqlManager(); - parent::__construct(); + parent::__construct($headers); } /** @@ -49,9 +49,10 @@ 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 \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..a1a071c 100644 --- a/geoapi/api/PssApi.php +++ b/geoapi/api/PssApi.php @@ -25,14 +25,15 @@ 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() { + public function __construct($headers = array()) { $this->sqlManager = new \database\PssSqlManager(); - parent::__construct(); + parent::__construct($headers); } /** @@ -50,9 +51,9 @@ 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 \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..c395a06 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"; /** @@ -72,50 +71,51 @@ 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() { + public function __construct($headers = array()) { $this->sqlManager = new \database\SpsSqlManager(); - parent::__construct(); + parent::__construct($headers); } /** @@ -132,7 +132,7 @@ class SpsApi extends Api { */ public function sendSpsAliasQuery($queryArgs) { $result = $this->sqlManager->sendSpsAliasQuery($queryArgs); - return \utiliy\XmlManager::arrayToSpsXml($result); + return $this->serialManager->arrayToSps($result); } /** @@ -143,22 +143,22 @@ 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); - return \utiliy\XmlManager::arrayToSpsXml($result); + return $this->serialManager->arrayToSps($result); } /** @@ -170,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; } }; @@ -186,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; } }; @@ -205,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 @@ get(\api\PisApi::$routeParameterPids, function ($pid) use ($app) { diff --git a/geoapi/service/pss/index.php b/geoapi/service/pss/index.php index 61bcbab..c6e55cc 100644 --- a/geoapi/service/pss/index.php +++ b/geoapi/service/pss/index.php @@ -3,8 +3,10 @@ include_once "../../global.inc.php"; require_once PATH_API . "/PssApi.php"; +// get reguest header +$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..b4f0c57 100644 --- a/geoapi/service/sps/index.php +++ b/geoapi/service/sps/index.php @@ -3,8 +3,11 @@ include_once "../../global.inc.php"; require_once PATH_API . "/SpsApi.php"; +// get reguest header +$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..7439786 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 @@ -33,7 +34,7 @@ class JsonManager { * Name for the value of the placeInfoName item * @var string */ - private static $placeInfoValueName = "placeInformationName"; + private static $placeInfoValueName = "placeInformationValue"; /** * Name for the placeServiceName item @@ -55,15 +56,15 @@ class JsonManager { /** * Method convert an array to a response json for the sps service - * + * @example [{"id":"121799787","parentId":null}] * @param array[num][assoc] $result * @return json-string */ public static function arrayToSpsJson($result) { $places = array(); foreach ($result as $row) { - $place = array(JsonManager::$placeIdName => $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); @@ -71,7 +72,7 @@ class JsonManager { /** * 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 */ @@ -79,6 +80,8 @@ class JsonManager { $actPlace = 0; $infos = array(); + $place = null; + foreach ($result as $row) { // fetch the place id of the row @@ -86,16 +89,20 @@ class JsonManager { // 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); } @@ -109,6 +116,7 @@ class JsonManager { $actPlace = 0; $services = array(); + $place = null; foreach ($result as $row) { // fetch the place id of the row @@ -116,20 +124,51 @@ class JsonManager { // 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 self::arrayToSpsJson($result); + } + + /** + * Implement the arrayToPss from @see SerialManager + * @param array [num] [assoc] $result + * @return string + */ + public function arrayToPss($result) { + return self::arrayToPssJson($result); + } + + /** + * Implement the arrayToPis from @see SerialManager + * @param array [num] [assoc] $result + * @return string + */ + public function arrayToPis($result) { + return self::arrayToPisJson($result); + } + } ?> diff --git a/geoapi/utility/SerialManager.php b/geoapi/utility/SerialManager.php new file mode 100644 index 0000000..1979027 --- /dev/null +++ b/geoapi/utility/SerialManager.php @@ -0,0 +1,34 @@ + diff --git a/geoapi/utility/XmlManager.php b/geoapi/utility/XmlManager.php index 8465a44..c4904cf 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 @@ -79,12 +80,12 @@ class XmlManager { * @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(); } @@ -99,7 +100,7 @@ class XmlManager { * @return xml-string */ public static function arrayToPisXml($result) { - $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); + $xml = new \SimpleXMLElement(self::$defaultXmlDoc); $actPlace = 0; foreach ($result as $row) { @@ -110,13 +111,13 @@ class XmlManager { // 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(); } @@ -134,7 +135,7 @@ class XmlManager { * @return xml-string */ public static function arrayToPssXml($result) { - $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc); + $xml = new \SimpleXMLElement(self::$defaultXmlDoc); $actPlace = 0; foreach ($result as $row) { @@ -145,18 +146,30 @@ class XmlManager { // 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 self::arrayToSpsXml($result); + } + + public function arrayToPis($result){ + return self::arrayToPisXml($result); + } + + public function arrayToPss($result) { + return self::arrayToPssXml($result); + } }