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 JsonManager implements SerialManager {
14:
15: /**
16: * Name for the sap item
17: * @var string
18: */
19: private static $placeSapName = "sap";
20:
21: /**
22: * Name for the request item
23: * @var string
24: */
25: private static $placeRequestName = "request";
26:
27: /**
28: * Name for the placeInfoName item
29: * @var string
30: */
31: private static $placeInfoName = "placeInformationName";
32:
33: /**
34: * Name for the value of the placeInfoName item
35: * @var string
36: */
37: private static $placeInfoValueName = "placeInformationValue";
38:
39: /**
40: * Name for the placeServiceName item
41: * @var string
42: */
43: private static $placeServiceName = "placeServiceName";
44:
45: /**
46: * Name for the placeid item
47: * @var string
48: */
49: private static $placeIdName = "id";
50:
51: /**
52: * Name for the parent item
53: * @var string
54: */
55: private static $parentIdName = "parentId";
56:
57: /**
58: * Name for the refpoint item
59: * @var string
60: */
61: private static $refpointName = "refpoint";
62:
63: /**
64: * Method convert an array to a response json for the sps service
65: * @example {"127003463":{"name":"Informations-, Kommunikations- und Medienzentrum","typ":"library"},"129258513":{"name":"Wohnheim Papitzer Stra\u00dfe 4\/5","typ":"guest_house"}}
66: * @param array[num][assoc] $result
67: * @return json-string
68: */
69: public static function arrayToSpsJson($result) {
70: $places = array();
71: foreach ($result as $row) {
72: $place = array(self::$parentIdName => $row[\database\SpsSqlManager::$parentId], self::$refpointName => $row[\database\SpsSqlManager::$refpoint]);
73: $places[$row[\database\SpsSqlManager::$placeId]] = $place;
74: }
75: return json_encode($places);
76: }
77:
78: /**
79: * Method convert an array to a response json for the pis service like
80: * @example [{"id":"127003463","0":{"placeInformationName":"name","placeInformationValue":"Informations-, Kommunikations- und Medienzentrum"},"1":{"placeInformationName":"typ","placeInformationValue":"library"}}]
81: * @param array[num][assoc] $result
82: * @return json-string
83: */
84: public static function arrayToPisJson($result) {
85: $infos = array();
86: foreach ($result as $row) {
87: // fetch the place id of the row
88: $placeId = $row[\database\PisSqlManager::$placeId];
89: $infos[$placeId][self::$parentIdName] = $row[\database\PisSqlManager::$parentId];
90: $infos[$placeId][self::$refpointName] = $row[\database\PisSqlManager::$refpoint];
91: $infos[$placeId][$row[\database\PisSqlManager::$infName]] = utf8_encode($row[\database\PisSqlManager::$infValue]);
92: }
93: return json_encode($infos);
94: }
95:
96: /**
97: * Method convert an array to a response json for the pss service
98: * @example {"1":{"website":{"sap":"http:\/\/www.","request":"tu-cottbus.de\/btu\/"}},"2":{"website":{"sap":"http:\/\/www.","request":"hs-lausitz.de\/start.html"}}}
99: * @param array[num][assoc] $result
100: * @return Json-string
101: */
102: public static function arrayToPssJson($result) {
103: $services = array();
104: foreach ($result as $row) {
105: // fetch the place id of the row
106: $placeId = $row[\database\PssSqlManager::$placeId];
107: $placeSrv = array(self::$placeSapName => $row[\database\PssSqlManager::$srvSap], self::$placeRequestName => $row[\database\PssSqlManager::$srvRequest]);
108: $services[$placeId][self::$parentIdName] = $row[\database\PssSqlManager::$parentId];
109: $services[$placeId][self::$refpointName] = $row[\database\PssSqlManager::$refpoint];
110: $services[$placeId][$row[\database\PssSqlManager::$srvName]] = $placeSrv;
111: }
112: return json_encode($services);
113: }
114:
115: /**
116: * Implement the arrayToSps from @see SerialManager
117: * @param array [num] [assoc] $result
118: * @return string
119: */
120: public function arrayToSps($result) {
121: return self::arrayToSpsJson($result);
122: }
123:
124: /**
125: * Implement the arrayToPss from @see SerialManager
126: * @param array [num] [assoc] $result
127: * @return string
128: */
129: public function arrayToPss($result) {
130: return self::arrayToPssJson($result);
131: }
132:
133: /**
134: * Implement the arrayToPis from @see SerialManager
135: * @param array [num] [assoc] $result
136: * @return string
137: */
138: public function arrayToPis($result) {
139: return self::arrayToPisJson($result);
140: }
141:
142: }
143:
144: ?>
145: