mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-04 05:44:58 +00:00
Notification: add a counter for notifications
This commit is contained in:
@@ -12,18 +12,25 @@ declare(strict_types=1);
|
||||
namespace Chill\MainBundle\Routing\MenuBuilder;
|
||||
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Notification\Counter\NotificationByUserCounter;
|
||||
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||
{
|
||||
private NotificationByUserCounter $notificationByUserCounter;
|
||||
|
||||
private Security $security;
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(Security $security, TranslatorInterface $translator)
|
||||
{
|
||||
public function __construct(
|
||||
NotificationByUserCounter $notificationByUserCounter,
|
||||
Security $security,
|
||||
TranslatorInterface $translator
|
||||
) {
|
||||
$this->notificationByUserCounter = $notificationByUserCounter;
|
||||
$this->security = $security;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
@@ -49,14 +56,17 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||
'icon' => 'map-marker',
|
||||
]);
|
||||
|
||||
$nbNotifications = $this->notificationByUserCounter->countUnreadByUser($user);
|
||||
|
||||
$menu
|
||||
->addChild(
|
||||
$this->translator->trans('My notifications'),
|
||||
$this->translator->trans('notification.My notifications with counter', ['nb' => $nbNotifications]),
|
||||
['route' => 'chill_main_notification_my']
|
||||
)
|
||||
->setExtras([
|
||||
'order' => 600,
|
||||
'icon' => 'envelope',
|
||||
'counter' => $nbNotifications,
|
||||
]);
|
||||
|
||||
$menu
|
||||
|
Reference in New Issue
Block a user