From 79d3a47e5a282e87bac9101265351f67246789b7 Mon Sep 17 00:00:00 2001 From: mokaddem Date: Tue, 9 Jun 2020 11:39:31 +0200 Subject: [PATCH] chg: [galaxyCluster:view] Arrange data before exporting --- app/Controller/GalaxiesController.php | 3 +++ app/Controller/GalaxyClustersController.php | 7 +------ app/Model/GalaxyCluster.php | 10 ++++++++++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/Controller/GalaxiesController.php b/app/Controller/GalaxiesController.php index 498a7c6ba..a69d8f497 100644 --- a/app/Controller/GalaxiesController.php +++ b/app/Controller/GalaxiesController.php @@ -243,6 +243,9 @@ class GalaxiesController extends AppController ); $clusters = $this->Galaxy->GalaxyCluster->fetchGalaxyClusters($this->Auth->user(),$options, $full=true); $clusters = $this->Galaxy->GalaxyCluster->unsetFieldsForExport($clusters); + foreach ($clusters as $k => $cluster) { + $clusters[$k] = $this->Galaxy->GalaxyCluster->arrangeDataForExport($cluster); + } $content = json_encode($clusters, JSON_PRETTY_PRINT); $this->response->body($content); if ($this->request->data['download'] == 'download') { diff --git a/app/Controller/GalaxyClustersController.php b/app/Controller/GalaxyClustersController.php index 435b90c8c..247501dd0 100644 --- a/app/Controller/GalaxyClustersController.php +++ b/app/Controller/GalaxyClustersController.php @@ -206,13 +206,8 @@ class GalaxyClustersController extends AppController throw new NotFoundException('Cluster not found.'); } if ($this->_isRest()) { - $models = array('Galaxy', 'GalaxyElement', 'GalaxyClusterRelation', 'Org', 'Orgc', 'TargettingClusterRelation'); - foreach ($models as $model) { - $cluster['GalaxyCluster'][$model] = $cluster[$model]; - unset($cluster[$model]); - } + $cluster = $this->GalaxyCluster->arrangeDataForExport($cluster); return $this->RestResponse->viewData($cluster, $this->response->type()); - // return $this->RestResponse->viewData(array('GalaxyCluster' => $cluster['GalaxyCluster']), $this->response->type()); } else { $cluster = $this->GalaxyCluster->attachExtendByInfo($this->Auth->user(), $cluster); $cluster = $this->GalaxyCluster->attachExtendFromInfo($this->Auth->user(), $cluster); diff --git a/app/Model/GalaxyCluster.php b/app/Model/GalaxyCluster.php index 1d3c73544..cdfb7eaa0 100644 --- a/app/Model/GalaxyCluster.php +++ b/app/Model/GalaxyCluster.php @@ -156,6 +156,16 @@ class GalaxyCluster extends AppModel $this->GalaxyClusterRelation->deleteAll(array('GalaxyClusterRelation.galaxy_cluster_uuid' => $this->uuid)); } + public function arrangeDataForExport($cluster) + { + $models = array('Galaxy', 'GalaxyElement', 'GalaxyClusterRelation', 'Org', 'Orgc', 'TargettingClusterRelation'); + foreach ($models as $model) { + $cluster['GalaxyCluster'][$model] = $cluster[$model]; + unset($cluster[$model]); + } + return $cluster; + } + // Respecting ACL, save a cluster, its elements and set correct fields public function saveCluster($user, $cluster, $allowEdit=false) {