new: [UI Helper] DataPathCollector helper added

- helps the index factory fields retrieve data from the currently processed object based on a set of paths
pull/5560/head
iglocska 2020-04-17 14:13:15 +02:00
parent ec93389669
commit 10ab82f830
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
2 changed files with 33 additions and 1 deletions

View File

@ -44,7 +44,7 @@ class AppController extends Controller
public $debugMode = false;
public $helpers = array('Utility', 'OrgImg', 'FontAwesome', 'UserName');
public $helpers = array('Utility', 'OrgImg', 'FontAwesome', 'UserName', 'DataPathCollector');
private $__queryVersion = '102';
public $pyMispVersion = '2.4.123';

View File

@ -0,0 +1,32 @@
<?php
/*
* Helper used to extract variables from an array based on path
* Used by the index factories
*
*/
App::uses('AppHelper', 'View/Helper');
class DataPathCollectorHelper extends AppHelper {
public function extract($data, $data_path, $options = array())
{
$result = array();
if (!is_array($data_path)) {
$data_path = array($data_path);
}
foreach ($data_path as $path) {
$temp = Hash::extract($data, $path);
if (is_array($temp)) {
if (count($temp) > 1) {
$temp = implode(', ', $temp);
} else {
if (count($temp) > 0) {
$temp = $temp[0];
} else {
$temp = '';
}
}
}
$result[$path] = $temp;
}
return $result;
}
}