Files
geodb/geoapi/utility/JsonManager.php
2013-07-10 13:50:09 +02:00

182 lines
5.0 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 [{"id":"121799787","parentId":null}]
* @param array[num][assoc] $result
* @return json-string
*/
public static function arrayToSpsJson($result) {
$places = array();
foreach ($result as $row) {
$place = array(self::$placeIdName => $row[\database\SpsSqlManager::$placeId],
self::$parentIdName => $row[\database\SpsSqlManager::$parentId],
self::$refpointName => $row[\database\SpsSqlManager::$refpoint]);
array_push($places, $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) {
$actPlace = 0;
$infos = array();
$place = null;
foreach ($result as $row) {
// fetch the place id of the row
$placeId = $row[\database\PisSqlManager::$placeId];
// if the id is new -> add new place item
if ($actPlace != $placeId) {
if ($place) {
array_push($infos, $place);
}
$actPlace = $placeId;
$place = array(self::$placeIdName => $placeId);
}
// add placeinformation item
$placeInfo = array(self::$placeInfoName => $row[\database\PisSqlManager::$infName], self::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue]));
array_push($place, $placeInfo);
}
array_push($infos, $place);
return json_encode($infos);
}
/**
* Method convert an array to a response json for the pss service
*
* @param array[num][assoc] $result
* @return Json-string
*/
public static function arrayToPssJson($result) {
$actPlace = 0;
$services = array();
$place = null;
foreach ($result as $row) {
// fetch the place id of the row
$placeId = $row[\database\PssSqlManager::$placeId];
// if the id is new -> add new place item
if ($actPlace != $placeId) {
if ($place) {
array_push($services, $place);
}
$actPlace = $placeId;
$place = array(self::$placeIdName => $placeId);
}
// add placeservice items
$placeSrv = array(self::$placeServiceName => $row[\database\PisSqlManager::$srvName],
self::$placeSapName => $row[\database\PisSqlManager::$srvSap],
self::$placeRequestName => $row[\database\PisSqlManager::$srvRequest]);
array_push($place, $placeSrv);
}
array_push($services, $place);
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);
}
}
?>