mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
95 lines
2.9 KiB
PHP
95 lines
2.9 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\Entity\User;
|
|
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
|
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
|
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
|
use Knp\Menu\MenuItem;
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
|
use Symfony\Component\Security\Core\Security;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
/**
|
|
* Class SectionMenuBuilder.
|
|
*/
|
|
class SectionMenuBuilder implements LocalMenuBuilderInterface
|
|
{
|
|
protected ParameterBagInterface $parameterBag;
|
|
|
|
protected TranslatorInterface $translator;
|
|
|
|
private Security $security;
|
|
|
|
/**
|
|
* SectionMenuBuilder constructor.
|
|
*/
|
|
public function __construct(ParameterBagInterface $parameterBag, Security $security, TranslatorInterface $translator)
|
|
{
|
|
$this->parameterBag = $parameterBag;
|
|
$this->security = $security;
|
|
$this->translator = $translator;
|
|
}
|
|
|
|
/**
|
|
* @param $menuId
|
|
*/
|
|
public function buildMenu($menuId, MenuItem $menu, array $parameters)
|
|
{
|
|
if ($this->security->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'],
|
|
]);
|
|
}
|
|
|
|
if ($this->security->isGranted(AccompanyingPeriodVoter::REASSIGN_BULK, null)) {
|
|
$menu->addChild($this->translator->trans('reassign.Bulk reassign'), [
|
|
'route' => 'chill_course_list_reassign',
|
|
])
|
|
->setExtras([
|
|
'order' => 40,
|
|
'icons' => [],
|
|
]);
|
|
}
|
|
|
|
if ($this->security->getUser() instanceof User && $this->security->isGranted('ROLE_USER')) {
|
|
$menu
|
|
->addChild('Régulation', [
|
|
'route' => 'chill_person_course_list_regulation',
|
|
])
|
|
->setExtras([
|
|
'order' => 150,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public static function getMenuIds(): array
|
|
{
|
|
return ['section'];
|
|
}
|
|
}
|