Overview

Namespaces

  • api
  • config
  • database
  • PHP
  • Slim
    • Exception
    • Http
    • Middleware
  • utiliy

Classes

  • ArrayManager
  • StringManager
  • XmlManager
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace utiliy;
  4: 
  5: include_once "../../global.inc.php";
  6: 
  7: /**
  8:  * The XmlManager provides some xml-methods
  9:  * @author stubbfel
 10:  * @since 25.06.2013
 11:  */
 12: class XmlManager {
 13: 
 14:     /**
 15:      * a default xml document
 16:      * @var xml-string
 17:      */
 18:     private static $defaultXmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
 19: 
 20:     /**
 21:      * Name for the place element
 22:      * @var string
 23:      */
 24:     private static $placeElementName = "place";
 25: 
 26:     /**
 27:      * Name for the placeinformation element
 28:      * @var string
 29:      */
 30:     private static $placeInfoElementName = "placeInformation";
 31: 
 32:     /**
 33:      * Name for the placeserviceelement
 34:      * @var string
 35:      */
 36:     private static $placeServiceElementName = "placeService";
 37: 
 38:     /**
 39:      * Name for the ssap element
 40:      * @var string
 41:      */
 42:     private static $placeSapElementName = "sap";
 43: 
 44:     /**
 45:      * Name for the request element
 46:      * @var string
 47:      */
 48:     private static $placeRequestElementName = "request";
 49: 
 50:     /**
 51:      * Name for the placeInfoName attribute
 52:      * @var string
 53:      */
 54:     private static $placeInfoAttrName = "placeInformationName";
 55: 
 56:     /**
 57:      * Name for the placeServiceName  attribute
 58:      * @var string
 59:      */
 60:     private static $placeServiceAttrName = "placeServiceName";
 61: 
 62:     /**
 63:      * Name for the placeid attribute
 64:      * @var string
 65:      */
 66:     private static $placeIdAttrName = "id";
 67: 
 68:     /**
 69:      * Name for the parent attribute
 70:      * @var string
 71:      */
 72:     private static $parentIdAttrName = "parentId";
 73: 
 74:     /**
 75:      * Method convert an array to a response xml for the sps service
 76:      * <place id ="4711" parentID=%0815"/>
 77:      * 
 78:      * @param array[num][assoc] $result
 79:      * @return xml-string
 80:      */
 81:     public static function arrayToSpsXml($result) {
 82:         $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc);
 83: 
 84:         foreach ($result as $row) {
 85:             $place = $xml->addChild(XmlManager::$placeElementName);
 86:             $place->addAttribute(XmlManager::$placeIdAttrName, $row[\database\SpsSqlManager::$placeId]);
 87:             $place->addAttribute(XmlManager::$parentIdAttrName, $row[\database\SpsSqlManager::$parentId]);
 88:         }
 89:         return $xml->asXML();
 90:     }
 91: 
 92:     /**
 93:      * Method convert an array to a response xml for the pis service like
 94:      * <place id ="4711">
 95:      * <placeInformation placeInformationName = "key">Value</placeinformation>
 96:      * </place>
 97:      * 
 98:      * @param array[num][assoc] $result
 99:      * @return xml-string
100:      */
101:     public static function arrayToPisXml($result) {
102:         $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc);
103:         $actPlace = 0;
104: 
105:         foreach ($result as $row) {
106: 
107:             // fetch  the place id of the row
108:             $placeId = $row[\database\PisSqlManager::$placeId];
109: 
110:             // if the id is new -> add new place element
111:             if ($actPlace != $placeId) {
112:                 $actPlace = $placeId;
113:                 $place = $xml->addChild(XmlManager::$placeElementName);
114:                 $place->addAttribute(XmlManager::$placeIdAttrName, $placeId);
115:             }
116: 
117:             // add placeinformation elment
118:             $placeInfo = $place->addChild(XmlManager::$placeInfoElementName, utf8_encode($row[\database\PisSqlManager::$infValue]));
119:             $placeInfo->addAttribute(XmlManager::$placeInfoAttrName, $row[\database\PisSqlManager::$infName]);
120:         }
121:         return $xml->asXML();
122:     }
123: 
124:     /**
125:      * Method convert an array to a response xml for the pss service
126:      * <place id ="4711">
127:      * <placeService placeServiceName = "key">
128:      * <sap>sapValue</sap>
129:      * <request>reqVaule</request>
130:      * </placeService>
131:      * </place>
132:      * 
133:      * @param array[num][assoc] $result
134:      * @return xml-string
135:      */
136:     public static function arrayToPssXml($result) {
137:         $xml = new \SimpleXMLElement(XmlManager::$defaultXmlDoc);
138:         $actPlace = 0;
139: 
140:         foreach ($result as $row) {
141: 
142:             // fetch  the place id of the row
143:             $placeId = $row[\database\PssSqlManager::$placeId];
144: 
145:             // if the id is new -> add new place element
146:             if ($actPlace != $placeId) {
147:                 $actPlace = $placeId;
148:                 $place = $xml->addChild(XmlManager::$placeElementName);
149:                 $place->addAttribute(XmlManager::$placeIdAttrName, $placeId);
150:             }
151: 
152:             // add placeservice elment
153:             $placeSrv = $place->addChild(XmlManager::$placeServiceElementName);
154:             $placeSrv->addAttribute(XmlManager::$placeServiceAttrName, $row[\database\PssSqlManager::$srvName]);
155:             $placeSrv->addChild(XmlManager::$placeSapElementName, $row[\database\PssSqlManager::$srvSap]);
156:             $placeSrv->addChild(XmlManager::$placeRequestElementName, $row[\database\PssSqlManager::$srvRequest]);
157:         }
158:         return $xml->asXML();
159:     }
160: 
161: }
162: 
163: ?>
164: 
GeoApi API documentation generated by ApiGen 2.8.0