84 lines
2.8 KiB
PHP
84 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Menu;
|
|
|
|
use App\Entity\User;
|
|
use Knp\Menu\FactoryInterface;
|
|
use Knp\Menu\ItemInterface;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
/**
|
|
* Serves the menu of the area the current user has the highest privileges for.
|
|
*
|
|
* Used by templates that are reachable by more than one role, so that the area
|
|
* selection follows a single priority order instead of being decided in Twig.
|
|
*/
|
|
class MenuBuilder extends AbstractMenuBuilder
|
|
{
|
|
public function __construct(
|
|
FactoryInterface $factory,
|
|
Security $security,
|
|
RequestStack $requestStack,
|
|
TranslatorInterface $translator,
|
|
private readonly AdminMenuBuilder $adminMenuBuilder,
|
|
private readonly ManagerMenuBuilder $managerMenuBuilder,
|
|
private readonly HouseManagerMenuBuilder $houseManagerMenuBuilder,
|
|
private readonly TeamerMenuBuilder $teamerMenuBuilder,
|
|
) {
|
|
parent::__construct($factory, $security, $requestStack, $translator);
|
|
}
|
|
|
|
public function createMainMenu(array $options): ItemInterface
|
|
{
|
|
$area = $this->resolveArea();
|
|
$menu = match ($area) {
|
|
'ROLE_TEAM_ADMIN' => $this->adminMenuBuilder->createMainMenu($options),
|
|
'ROLE_MANAGER' => $this->managerMenuBuilder->createMainMenu($options),
|
|
'ROLE_HOUSE_MANAGER' => $this->houseManagerMenuBuilder->createMainMenu($options),
|
|
'ROLE_TEAMER' => $this->teamerMenuBuilder->createMainMenu($options),
|
|
default => $this->createRootElement(),
|
|
};
|
|
|
|
$user = $this->security->getUser();
|
|
|
|
if ($user instanceof User) {
|
|
$this->addDivider($menu);
|
|
|
|
// A group without uri, so the sidebar renders it collapsible; the teamer menu has its own "Mein Profil".
|
|
$account = $menu->addChild('account', [
|
|
'label' => 'Mein Account',
|
|
'extras' => [
|
|
'icon' => 'user',
|
|
],
|
|
]);
|
|
|
|
$this->addAccountItems($account, withIcons: false, withProfile: 'ROLE_TEAMER' !== $area);
|
|
}
|
|
|
|
return $menu;
|
|
}
|
|
|
|
/**
|
|
* The account menu behind the user's picture in the header: own profile, the other areas and logout.
|
|
*/
|
|
public function createUserMenu(array $options): ItemInterface
|
|
{
|
|
$menu = $this->createRootElement();
|
|
|
|
$this->addAccountItems($menu);
|
|
|
|
return $menu;
|
|
}
|
|
|
|
public function createTeamerMenu(array $options): ItemInterface
|
|
{
|
|
return match ($this->resolveArea()) {
|
|
'ROLE_TEAM_ADMIN' => $this->adminMenuBuilder->createTeamerMenu($options),
|
|
'ROLE_MANAGER' => $this->managerMenuBuilder->createTeamerMenu($options),
|
|
default => $this->createRootElement(),
|
|
};
|
|
}
|
|
}
|