103 lines
2.8 KiB
PHP
103 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace utiliy;
|
|
|
|
include_once "../../global.inc.php";
|
|
|
|
/**
|
|
* The XmlManager provides some xml-methods
|
|
* @author stubbfel
|
|
* @since 25.06.2013
|
|
*/
|
|
class XmlManager {
|
|
|
|
/**
|
|
* a default xml document
|
|
* @var xml-string
|
|
*/
|
|
public static $defaultXmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
|
|
|
|
/**
|
|
* Name for the place element
|
|
* @var string
|
|
*/
|
|
public static $placeElementName = "place";
|
|
|
|
/**
|
|
* Name for the placeinformation element
|
|
* @var string
|
|
*/
|
|
public static $placeInfoElementName = "placeInformation";
|
|
|
|
/**
|
|
* Name for the placeInfoName attribute
|
|
* @var string
|
|
*/
|
|
public static $placeInfoName = "placeInformationName";
|
|
|
|
/**
|
|
* Name for the place element
|
|
* @var string
|
|
*/
|
|
public static $placeInfoValue = "placeInformationValue";
|
|
|
|
/**
|
|
* Name for the placeid attribute
|
|
* @var string
|
|
*/
|
|
public static $placeIdAttrName = "id";
|
|
|
|
/**
|
|
* Name for the parent attribute
|
|
* @var string
|
|
*/
|
|
public 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()) {
|
|
$xml = new \SimpleXMLElement(XmlManager::$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]);
|
|
}
|
|
return $xml->asXML();
|
|
}
|
|
|
|
/**
|
|
* Method convert an array to a response xml for the sps service
|
|
* @param array[num][assoc] $result
|
|
* @return xml-string
|
|
*/
|
|
public static function arrayToPisXml($result = array()) {
|
|
$xml = new \SimpleXMLElement(XmlManager::$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(XmlManager::$placeElementName);
|
|
$place->addAttribute(XmlManager::$placeIdAttrName, $placeId);
|
|
}
|
|
|
|
// add placeinformation elment
|
|
$placeInfo = $place->addChild(XmlManager::$placeInfoElementName, utf8_encode($row[\database\PisSqlManager::$infValue]));
|
|
$placeInfo->addAttribute(XmlManager::$placeInfoName, $row[\database\PisSqlManager::$infName]);
|
|
}
|
|
return $xml->asXML();
|
|
}
|
|
|
|
}
|
|
|
|
?>
|