select()->from( 'statusSummary', array( 'hosts_down_unhandled', 'services_critical_unhandled' ) )->getQuery()->fetchRow(); } if ($column === null) { return self::$summary; } elseif (isset(self::$summary->$column)) { return self::$summary->$column; } else { return null; } } protected function getBadgeTitle() { $translations = array( 'hosts_down_unhandled' => mt('monitoring', '%d unhandled hosts down'), 'services_critical_unhandled' => mt('monitoring', '%d unhandled services critical') ); $titles = array(); $sum = $this->summary(); foreach ($this->columns as $col) { if (isset($sum->$col) && $sum->$col > 0) { $titles[] = sprintf($translations[$col], $sum->$col); } } return implode(', ', $titles); } protected function countItems() { $sum = self::summary(); $count = 0; foreach ($this->columns as $col) { if (isset($sum->$col)) { $count += $sum->$col; } } return $count; } public function render(Menu $menu) { $count = $this->countItems(); $badge = ''; if ($count) { $badge = sprintf( '
%s
', $this->getBadgeTitle(), $count ); } if ($menu->getIcon() && strpos($menu->getIcon(), '.') === false) { return sprintf( '%s %s', $badge, $menu->getUrl() ?: '#', $menu->getIcon(), htmlspecialchars($menu->getTitle()) ); } return sprintf( '%s%s%s', $badge, $menu->getUrl() ?: '#', $menu->getIcon() ? ' ' : '', htmlspecialchars($menu->getTitle()) ); } }