mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
59 lines
1.9 KiB
PHP
59 lines
1.9 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\ActivityBundle\Menu;
|
|
|
|
use Chill\ActivityBundle\Entity\Activity;
|
|
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
|
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
|
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
use Knp\Menu\MenuItem;
|
|
use Symfony\Component\Security\Core\Security;
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
/**
|
|
* @implements LocalMenuBuilderInterface<array{accompanyingCourse: AccompanyingPeriod}>
|
|
*/
|
|
class AccompanyingCourseMenuBuilder implements LocalMenuBuilderInterface
|
|
{
|
|
public function __construct(
|
|
protected Security $security,
|
|
protected TranslatorInterface $translator,
|
|
private readonly \Doctrine\Persistence\ManagerRegistry $managerRegistry,
|
|
) {}
|
|
|
|
public function buildMenu($menuId, MenuItem $menu, array $parameters): void
|
|
{
|
|
$period = $parameters['accompanyingCourse'];
|
|
|
|
$activities = $this->managerRegistry->getManager()->getRepository(Activity::class)->findBy(
|
|
['accompanyingPeriod' => $period]
|
|
);
|
|
|
|
if (
|
|
AccompanyingPeriod::STEP_DRAFT !== $period->getStep()
|
|
&& $this->security->isGranted(ActivityVoter::SEE, $period)
|
|
) {
|
|
$menu->addChild($this->translator->trans('Activities'), [
|
|
'route' => 'chill_activity_activity_list',
|
|
'routeParameters' => [
|
|
'accompanying_period_id' => $period->getId(),
|
|
], ])
|
|
->setExtras(['order' => 40, 'counter' => count($activities) > 0 ? count($activities) : null]);
|
|
}
|
|
}
|
|
|
|
public static function getMenuIds(): array
|
|
{
|
|
return ['accompanyingCourse'];
|
|
}
|
|
}
|