Merge branch 'release/r#65'
This commit is contained in:
135
geoapi/utility/JsonManager.php
Normal file
135
geoapi/utility/JsonManager.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace utiliy;
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
|
||||
/**
|
||||
* The XmlManager provides some xml-methods
|
||||
* @author stubbfel
|
||||
* @since 25.06.2013
|
||||
*/
|
||||
class JsonManager {
|
||||
|
||||
/**
|
||||
* 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 = "placeInformationName";
|
||||
|
||||
/**
|
||||
* 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";
|
||||
|
||||
/**
|
||||
* Method convert an array to a response json for the sps service
|
||||
*
|
||||
* @param array[num][assoc] $result
|
||||
* @return json-string
|
||||
*/
|
||||
public static function arrayToSpsJson($result) {
|
||||
$places = array();
|
||||
foreach ($result as $row) {
|
||||
$place = array(JsonManager::$placeIdName => $row[\database\SpsSqlManager::$placeId],
|
||||
JsonManager::$parentIdName => $row[\database\SpsSqlManager::$parentId]);
|
||||
array_push($places, $place);
|
||||
}
|
||||
return json_encode($places);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method convert an array to a response json for the pis service like
|
||||
*
|
||||
* @param array[num][assoc] $result
|
||||
* @return json-string
|
||||
*/
|
||||
public static function arrayToPisJson($result) {
|
||||
$actPlace = 0;
|
||||
|
||||
$infos = array();
|
||||
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) {
|
||||
$actPlace = $placeId;
|
||||
$place = array(JsonManager::$placeIdName => $placeId);
|
||||
array_push($infos, $place);
|
||||
}
|
||||
|
||||
// add placeinformation item
|
||||
$placeInfo = array(JsonManager::$placeInfoName => $row[\database\PisSqlManager::$infName],
|
||||
JsonManager::$placeInfoValueName => utf8_encode($row[\database\PisSqlManager::$infValue]));
|
||||
array_push($place, $placeInfo);
|
||||
}
|
||||
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();
|
||||
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) {
|
||||
$actPlace = $placeId;
|
||||
$place = array(JsonManager::$placeIdName => $placeId);
|
||||
array_push($services, $place);
|
||||
}
|
||||
|
||||
// add placeservice items
|
||||
$placeSrv = array(JsonManager::$placeServiceName => $row[\database\PisSqlManager::$srvName],
|
||||
JsonManager::$placeSapName => $row[\database\PisSqlManager::$srvSap],
|
||||
JsonManager::$placeRequestName => $row[\database\PisSqlManager::$srvRequest]);
|
||||
array_push($place, $placeSrv);
|
||||
}
|
||||
return json_encode($services);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user