| 1 |
<?php |
| 2 |
/* Icinga Web 2 Top Level View | (c) 2017 Icinga Development Team | GPLv2+ */ |
| 3 |
|
| 4 |
use Icinga\Module\Toplevelview\Tree\TLVTreeNode; |
| 5 |
use Icinga\Web\Url; |
| 6 |
|
| 7 |
class Zend_View_Helper_Tree extends Zend_View_Helper_Abstract |
| 8 |
{ |
| 9 |
/** @var \Icinga\Web\View */ |
| 10 |
public $view; |
| 11 |
|
| 12 |
/** |
| 13 |
* tree takes a TLVTreeNode and renders it recursively into HTML. |
| 14 |
* It is used in a Controller to render the full tree. |
| 15 |
*/ |
| 16 |
public function tree(TLVTreeNode $node, $classes = array(), $level = 0) |
| 17 |
{ |
| 18 |
$htm = ''; |
| 19 |
$htmExtra = ''; |
| 20 |
$title = $node->getTitle(); |
| 21 |
$type = $node->getType(); |
| 22 |
|
| 23 |
$cssClasses = join(' ', $classes); |
| 24 |
|
| 25 |
$status = $node->getStatus(); |
| 26 |
$statusClass = $status->getOverall(); |
| 27 |
|
| 28 |
if ($type === 'host') { |
| 29 |
$icon = 'host'; |
| 30 |
$url = Url::fromPath('icingadb/host', ['name' => $node->get('host')]); |
| 31 |
} elseif ($type === 'service') { |
| 32 |
$icon = 'service'; |
| 33 |
$url = Url::fromPath( |
| 34 |
'icingadb/service', |
| 35 |
[ |
| 36 |
'name' => $node->get('service'), |
| 37 |
'host.name' => $node->get('host') |
| 38 |
] |
| 39 |
); |
| 40 |
} elseif ($type === 'servicegroup') { |
| 41 |
$icon = 'services'; |
| 42 |
$url = Url::fromPath( |
| 43 |
'icingadb/servicegroup', |
| 44 |
[ |
| 45 |
'name' => $node->get('servicegroup') |
| 46 |
] |
| 47 |
); |
| 48 |
} elseif ($type === 'hostgroup') { |
| 49 |
$icon = 'cubes'; |
| 50 |
$url = Url::fromPath( |
| 51 |
'icingadb/services', |
| 52 |
[ |
| 53 |
'hostgroup.name' => $node->get('hostgroup') |
| 54 |
] |
| 55 |
); |
| 56 |
|
| 57 |
if (($h = $status->getMeta('hosts_unhandled')) > 0) { |
| 58 |
$hostTitle = '(<strong>' |
| 59 |
. sprintf($this->view->translatePlural('%s unhandled host', '%s unhandled hosts', $h), $h) |
| 60 |
. '</strong>)'; |
| 61 |
} else { |
| 62 |
$h = $status->getMeta('hosts_total'); |
| 63 |
$hostTitle = '(' . sprintf($this->view->translatePlural('%s host', '%s hosts', $h), $h) . ')'; |
| 64 |
} |
| 65 |
|
| 66 |
$htmExtra .= ' ' . $this->view->qlink( |
| 67 |
$hostTitle, |
| 68 |
'icingadb/hosts', |
| 69 |
[ |
| 70 |
'hostgroup.name' => $node->get('hostgroup') |
| 71 |
], |
| 72 |
null, |
| 73 |
false |
| 74 |
); |
| 75 |
} else { |
| 76 |
$icon = null; |
| 77 |
$url = Url::fromPath( |
| 78 |
'toplevelview/show/tree', |
| 79 |
[ |
| 80 |
'name' => $node->getRoot()->getViewName(), |
| 81 |
'id' => $node->getFullId() |
| 82 |
] |
| 83 |
); |
| 84 |
} |
| 85 |
|
| 86 |
if ($type !== 'node') { |
| 87 |
$htm .= "<div class=\"tlv-node-icinga tlv-node-\$type tlv-status-tile action $statusClass $cssClasses\"" |
| 88 |
. " data-base-target=\"_next\" href=\"$url\">"; |
| 89 |
$htm .= $this->view->icon($icon) . ' '; |
| 90 |
$htm .= $this->view->qlink($title, $url); |
| 91 |
$htm .= $htmExtra; |
| 92 |
$htm .= ' ' . $this->view->badges($status, false); |
| 93 |
$htm .= '</div>'; |
| 94 |
} else { |
| 95 |
$htm .= "<div class=\"tlv-tree-node tlv-status-section tlv-collapsible $statusClass $cssClasses\""; |
| 96 |
$htm .= " title=\"$title\">"; |
| 97 |
$htm .= '<div class="tlv-tree-title">'; |
| 98 |
$htm .= $this->view->badges($status, false, $level === 0 ? true : false); |
| 99 |
$htm .= '<i class="icon icon-bycss tlv-collapse-handle"></i> '; |
| 100 |
$htm .= $this->view->qlink($title, $url); |
| 101 |
$htm .= $htmExtra; |
| 102 |
$htm .= '</div>'; |
| 103 |
if ($node->hasChildren()) { |
| 104 |
foreach ($node->getChildren() as $child) { |
| 105 |
$htm .= $this->tree($child, $classes, $level + 1); |
| 106 |
} |
| 107 |
} |
| 108 |
$htm .= '</div>'; |
| 109 |
} |
| 110 |
|
| 111 |
return $htm; |
| 112 |
} |
| 113 |
} |