mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-05 14:25:00 +00:00
#365 Add works and activities counter
This commit is contained in:
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\ActivityBundle\Menu;
|
||||
|
||||
use Chill\ActivityBundle\Repository\ActivityACLAwareRepositoryInterface;
|
||||
use Chill\ActivityBundle\Security\Authorization\ActivityVoter;
|
||||
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
@@ -23,13 +24,20 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
*/
|
||||
final readonly class PersonMenuBuilder implements LocalMenuBuilderInterface
|
||||
{
|
||||
public function __construct(private AuthorizationCheckerInterface $authorizationChecker, private TranslatorInterface $translator) {}
|
||||
public function __construct(
|
||||
private readonly ActivityACLAwareRepositoryInterface $activityACLAwareRepository,
|
||||
private AuthorizationCheckerInterface $authorizationChecker,
|
||||
private TranslatorInterface $translator,
|
||||
) {}
|
||||
|
||||
public function buildMenu($menuId, MenuItem $menu, array $parameters)
|
||||
{
|
||||
/** @var Person $person */
|
||||
$person = $parameters['person'];
|
||||
|
||||
|
||||
$count = $this->activityACLAwareRepository->countByPerson($person, ActivityVoter::SEE);
|
||||
|
||||
if ($this->authorizationChecker->isGranted(ActivityVoter::SEE, $person)) {
|
||||
$menu->addChild(
|
||||
$this->translator->trans('Activities'),
|
||||
@@ -38,7 +46,7 @@ final readonly class PersonMenuBuilder implements LocalMenuBuilderInterface
|
||||
'routeParameters' => ['person_id' => $person->getId()],
|
||||
]
|
||||
)
|
||||
->setExtra('order', 201);
|
||||
->setExtras(['order' => 201, 'counter' => $count > 0 ? $count : null]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user