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

View File

@ -301,4 +301,22 @@ function get_complementary_rgb ($hexcode) {
return $rgbhex; 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;
}
?> ?>