From 46a5b3cb2f599472b4325c2f01fed39d602034a4 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 14 Oct 2016 21:14:04 +0000 Subject: [PATCH] CubeLinks: hook into the cube module --- library/Director/ProvidedHook/CubeLinks.php | 49 +++++++++++++++++++++ run.php | 2 + 2 files changed, 51 insertions(+) create mode 100644 library/Director/ProvidedHook/CubeLinks.php diff --git a/library/Director/ProvidedHook/CubeLinks.php b/library/Director/ProvidedHook/CubeLinks.php new file mode 100644 index 00000000..4cbdd9f6 --- /dev/null +++ b/library/Director/ProvidedHook/CubeLinks.php @@ -0,0 +1,49 @@ +finalizeInnerQuery(); + $query = $cube->innerQuery() + ->reset('columns') + ->columns(array('host' => 'o.name1')) + ->reset('group'); + + $hosts = $cube->db()->fetchCol($query); + + if (count($hosts) === 1) { + $url = 'director/host/edit'; + $params = array('name' => $hosts[0]); + } else { + $params = null; + + $filter = Filter::matchAny(); + foreach($hosts as $host) { + $filter->addFilter( + Filter::matchAny(Filter::expression('name', '=', $host)) + ); + } + + $url = 'director/hosts/edit?' . $filter->toQueryString(); + } + + return $view->qlink( + $view->translate('Modify hosts'), + $url, + $params, + array('class' => 'icon-wrench') + ); + } +} diff --git a/run.php b/run.php index 9c2ae566..0ded6e40 100644 --- a/run.php +++ b/run.php @@ -42,3 +42,5 @@ $this->provideHook('director/Job', $prefix . 'Job\\HousekeepingJob'); $this->provideHook('director/Job', $prefix . 'Job\\ConfigJob'); $this->provideHook('director/Job', $prefix . 'Job\\ImportJob'); $this->provideHook('director/Job', $prefix . 'Job\\SyncJob'); + +$this->provideHook('cube/ActionLinks', 'CubeLinks');