icingaweb2-module-director/library/Director/ProvidedHook/CubeLinks.php

66 lines
1.7 KiB
PHP
Raw Normal View History

2016-10-14 23:14:04 +02:00
<?php
namespace Icinga\Module\Director\ProvidedHook;
2017-01-13 18:58:46 +01:00
use Icinga\Data\Filter\Filter;
2016-10-14 23:14:04 +02:00
use Icinga\Module\Cube\Cube;
2017-01-13 18:58:46 +01:00
use Icinga\Module\Cube\Hook\ActionsHook;
2016-10-14 23:14:04 +02:00
use Icinga\Module\Cube\Ido\IdoHostStatusCube;
use Icinga\Web\View;
class CubeLinks extends ActionsHook
2016-10-14 23:14:04 +02:00
{
2017-01-13 18:58:46 +01:00
/**
* @inheritdoc
*/
2016-11-25 20:50:31 +01:00
public function prepareActionLinks(Cube $cube, View $view)
2016-10-14 23:14:04 +02:00
{
if (! $cube instanceof IdoHostStatusCube) {
2016-11-25 20:50:31 +01:00
return;
2016-10-14 23:14:04 +02:00
}
2016-11-25 20:50:31 +01:00
2016-10-14 23:14:04 +02:00
$cube->finalizeInnerQuery();
$query = $cube->innerQuery()
->reset('columns')
->columns(array('host' => 'o.name1'))
->reset('group');
$hosts = $cube->db()->fetchCol($query);
2016-11-25 20:50:31 +01:00
$count = count($hosts);
if ($count === 1) {
2016-10-14 23:14:04 +02:00
$url = 'director/host/edit';
$params = array('name' => $hosts[0]);
2016-11-25 20:50:31 +01:00
$title = $view->translate('Modify a host');
$description = sprintf(
$view->translate('This allows you to modify properties for "%s"'),
$hosts[0]
);
2016-10-14 23:14:04 +02:00
} else {
$params = null;
$filter = Filter::matchAny();
2017-01-13 18:58:46 +01:00
foreach ($hosts as $host) {
2016-10-14 23:14:04 +02:00
$filter->addFilter(
Filter::matchAny(Filter::expression('name', '=', $host))
);
}
$url = 'director/hosts/edit?' . $filter->toQueryString();
2016-11-25 20:50:31 +01:00
$title = sprintf($view->translate('Modify %d hosts'), $count);
$description = $view->translate(
'This allows you to modify properties for all chosen hosts at once'
);
2016-10-14 23:14:04 +02:00
}
2016-11-25 20:50:31 +01:00
$this->addActionLink(
$this->makeUrl($url, $params),
$title,
$description,
'wrench'
2016-10-14 23:14:04 +02:00
);
}
}