forked from Icinga/icingaweb2-module-director
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CubeLinks: hook into the cube module
- Loading branch information
1 parent
a8c3769
commit 46a5b3c
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters