diff --git a/app/Controller/GalaxiesController.php b/app/Controller/GalaxiesController.php index 33e047ff3..baf8c7447 100644 --- a/app/Controller/GalaxiesController.php +++ b/app/Controller/GalaxiesController.php @@ -413,4 +413,51 @@ class GalaxiesController extends AppController $this->set('object', $object[0]); $this->render('/Events/ajax/ajaxGalaxies'); } + + public function forkTree($galaxyId) + { + $clusters = $this->Galaxy->GalaxyCluster->fetchGalaxyClusters($this->Auth->user(), array('conditions' => array('GalaxyCluster.galaxy_id' => $galaxyId))); + if (empty($clusters)) { + throw new MethodNotAllowedException('Invalid Galaxy.'); + } + foreach ($clusters as $k => $cluster) { + $clusters[$k] = $this->Galaxy->GalaxyCluster->attachExtendByInfo($this->Auth->user(), $clusters[$k]); + $clusters[$k] = $this->Galaxy->GalaxyCluster->attachExtendFromInfo($this->Auth->user(), $clusters[$k]); + } + $galaxy = $this->Galaxy->find('first', array( + '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) + )); + if ($this->_isRest()) { + return $this->RestResponse->viewData($tree, $this->response->type()); + } + $this->set('tree', $tree); + $this->set('galaxy', $galaxy); + $this->set('galaxy_id', $galaxyId); + } } diff --git a/app/Controller/GalaxyClustersController.php b/app/Controller/GalaxyClustersController.php index cef60ce5c..c30db8403 100644 --- a/app/Controller/GalaxyClustersController.php +++ b/app/Controller/GalaxyClustersController.php @@ -312,7 +312,7 @@ class GalaxyClustersController extends AppController if ($temp === null) { throw new NotFoundException('Invalid galaxy cluster'); } - $id = $temp['Galaxy']['id']; + $id = $temp['GalaxyCluster']['id']; } elseif (!is_numeric($id)) { throw new NotFoundException(__('Invalid galaxy cluster')); } diff --git a/app/View/Galaxies/fork_tree.ctp b/app/View/Galaxies/fork_tree.ctp new file mode 100644 index 000000000..af51b74d9 --- /dev/null +++ b/app/View/Galaxies/fork_tree.ctp @@ -0,0 +1,115 @@ +