mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
80 lines
2.5 KiB
PHP
80 lines
2.5 KiB
PHP
<?php
|
|
/*
|
|
*/
|
|
namespace Chill\DocStoreBundle\Menu;
|
|
|
|
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
|
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
|
use Knp\Menu\MenuItem;
|
|
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
|
use Symfony\Component\Security\Core\Security;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
final class MenuBuilder implements LocalMenuBuilderInterface
|
|
{
|
|
private Security $security;
|
|
protected TranslatorInterface $translator;
|
|
|
|
public function __construct(
|
|
Security $security,
|
|
TranslatorInterface $translator
|
|
) {
|
|
$this->security = $security;
|
|
$this->translator = $translator;
|
|
}
|
|
|
|
|
|
public function buildMenu($menuId, MenuItem $menu, array $parameters)
|
|
{
|
|
switch($menuId) {
|
|
case 'accompanyingCourse':
|
|
$this->buildMenuAccompanyingCourse($menu, $parameters);
|
|
break;
|
|
case 'person':
|
|
$this->buildMenuPerson($menu, $parameters);
|
|
break;
|
|
default:
|
|
throw new \LogicException("this menuid $menuId is not implemented");
|
|
}
|
|
}
|
|
|
|
protected function buildMenuPerson(MenuItem $menu, array $parameters)
|
|
{
|
|
/* @var $person \Chill\PersonBundle\Entity\Person */
|
|
$person = $parameters['person'];
|
|
|
|
if ($this->security->isGranted(PersonDocumentVoter::SEE, $person)) {
|
|
$menu->addChild($this->translator->trans('Documents'), [
|
|
'route' => 'person_document_index',
|
|
'routeParameters' => [
|
|
'person' => $person->getId()
|
|
]
|
|
])
|
|
->setExtras([
|
|
'order'=> 350
|
|
]);
|
|
}
|
|
}
|
|
|
|
protected function buildMenuAccompanyingCourse(MenuItem $menu, array $parameters){
|
|
$course = $parameters['accompanyingCourse'];
|
|
|
|
if ($this->security->isGranted(AccompanyingCourseDocumentVoter::SEE, $course)) {
|
|
$menu->addChild($this->translator->trans('Documents'), [
|
|
'route' => 'accompanying_course_document_index',
|
|
'routeParameters' => [
|
|
'course' => $course->getId()
|
|
]
|
|
])
|
|
->setExtras([
|
|
'order' => 400
|
|
]);
|
|
}
|
|
}
|
|
|
|
public static function getMenuIds(): array
|
|
{
|
|
return [ 'person', 'accompanyingCourse' ];
|
|
}
|
|
}
|