diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
commit | f66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /library/Director/ProvidedHook/IcingaDbCubeLinks.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip |
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Director/ProvidedHook/IcingaDbCubeLinks.php')
-rw-r--r-- | library/Director/ProvidedHook/IcingaDbCubeLinks.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/library/Director/ProvidedHook/IcingaDbCubeLinks.php b/library/Director/ProvidedHook/IcingaDbCubeLinks.php new file mode 100644 index 0000000..234f61f --- /dev/null +++ b/library/Director/ProvidedHook/IcingaDbCubeLinks.php @@ -0,0 +1,66 @@ +<?php + +namespace Icinga\Module\Director\ProvidedHook; + +use Icinga\Data\Filter\Filter; +use Icinga\Exception\ProgrammingError; +use Icinga\Module\Cube\Hook\IcingaDbActionsHook; +use Icinga\Module\Cube\IcingaDb\IcingaDbCube; +use Icinga\Module\Cube\IcingaDb\IcingaDbHostStatusCube; + +class IcingaDbCubeLinks extends IcingaDbActionsHook +{ + /** + * @inheritDoc + * @param IcingaDbCube $cube + * @throws ProgrammingError + */ + public function createActionLinks(IcingaDbCube $cube) + { + if (! $cube instanceof IcingaDbHostStatusCube) { + return; + } + + $filterChain = $cube->getObjectsFilter(); + + if ($filterChain->count() === 1) { + $url = 'director/host/edit?'; + $params = ['name' => $filterChain->getIterator()->current()->getValue()]; + + $title = t('Modify a host'); + $description = sprintf( + t('This allows you to modify properties for "%s"'), + $filterChain->getIterator()->current()->getValue() + ); + } else { + $params = null; + + $urlFilter = Filter::matchAny(); + foreach ($filterChain as $filter) { + $urlFilter->addFilter( + Filter::matchAny( + Filter::expression( + 'name', + '=', + $filter->getValue() + ) + ) + ); + } + + $url = 'director/hosts/edit?' . $urlFilter->toQueryString(); + + $title = sprintf(t('Modify %d hosts'), $filterChain->count()); + $description = t( + 'This allows you to modify properties for all chosen hosts at once' + ); + } + + $this->addActionLink( + $this->makeUrl($url, $params), + $title, + $description, + 'wrench' + ); + } +} |