diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:47:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:47:21 +0000 |
commit | 1ac4a2050c8076eb96e07e83721ebc9db864db94 (patch) | |
tree | da9b32212bf99154450a7668f61a75f65617a9fa /application/views/helpers/Badges.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-toplevelview-upstream.tar.xz icingaweb2-module-toplevelview-upstream.zip |
Adding upstream version 0.3.3.upstream/0.3.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | application/views/helpers/Badges.php | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/application/views/helpers/Badges.php b/application/views/helpers/Badges.php new file mode 100644 index 0000000..6066a72 --- /dev/null +++ b/application/views/helpers/Badges.php @@ -0,0 +1,49 @@ +<?php +/* Icinga Web 2 Top Level View | (c) 2017 Icinga Development Team | GPLv2+ */ + +use Icinga\Module\Toplevelview\Tree\TLVStatus; +use Icinga\Web\Url; + +class Zend_View_Helper_Badges extends Zend_View_Helper_Abstract +{ + /** @var \Icinga\Web\View */ + public $view; + + protected function prettyTitle($identifier) + { + $s = ''; + foreach (preg_split('/[\.\-_\s]+/', $identifier) as $p) { + $s .= ' ' . ucfirst($p); + } + return trim($s); + } + + public function badges(TLVStatus $status, $problemsOnly = true, $showTotal = false) + { + $htm = ''; + + $values = false; + $htm .= '<div class="badges">'; + foreach ($status->getProperties() as $key => $value) { + if ($problemsOnly === true && ($key === 'ok' || $key === 'downtime_active') + || ($key === 'total' && $showTotal !== true) + ) { + continue; + } + if ($value !== null && $value > 0) { + $values = true; + $title = $value . ' ' . $this->prettyTitle($key); + $class = 'tlv-status-tile ' . str_replace('_', ' ', $key); + $htm .= sprintf( + '<div class="badge status-badge %s" title="%s">%s</div>', + $class, + $title, + $value + ); + } + } + $htm .= '</div>'; + + return $values ? $htm : ''; + } +} |