188 lines
5.6 KiB
PHP
188 lines
5.6 KiB
PHP
<?php
|
|
|
|
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 implements SerialManager {
|
|
|
|
/**
|
|
* a default xml document
|
|
* @var xml-string
|
|
*/
|
|
private static $defaultXmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
|
|
|
|
/**
|
|
* Name for the place element
|
|
* @var string
|
|
*/
|
|
private static $placeElementName = "place";
|
|
|
|
/**
|
|
* Name for the placeinformation element
|
|
* @var string
|
|
*/
|
|
private static $placeInfoElementName = "placeInformation";
|
|
|
|
/**
|
|
* Name for the placeserviceelement
|
|
* @var string
|
|
*/
|
|
private static $placeServiceElementName = "placeService";
|
|
|
|
/**
|
|
* Name for the ssap element
|
|
* @var string
|
|
*/
|
|
private static $placeSapElementName = "sap";
|
|
|
|
/**
|
|
* Name for the request element
|
|
* @var string
|
|
*/
|
|
private static $placeRequestElementName = "request";
|
|
|
|
/**
|
|
* Name for the placeInfoName attribute
|
|
* @var string
|
|
*/
|
|
private static $placeInfoAttrName = "placeInformationName";
|
|
|
|
/**
|
|
* Name for the placeServiceName attribute
|
|
* @var string
|
|
*/
|
|
private static $placeServiceAttrName = "placeServiceName";
|
|
|
|
/**
|
|
* Name for the placeid attribute
|
|
* @var string
|
|
*/
|
|
private static $placeIdAttrName = "id";
|
|
|
|
/**
|
|
* Name for the parent attribute
|
|
* @var string
|
|
*/
|
|
private static $parentIdAttrName = "parentId";
|
|
|
|
/**
|
|
* Name for the refpoint attribute
|
|
* @var string
|
|
*/
|
|
private static $refpointAttrName = "refpoint";
|
|
|
|
/**
|
|
* Method convert an array to a response xml for the sps service
|
|
* <place id ="4711" parentID=%0815"/>
|
|
*
|
|
* @param array[num][assoc] $result
|
|
* @return xml-string
|
|
*/
|
|
public static function arrayToSpsXml($result) {
|
|
$xml = new \SimpleXMLElement(self::$defaultXmlDoc);
|
|
|
|
foreach ($result as $row) {
|
|
$place = $xml->addChild(self::$placeElementName);
|
|
$place->addAttribute(self::$placeIdAttrName, $row[\database\SpsSqlManager::$placeId]);
|
|
$place->addAttribute(self::$parentIdAttrName, $row[\database\SpsSqlManager::$parentId]);
|
|
$place->addAttribute(self::$refpointAttrName, $row[\database\SpsSqlManager::$refpoint]);
|
|
}
|
|
return $xml->asXML();
|
|
}
|
|
|
|
/**
|
|
* Method convert an array to a response xml for the pis service like
|
|
* <place id ="4711">
|
|
* <placeInformation placeInformationName = "key">Value</placeinformation>
|
|
* </place>
|
|
*
|
|
* @param array[num][assoc] $result
|
|
* @return xml-string
|
|
*/
|
|
public static function arrayToPisXml($result) {
|
|
$xml = new \SimpleXMLElement(self::$defaultXmlDoc);
|
|
$actPlace = 0;
|
|
|
|
foreach ($result as $row) {
|
|
|
|
// fetch the place id of the row
|
|
$placeId = $row[\database\PisSqlManager::$placeId];
|
|
|
|
// if the id is new -> add new place element
|
|
if ($actPlace != $placeId) {
|
|
$actPlace = $placeId;
|
|
$place = $xml->addChild(self::$placeElementName);
|
|
$place->addAttribute(self::$placeIdAttrName, $placeId);
|
|
$place->addAttribute(self::$parentIdAttrName, $row[\database\PisSqlManager::$parentId]);
|
|
$place->addAttribute(self::$refpointAttrName, $row[\database\PisSqlManager::$refpoint]);
|
|
}
|
|
|
|
// add placeinformation elment
|
|
$placeInfo = $place->addChild(self::$placeInfoElementName, utf8_encode($row[\database\PisSqlManager::$infValue]));
|
|
$placeInfo->addAttribute(self::$placeInfoAttrName, $row[\database\PisSqlManager::$infName]);
|
|
}
|
|
return $xml->asXML();
|
|
}
|
|
|
|
/**
|
|
* Method convert an array to a response xml for the pss service
|
|
* <place id ="4711">
|
|
* <placeService placeServiceName = "key">
|
|
* <sap>sapValue</sap>
|
|
* <request>reqVaule</request>
|
|
* </placeService>
|
|
* </place>
|
|
*
|
|
* @param array[num][assoc] $result
|
|
* @return xml-string
|
|
*/
|
|
public static function arrayToPssXml($result) {
|
|
$xml = new \SimpleXMLElement(self::$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(self::$placeElementName);
|
|
$place->addAttribute(self::$placeIdAttrName, $placeId);
|
|
$place->addAttribute(self::$parentIdAttrName, $row[\database\PssSqlManager::$parentId]);
|
|
$place->addAttribute(self::$refpointAttrName, $row[\database\PssSqlManager::$refpoint]);
|
|
}
|
|
|
|
// add placeservice elment
|
|
$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);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|