mirror of https://github.com/MISP/MISP
chg: [clusterRelations:view_relations] Attached referencing relations
parent
7328eb1ebd
commit
d61e864a1e
|
@ -831,8 +831,8 @@ class GalaxyClustersController extends AppController
|
|||
}
|
||||
$cluster = $cluster[0];
|
||||
$existingRelations = $this->GalaxyCluster->GalaxyClusterRelation->getExistingRelationships();
|
||||
$cluster = $this->GalaxyCluster->attachReferencingRelations($this->Auth->user(), $cluster);
|
||||
$cluster = $this->GalaxyCluster->attachClusterToRelations($this->Auth->user(), $cluster);
|
||||
debug($existingRelations);
|
||||
|
||||
$treeRight = array(array(
|
||||
'GalaxyCluster' => $cluster['GalaxyCluster'],
|
||||
|
@ -849,7 +849,20 @@ class GalaxyClustersController extends AppController
|
|||
$treeRight[0]['children'][] = $tmp;
|
||||
}
|
||||
|
||||
$treeLeft = array();
|
||||
$treeLeft = array(array(
|
||||
'GalaxyCluster' => $cluster['GalaxyCluster'],
|
||||
'children' => array()
|
||||
));
|
||||
foreach($cluster['ReferencingGalaxyClusterRelation'] as $relation) {
|
||||
$tmp = array(
|
||||
'Relation' => array_diff_key($relation, array_flip(array('GalaxyCluster'))),
|
||||
'children' => array(
|
||||
array('GalaxyCluster' => $relation['GalaxyCluster']),
|
||||
)
|
||||
);
|
||||
$treeLeft[0]['children'][] = $tmp;
|
||||
}
|
||||
|
||||
$tree = array(
|
||||
'right' => $treeRight,
|
||||
'left' => $treeLeft,
|
||||
|
|
|
@ -1399,6 +1399,7 @@ class AppModel extends Model
|
|||
`tag_id` int(11) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
|
||||
// TODO: ADD INDEXES
|
||||
break;
|
||||
case 'fixNonEmptySharingGroupID':
|
||||
$sqlArray[] = 'UPDATE `events` SET `sharing_group_id` = 0 WHERE `distribution` != 4;';
|
||||
|
|
|
@ -579,7 +579,7 @@ class GalaxyCluster extends AppModel
|
|||
|
||||
public function attachClusterToRelations($user, $cluster)
|
||||
{
|
||||
if (isset($cluster['GalaxyClusterRelation'])) {
|
||||
if (!empty($cluster['GalaxyClusterRelation'])) {
|
||||
foreach ($cluster['GalaxyClusterRelation'] as $k => $relation) {
|
||||
$conditions = array('conditions' => array('GalaxyCluster.id' => $relation['referenced_galaxy_cluster_id']));
|
||||
$relatedCluster = $this->fetchGalaxyClusters($user, $conditions, false);
|
||||
|
@ -588,6 +588,28 @@ class GalaxyCluster extends AppModel
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!empty($cluster['ReferencingGalaxyClusterRelation'])) {
|
||||
foreach ($cluster['ReferencingGalaxyClusterRelation'] as $k => $relation) {
|
||||
$conditions = array('conditions' => array('GalaxyCluster.id' => $relation['galaxy_cluster_id']));
|
||||
$relatedCluster = $this->fetchGalaxyClusters($user, $conditions, false);
|
||||
if (!empty($relatedCluster)) {
|
||||
$cluster['ReferencingGalaxyClusterRelation'][$k]['GalaxyCluster'] = $relatedCluster[0]['GalaxyCluster'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $cluster;
|
||||
}
|
||||
|
||||
public function attachReferencingRelations($user, $cluster)
|
||||
{
|
||||
$referencingRelations = $this->GalaxyClusterRelation->fetchRelations($user, array('conditions' => array(
|
||||
'referenced_galaxy_cluster_id' => $cluster['GalaxyCluster']['id']
|
||||
)));
|
||||
if (!empty($referencingRelations)) {
|
||||
foreach ($referencingRelations as $k => $relation) {
|
||||
$cluster['ReferencingGalaxyClusterRelation'][] = $relation['GalaxyClusterRelation'];
|
||||
}
|
||||
}
|
||||
return $cluster;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,8 +52,6 @@ echo $this->element('genericElements/assetLoader', array(
|
|||
|
||||
<script>
|
||||
var treeData = <?= json_encode($tree) ?>;
|
||||
var treeRight = treeData.right;
|
||||
var treeLeft = treeData.left;
|
||||
var margin = {top: 10, right: 10, bottom: 10, left: 20};
|
||||
var treeWidth, treeHeight;
|
||||
var colors = d3.scale.category10();
|
||||
|
@ -121,11 +119,16 @@ echo $this->element('genericElements/assetLoader', array(
|
|||
}
|
||||
|
||||
function buildTree() {
|
||||
// drawTree(treeData.right, false);
|
||||
drawTree(treeData.left, true);
|
||||
}
|
||||
|
||||
function drawTree(data, orientationLeft) {
|
||||
var $tree = $('#treeSVG');
|
||||
treeWidth = $tree.width() - margin.right - margin.left;
|
||||
treeHeight = $tree.height() - margin.top - margin.bottom;
|
||||
|
||||
var tree = d3.layout.tree(treeRight)
|
||||
var tree = d3.layout.tree(data)
|
||||
.size([treeHeight, treeWidth]);
|
||||
|
||||
var diagonal = function link(d) {
|
||||
|
@ -141,7 +144,7 @@ echo $this->element('genericElements/assetLoader', array(
|
|||
.append("g")
|
||||
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
|
||||
|
||||
var root = treeRight[0];
|
||||
var root = data[0];
|
||||
root.isRoot = true;
|
||||
root.x0 = treeHeight / 2;
|
||||
root.y0 = 0;
|
||||
|
|
Loading…
Reference in New Issue