2023-03-11 15:14:05 +01:00
|
|
|
<?php
|
|
|
|
/*****************************************************************************
|
|
|
|
* NavBar.php
|
|
|
|
* Contains the navigational menu template.
|
|
|
|
*
|
2023-04-08 21:32:38 +02:00
|
|
|
* Kabuki CMS (C) 2013-2023, Aaron van Geffen
|
2023-03-11 15:14:05 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
abstract class NavBar extends Template
|
|
|
|
{
|
|
|
|
protected $primaryBadgeClasses = 'bg-dark text-light';
|
|
|
|
protected $secondaryBadgeClasses = 'bg-light text-dark';
|
|
|
|
|
|
|
|
public function renderMenu(array $items, $navBarClasses = '')
|
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<ul class="navbar-nav ', $navBarClasses, '">';
|
|
|
|
|
|
|
|
$this->renderMenuItems($items, $navBarClasses);
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</ul>';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function renderMenuItems(array $items)
|
|
|
|
{
|
|
|
|
foreach ($items as $menuId => $item)
|
|
|
|
{
|
|
|
|
if (isset($item['icon']))
|
|
|
|
$item['label'] = '<i class="bi bi-' . $item['icon'] . '"></i> ' . $item['label'];
|
|
|
|
|
|
|
|
if (isset($item['badge']))
|
|
|
|
$item['label'] .= ' <span class="badge ' . $this->primaryBadgeClasses . '">' . $item['badge'] . '</span>';
|
|
|
|
|
|
|
|
if (empty($item['subs']))
|
|
|
|
{
|
|
|
|
echo '
|
|
|
|
<li class="nav-item"><a class="nav-link" href="', $item['url'], '">', $item['label'], '</a></li>';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<li class="nav-item dropdown">
|
|
|
|
<a class="nav-link dropdown-toggle" href="#" id="menu', $menuId, '" data-bs-toggle="dropdown" aria-expanded="false">', $item['label'], '</a>
|
|
|
|
<ul class="dropdown-menu" aria-labelledby="menu', $menuId, '">';
|
|
|
|
|
|
|
|
foreach ($item['subs'] as $subitem)
|
|
|
|
{
|
|
|
|
if (isset($subitem['badge']))
|
|
|
|
$subitem['label'] .= ' <span class="badge ' . $this->secondaryBadgeClasses . '">' . $subitem['badge'] . '</span>';
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<li><a class="dropdown-item" href="', $subitem['url'], '">', $subitem['label'], '</a></li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</ul>
|
|
|
|
</li>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|