mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 06:14:23 +00:00
71 lines
2.0 KiB
PHP
71 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace Chill\EventBundle\Menu;
|
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
|
use Symfony\Component\Translation\TranslatorInterface;
|
|
use Symfony\Component\Security\Core\Role\Role;
|
|
use Knp\Menu\MenuItem;
|
|
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
|
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
|
|
use Chill\EventBundle\Security\Authorization\EventVoter;
|
|
|
|
class PersonMenuBuilder implements LocalMenuBuilderInterface
|
|
{
|
|
/**
|
|
*
|
|
* @var TokenStorageInterface
|
|
*/
|
|
protected $tokenStorage;
|
|
|
|
/**
|
|
*
|
|
* @var TranslatorInterface
|
|
*/
|
|
protected $translator;
|
|
|
|
/**
|
|
*
|
|
* @var AuthorizationHelper
|
|
*/
|
|
protected $authorizationHelper;
|
|
|
|
public function __construct(
|
|
AuthorizationHelper $authorizationHelper,
|
|
TokenStorageInterface $tokenStorage,
|
|
TranslatorInterface $translator
|
|
) {
|
|
$this->tokenStorage = $tokenStorage;
|
|
$this->translator = $translator;
|
|
$this->authorizationHelper = $authorizationHelper;
|
|
}
|
|
|
|
|
|
public function buildMenu($menuId, MenuItem $menu, array $parameters)
|
|
{
|
|
/* @var $person \Chill\PersonBundle\Entity\Person */
|
|
$person = $parameters['person'];
|
|
|
|
$user = $this->tokenStorage->getToken()->getUser();
|
|
$roleSee = new Role(EventVoter::SEE);
|
|
|
|
// ASK use authorizationHelper or authorizationChecker ??
|
|
if ($this->authorizationHelper->userHasAccess($user, $person, $roleSee)) {
|
|
|
|
$menu->addChild($this->translator->trans('Events participation'), [
|
|
'route' => 'chill_event__list_by_person',
|
|
'routeParameters' => [
|
|
'person_id' => $person->getId()
|
|
]
|
|
])
|
|
->setExtras([
|
|
'order' => 500
|
|
]);
|
|
}
|
|
}
|
|
|
|
public static function getMenuIds(): array
|
|
{
|
|
return [ 'person' ];
|
|
}
|
|
} |