pics/templates/NavBar.php

62 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/*****************************************************************************
* NavBar.php
* Contains the navigational menu template.
*
* Kabuki CMS (C) 2013-2023, Aaron van Geffen
*****************************************************************************/
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>';
}
}
}