Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs # 4139
- Loading branch information
Alexander Fuhr
committed
Apr 30, 2015
1 parent
7c0be30
commit 7f28c0a
Showing
2 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */ | ||
|
||
namespace Icinga\Web\Menu; | ||
|
||
use Icinga\Web\Menu; | ||
|
||
class ProblemMenuItemRenderer extends MenuItemRenderer | ||
{ | ||
/** | ||
* Set of summarized problems from submenus | ||
* | ||
* @var array | ||
*/ | ||
protected $summary = array(); | ||
|
||
/** | ||
* Renders the html content of a single menu item and summarizes submenu problems | ||
* | ||
* @param Menu $menu | ||
* | ||
* @return string | ||
*/ | ||
public function render(Menu $menu) | ||
{ | ||
if ($menu->getParent() !== null && $menu->hasSubMenus()) { | ||
/** @var $submenu Menu */ | ||
foreach ($menu->getSubMenus() as $submenu) { | ||
$renderer = $submenu->getRenderer(); | ||
if (method_exists($renderer, 'getSummary')) { | ||
if ($renderer->getSummary() !== null) { | ||
$this->summary[] = $renderer->getSummary(); | ||
} | ||
} | ||
} | ||
} | ||
return $this->getBadge() . $this->createLink($menu); | ||
} | ||
|
||
/** | ||
* Get the problem badge | ||
* | ||
* @return string | ||
*/ | ||
protected function getBadge() | ||
{ | ||
if (count($this->summary) > 0) { | ||
$problems = 0; | ||
$titles = array(); | ||
|
||
foreach ($this->summary as $summary) { | ||
$problems += $summary['problems']; | ||
$titles[] = $summary['title']; | ||
} | ||
|
||
return sprintf( | ||
'<div title="%s" class="badge-container"><span class="badge badge-critical">%s</span></div>', | ||
implode(', ', $titles), | ||
$problems | ||
); | ||
} | ||
return ''; | ||
} | ||
} |