mirror of https://github.com/MISP/MISP
chg: [galaxy:fork_tree] Moved generation in the model
parent
7ffcd86eae
commit
f2c136bae3
|
@ -428,31 +428,7 @@ class GalaxiesController extends AppController
|
|||
'recursive' => -1,
|
||||
'conditions' => array('Galaxy.id' => $galaxyId)
|
||||
));
|
||||
$tree = array();
|
||||
$lookup = array();
|
||||
foreach ($clusters as $i => $cluster) {
|
||||
$clusters[$i]['children'] = array();
|
||||
$lookup[$cluster['GalaxyCluster']['id']] = &$clusters[$i];
|
||||
}
|
||||
foreach ($clusters as $i => $cluster) {
|
||||
if (!empty($cluster['GalaxyCluster']['extended_from'])) {
|
||||
$parent = $cluster['GalaxyCluster']['extended_from'];
|
||||
$lookup[$parent['GalaxyCluster']['id']]['children'][] = &$clusters[$i];
|
||||
} else {
|
||||
$tree[] = &$clusters[$i];
|
||||
}
|
||||
}
|
||||
|
||||
foreach($tree as $i => $node) {
|
||||
if (empty($node['children'])) {
|
||||
unset($tree[$i]);
|
||||
}
|
||||
}
|
||||
|
||||
$tree = array(array(
|
||||
'Galaxy' => $galaxy['Galaxy'],
|
||||
'children' => array_values($tree)
|
||||
));
|
||||
$tree = $this->Galaxy->generateForkTree($clusters, $galaxy, $pruneRootLeaves=true);
|
||||
if ($this->_isRest()) {
|
||||
return $this->RestResponse->viewData($tree, $this->response->type());
|
||||
}
|
||||
|
|
|
@ -510,4 +510,36 @@ class Galaxy extends AppModel
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function generateForkTree($clusters, $galaxy, $pruneRootLeaves=true)
|
||||
{
|
||||
$tree = array();
|
||||
$lookup = array();
|
||||
foreach ($clusters as $i => $cluster) {
|
||||
$clusters[$i]['children'] = array();
|
||||
$lookup[$cluster['GalaxyCluster']['id']] = &$clusters[$i];
|
||||
}
|
||||
foreach ($clusters as $i => $cluster) {
|
||||
if (!empty($cluster['GalaxyCluster']['extended_from'])) {
|
||||
$parent = $cluster['GalaxyCluster']['extended_from'];
|
||||
$lookup[$parent['GalaxyCluster']['id']]['children'][] = &$clusters[$i];
|
||||
} else {
|
||||
$tree[] = &$clusters[$i];
|
||||
}
|
||||
}
|
||||
|
||||
if ($pruneRootLeaves) {
|
||||
foreach($tree as $i => $node) {
|
||||
if (empty($node['children'])) {
|
||||
unset($tree[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tree = array(array(
|
||||
'Galaxy' => $galaxy['Galaxy'],
|
||||
'children' => array_values($tree)
|
||||
));
|
||||
return $tree;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue