Files
geodb/geoapi/utility/JsonManager.php
2013-08-19 17:54:44 +02:00

145 lines
4.6 KiB
PHP

<?php
namespace utiliy;
include_once "../../global.inc.php";
require_once PATH_UTILITTY . "/SerialManager.php";
/**
* The XmlManager provides some xml-methods
* @author stubbfel
* @since 25.06.2013
*/
class JsonManager implements SerialManager {
/**
* Name for the sap item
* @var string
*/
private static $placeSapName = "sap";
/**
* Name for the request item
* @var string
*/
private static $placeRequestName = "request";
/**
* Name for the placeInfoName item
* @var string
*/
private static $placeInfoName = "placeInformationName";
/**
* Name for the value of the placeInfoName item
* @var string
*/
private static $placeInfoValueName = "placeInformationValue";
/**
* Name for the placeServiceName item
* @var string
*/
private static $placeServiceName = "placeServiceName";
/**
* Name for the placeid item
* @var string
*/
private static $placeIdName = "id";
/**
* Name for the parent item
* @var string
*/
private static $parentIdName = "parentId";
/**
* Name for the refpoint item
* @var string
*/
private static $refpointName = "refpoint";
/**
* Method convert an array to a response json for the sps service
* @example {"127003463":{"name":"Informations-, Kommunikations- und Medienzentrum","typ":"library"},"129258513":{"name":"Wohnheim Papitzer Stra\u00dfe 4\/5","typ":"guest_house"}}
* @param array[num][assoc] $result
* @return json-string
*/
public static function arrayToSpsJson($result) {
$places = array();
foreach ($result as $row) {
$place = array(self::$parentIdName => $row[\database\SpsSqlManager::$parentId], self::$refpointName => $row[\database\SpsSqlManager::$refpoint]);
$places[$row[\database\SpsSqlManager::$placeId]] = $place;
}
return json_encode($places);
}
/**
* Method convert an array to a response json for the pis service like
* @example [{"id":"127003463","0":{"placeInformationName":"name","placeInformationValue":"Informations-, Kommunikations- und Medienzentrum"},"1":{"placeInformationName":"typ","placeInformationValue":"library"}}]
* @param array[num][assoc] $result
* @return json-string
*/
public static function arrayToPisJson($result) {
$infos = array();
foreach ($result as $row) {
// fetch the place id of the row
$placeId = $row[\database\PisSqlManager::$placeId];
$infos[$placeId][self::$parentIdName] = $row[\database\PisSqlManager::$parentId];
$infos[$placeId][self::$refpointName] = $row[\database\PisSqlManager::$refpoint];
$infos[$placeId][$row[\database\PisSqlManager::$infName]] = utf8_encode($row[\database\PisSqlManager::$infValue]);
}
return json_encode($infos);
}
/**
* Method convert an array to a response json for the pss service
* @example {"1":{"website":{"sap":"http:\/\/www.","request":"tu-cottbus.de\/btu\/"}},"2":{"website":{"sap":"http:\/\/www.","request":"hs-lausitz.de\/start.html"}}}
* @param array[num][assoc] $result
* @return Json-string
*/
public static function arrayToPssJson($result) {
$services = array();
foreach ($result as $row) {
// fetch the place id of the row
$placeId = $row[\database\PssSqlManager::$placeId];
$placeSrv = array(self::$placeSapName => $row[\database\PssSqlManager::$srvSap], self::$placeRequestName => $row[\database\PssSqlManager::$srvRequest]);
$services[$placeId][self::$parentIdName] = $row[\database\PssSqlManager::$parentId];
$services[$placeId][self::$refpointName] = $row[\database\PssSqlManager::$refpoint];
$services[$placeId][$row[\database\PssSqlManager::$srvName]] = $placeSrv;
}
return json_encode($services);
}
/**
* Implement the arrayToSps from @see SerialManager
* @param array [num] [assoc] $result
* @return string
*/
public function arrayToSps($result) {
return self::arrayToSpsJson($result);
}
/**
* Implement the arrayToPss from @see SerialManager
* @param array [num] [assoc] $result
* @return string
*/
public function arrayToPss($result) {
return self::arrayToPssJson($result);
}
/**
* Implement the arrayToPis from @see SerialManager
* @param array [num] [assoc] $result
* @return string
*/
public function arrayToPis($result) {
return self::arrayToPisJson($result);
}
}
?>