1: <?php
2:
3: namespace utiliy;
4:
5: include_once "../../global.inc.php";
6: require_once PATH_UTILITTY . "/SerialManager.php";
7:
8: 9: 10: 11: 12:
13: class XmlManager implements SerialManager {
14:
15: 16: 17: 18:
19: private static $defaultXmlDoc = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
20:
21: 22: 23: 24:
25: private static $placeElementName = "place";
26:
27: 28: 29: 30:
31: private static $placeInfoElementName = "placeInformation";
32:
33: 34: 35: 36:
37: private static $placeServiceElementName = "placeService";
38:
39: 40: 41: 42:
43: private static $placeSapElementName = "sap";
44:
45: 46: 47: 48:
49: private static $placeRequestElementName = "request";
50:
51: 52: 53: 54:
55: private static $placeInfoAttrName = "placeInformationName";
56:
57: 58: 59: 60:
61: private static $placeServiceAttrName = "placeServiceName";
62:
63: 64: 65: 66:
67: private static $placeIdAttrName = "id";
68:
69: 70: 71: 72:
73: private static $parentIdAttrName = "parentId";
74:
75: 76: 77: 78:
79: private static $refpointAttrName = "refpoint";
80:
81: 82: 83: 84: 85: 86: 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: 102: 103: 104: 105: 106: 107: 108:
109: public static function arrayToPisXml($result) {
110: $xml = new \SimpleXMLElement(self::$defaultXmlDoc);
111: $actPlace = 0;
112:
113: foreach ($result as $row) {
114:
115:
116: $placeId = $row[\database\PisSqlManager::$placeId];
117:
118:
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:
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: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145:
146: public static function arrayToPssXml($result) {
147: $xml = new \SimpleXMLElement(self::$defaultXmlDoc);
148: $actPlace = 0;
149:
150: foreach ($result as $row) {
151:
152:
153: $placeId = $row[\database\PssSqlManager::$placeId];
154:
155:
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:
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: