chill-bundles/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php

82 lines
2.5 KiB
PHP

<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Menu;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Chill\PersonBundle\Security\Authorization\PersonVoter;
use Doctrine\ORM\Query\Parameter;
use Knp\Menu\MenuItem;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class SectionMenuBuilder.
*/
class SectionMenuBuilder implements LocalMenuBuilderInterface
{
protected AuthorizationCheckerInterface $authorizationChecker;
protected TranslatorInterface $translator;
protected ParameterBagInterface $parameterBag;
/**
* SectionMenuBuilder constructor.
*/
public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator, ParameterBagInterface $parameterBag)
{
$this->authorizationChecker = $authorizationChecker;
$this->translator = $translator;
$this->parameterBag = $parameterBag;
}
/**
* @param $menuId
*/
public function buildMenu($menuId, MenuItem $menu, array $parameters)
{
if ($this->authorizationChecker->isGranted(PersonVoter::CREATE) && $this->parameterBag->get('chill_person.create_person_allowed')) {
$menu->addChild($this->translator->trans('Add a person'), [
'route' => 'chill_person_new',
])
->setExtras([
'order' => 10,
'icons' => ['plus'],
]);
}
if ($this->parameterBag->get('chill_person.create_parcours_allowed')) {
$menu->addChild($this->translator->trans('Create an accompanying course'), [
'route' => 'chill_person_accompanying_course_new',
])
->setExtras([
'order' => 11,
'icons' => ['plus'],
]);
}
$menu->addChild($this->translator->trans('Accompanying courses of users'), [
'route' => 'chill_course_list_reassign',
])
->setExtras([
'order' => 12,
'icons' => ['task'],
]);
}
public static function getMenuIds(): array
{
return ['section'];
}
}