mirror of https://github.com/MISP/MISP
new: [UI Helper] DataPathCollector helper added
- helps the index factory fields retrieve data from the currently processed object based on a set of pathspull/5560/head
parent
ec93389669
commit
10ab82f830
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue