| 1 |
<?php |
| 2 |
/* Icinga Web 2 Top Level View | (c) 2017 Icinga Development Team | GPLv2+ */ |
| 3 |
|
| 4 |
use Icinga\Module\Toplevelview\Tree\TLVStatus; |
| 5 |
use Icinga\Module\Toplevelview\Util\Str; |
| 6 |
|
| 7 |
class Zend_View_Helper_Badges extends Zend_View_Helper_Abstract |
| 8 |
{ |
| 9 |
/** @var \Icinga\Web\View */ |
| 10 |
public $view; |
| 11 |
|
| 12 |
/** |
| 13 |
* badges renders a TLVNode's TLVStatus into HTML. |
| 14 |
* A badge represents the number of status of a given node |
| 15 |
*/ |
| 16 |
public function badges(TLVStatus $status, $problemsOnly = true, $showTotal = false) |
| 17 |
{ |
| 18 |
$htm = ''; |
| 19 |
|
| 20 |
$values = false; |
| 21 |
$htm .= '<div class="badges">'; |
| 22 |
foreach ($status->getProperties() as $key => $value) { |
| 23 |
if ($problemsOnly === true && ($key === 'ok' || $key === 'downtime_active') |
| 24 |
|| ($key === 'total' && $showTotal !== true) |
| 25 |
) { |
| 26 |
continue; |
| 27 |
} |
| 28 |
if ($value !== null && $value > 0) { |
| 29 |
$values = true; |
| 30 |
$title = $value . ' ' . Str::prettyTitle($key); |
| 31 |
$class = 'tlv-status-badge ' . str_replace('_', ' ', $key); |
| 32 |
$htm .= sprintf( |
| 33 |
'<div class="badge status-badge %s" title="%s">%s</div>', |
| 34 |
$class, |
| 35 |
$title, |
| 36 |
$value |
| 37 |
); |
| 38 |
} |
| 39 |
} |
| 40 |
$htm .= '</div>'; |
| 41 |
|
| 42 |
return $values ? $htm : ''; |
| 43 |
} |
| 44 |
} |