From d61e864a1e47b049ea49047acdf22fe66c6b7b58 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Fri, 8 May 2020 09:17:37 +0200 Subject: [PATCH] chg: [clusterRelations:view_relations] Attached referencing relations --- app/Controller/GalaxyClustersController.php | 17 +++++++++++-- app/Model/AppModel.php | 1 + app/Model/GalaxyCluster.php | 24 ++++++++++++++++++- .../GalaxyClusters/view_relations.ctp | 11 +++++---- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/app/Controller/GalaxyClustersController.php b/app/Controller/GalaxyClustersController.php index 9107ba7e7..ba1e87656 100644 --- a/app/Controller/GalaxyClustersController.php +++ b/app/Controller/GalaxyClustersController.php @@ -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, diff --git a/app/Model/AppModel.php b/app/Model/AppModel.php index 381d52b5d..4fd33d324 100644 --- a/app/Model/AppModel.php +++ b/app/Model/AppModel.php @@ -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;'; diff --git a/app/Model/GalaxyCluster.php b/app/Model/GalaxyCluster.php index 4e852d148..49f7dcd95 100644 --- a/app/Model/GalaxyCluster.php +++ b/app/Model/GalaxyCluster.php @@ -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; } } diff --git a/app/View/Elements/GalaxyClusters/view_relations.ctp b/app/View/Elements/GalaxyClusters/view_relations.ctp index eff353793..9d0da75c8 100644 --- a/app/View/Elements/GalaxyClusters/view_relations.ctp +++ b/app/View/Elements/GalaxyClusters/view_relations.ctp @@ -52,8 +52,6 @@ echo $this->element('genericElements/assetLoader', array(