Overview

Namespaces

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

Classes

  • ArrayManager
  • JsonManager
  • StringManager
  • XmlManager

Interfaces

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