Menu: Provide own class for dashboard homes navigation items

This commit is contained in:
Yonas Habteab 2022-03-11 16:43:05 +01:00
parent c94284e9b2
commit 715adfedb1

View File

@ -0,0 +1,41 @@
<?php
namespace Icinga\Web;
use Icinga\Model\Home;
use Icinga\Web\Dashboard\Dashboard;
use Icinga\Web\Navigation\DashboardHome;
use ipl\Stdlib\Filter;
/**
* Entrypoint of the dashboard homes
*/
class HomeMenu extends Menu
{
public function __construct()
{
parent::__construct();
$this->initHome();
}
public function initHome()
{
$user = Dashboard::getUser();
$dashboardItem = $this->getItem('dashboard');
$homes = Home::on(Dashboard::getConn());
$homes->filter(Filter::equal('username', $user->getUsername()));
foreach ($homes as $home) {
$dashboardHome = new DashboardHome($home->name, [
'uuid' => $home->id,
'label' => t($home->label),
'priority' => $home->priority,
'type' => $home->type,
]);
$dashboardItem->addChild($dashboardHome);
}
}
}