mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 14:24:24 +00:00
94 lines
2.7 KiB
PHP
94 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/*
|
|
* 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.
|
|
*/
|
|
|
|
namespace Chill\DocStoreBundle\Menu;
|
|
|
|
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
|
use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter;
|
|
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
|
use Knp\Menu\MenuItem;
|
|
use LogicException;
|
|
use Symfony\Component\Security\Core\Security;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
final class MenuBuilder implements LocalMenuBuilderInterface
|
|
{
|
|
private Security $security;
|
|
|
|
private 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");
|
|
}
|
|
}
|
|
|
|
public static function getMenuIds(): array
|
|
{
|
|
return ['person', 'accompanyingCourse'];
|
|
}
|
|
|
|
private function buildMenuAccompanyingCourse(MenuItem $menu, array $parameters)
|
|
{
|
|
$course = $parameters['accompanyingCourse'];
|
|
|
|
if ($this->security->isGranted(AccompanyingCourseDocumentVoter::SEE, $course)) {
|
|
$menu->addChild($this->translator->trans('Documents'), [
|
|
'route' => 'chill_docstore_generic-doc_by-period_index',
|
|
'routeParameters' => [
|
|
'id' => $course->getId(),
|
|
],
|
|
])
|
|
->setExtras([
|
|
'order' => 400,
|
|
]);
|
|
}
|
|
}
|
|
|
|
private function buildMenuPerson(MenuItem $menu, array $parameters)
|
|
{
|
|
/** @var \Chill\PersonBundle\Entity\Person $person */
|
|
$person = $parameters['person'];
|
|
|
|
if ($this->security->isGranted(PersonDocumentVoter::SEE, $person)) {
|
|
$menu->addChild($this->translator->trans('Documents'), [
|
|
'route' => 'chill_docstore_generic-doc_by-person_index',
|
|
'routeParameters' => [
|
|
'id' => $person->getId(),
|
|
],
|
|
])
|
|
->setExtras([
|
|
'order' => 350,
|
|
]);
|
|
}
|
|
}
|
|
}
|