add functions api for policies node

This commit is contained in:
daniel 2018-07-23 08:59:08 +02:00
parent 63cc7aab9c
commit f05ba656e1
2 changed files with 61 additions and 52 deletions

View File

@ -99,35 +99,31 @@ function returnError($typeError, $returnType = 'string') {
break;
default:
returnData("string",
array('type' => 'string', 'data' => __($returnType)));
array('type' => 'string', 'data' => __($typeError)));
break;
}
}
/**
*
* @param $returnType
* @param $data
* @param $separator
*
* @return
*/
function returnData($returnType, $data, $separator = ';') {
switch ($returnType) {
case 'string':
if ($data['type'] == 'string') {
echo $data['data'];
if( is_array($data['data']) ){
echo convert_array_multi($data['data'], $separator);
}
else{
//TODO
echo $data['data'];
}
break;
case 'csv':
case 'csv_head':
switch ($data['type']) {
case 'array':
if (array_key_exists('list_index', $data))
{
if( is_array($data['data']) ){
if (array_key_exists('list_index', $data)) {
if ($returnType == 'csv_head') {
foreach($data['list_index'] as $index) {
echo $index;
@ -150,11 +146,8 @@ function returnData($returnType, $data, $separator = ';') {
}
else {
if (!empty($data['data'])) {
foreach ($data['data'] as $dataContent) {
$clean = array_map("array_apply_io_safe_output", $dataContent);
foreach ($clean as $k => $v) {
$clean[$k] = str_replace("\r", "\n", $clean[$k]);
$clean[$k] = str_replace("\n", " ", $clean[$k]);
@ -162,15 +155,13 @@ function returnData($returnType, $data, $separator = ';') {
$clean[$k] = str_replace(';',' ',$clean[$k]);
}
$row = implode($separator, $clean);
echo $row . "\n";
}
}
}
break;
case 'string':
}
else{
echo $data['data'];
break;
}
break;
case 'json':

View File

@ -301,4 +301,22 @@ function get_complementary_rgb ($hexcode) {
return $rgbhex;
}
/**
* Returns convert array multidimensional to string whit gluer.
* @param array $array to convert
* @param string glue to implode
*/
function convert_array_multi($array, $glue) {
$result = '';
foreach ($array as $item) {
if (is_array($item)) {
$result .= convert_array_multi($item, $glue) . $glue;
} else {
$result .= $item . $glue;
}
}
$result = substr($result, 0, 0-strlen($glue));
return $result;
}
?>