Skip to content

Commit

Permalink
CubeLinks: hook into the cube module
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Gelf committed Oct 14, 2016
1 parent a8c3769 commit 46a5b3c
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
49 changes: 49 additions & 0 deletions library/Director/ProvidedHook/CubeLinks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Icinga\Module\Director\ProvidedHook;

use Icinga\Module\Cube\Hook\ActionLinksHook;
use Icinga\Module\Cube\Cube;
use Icinga\Module\Cube\Ido\IdoHostStatusCube;
use Icinga\Data\Filter\Filter;
use Icinga\Web\View;

class CubeLinks extends ActionLinksHook
{
public function getHtml(View $view, Cube $cube)
{
if (! $cube instanceof IdoHostStatusCube) {
return '';
}
$cube->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')
);
}
}
2 changes: 2 additions & 0 deletions run.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@
$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');

0 comments on commit 46a5b3c

Please sign in to comment.