mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix controller loading and add UserMenu entry
This commit is contained in:
parent
6a0ce72836
commit
e972beee11
@ -15,6 +15,7 @@ use Chill\MainBundle\Notification\NotificationRenderer;
|
||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
||||
use Chill\MainBundle\Repository\NotificationRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
@ -23,27 +24,34 @@ use Symfony\Component\Security\Core\Security;
|
||||
*/
|
||||
class NotificationController extends AbstractController
|
||||
{
|
||||
private $security;
|
||||
private Security $security;
|
||||
private NotificationRepository $notificationRepository;
|
||||
private NotificationRenderer $notificationRenderer;
|
||||
private PaginatorFactory $paginatorFactory;
|
||||
|
||||
public function __construct(Security $security)
|
||||
{
|
||||
public function __construct(
|
||||
Security $security,
|
||||
NotificationRepository $notificationRepository,
|
||||
NotificationRenderer $notificationRenderer,
|
||||
PaginatorFactory $paginatorFactory
|
||||
) {
|
||||
$this->security = $security;
|
||||
$this->notificationRepository = $notificationRepository;
|
||||
$this->notificationRenderer = $notificationRenderer;
|
||||
$this->paginatorFactory = $paginatorFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/show", name="chill_main_notification_show")
|
||||
*/
|
||||
public function showAction(
|
||||
NotificationRepository $notificationRepository,
|
||||
NotificationRenderer $notificationRenderer,
|
||||
PaginatorFactory $paginatorFactory
|
||||
) {
|
||||
public function showAction(): Response
|
||||
{
|
||||
$currentUser = $this->security->getUser();
|
||||
|
||||
$notificationsNbr = $notificationRepository->countAllForAttendee(($currentUser));
|
||||
$paginator = $paginatorFactory->create($notificationsNbr);
|
||||
$notificationsNbr = $this->notificationRepository->countAllForAttendee(($currentUser));
|
||||
$paginator = $this->paginatorFactory->create($notificationsNbr);
|
||||
|
||||
$notifications = $notificationRepository->findAllForAttendee(
|
||||
$notifications = $this->notificationRepository->findAllForAttendee(
|
||||
$currentUser,
|
||||
$limit = $paginator->getItemsPerPage(),
|
||||
$offset = $paginator->getCurrentPage()->getFirstItemNumber()
|
||||
@ -53,8 +61,8 @@ class NotificationController extends AbstractController
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$data = [
|
||||
'template' => $notificationRenderer->getTemplate($notification),
|
||||
'template_data' => $notificationRenderer->getTemplateData($notification),
|
||||
'template' => $this->notificationRenderer->getTemplate($notification),
|
||||
'template_data' => $this->notificationRenderer->getTemplateData($notification),
|
||||
'notification' => $notification,
|
||||
];
|
||||
$templateData[] = $data;
|
||||
|
@ -48,7 +48,7 @@ class Notification
|
||||
/**
|
||||
* @ORM\Column(type="text")
|
||||
*/
|
||||
private string $message;
|
||||
private string $message = '';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="json")
|
||||
@ -58,7 +58,7 @@ class Notification
|
||||
/**
|
||||
* @ORM\Column(type="string", length=255)
|
||||
*/
|
||||
private string $relatedEntityClass;
|
||||
private string $relatedEntityClass = '';
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="integer")
|
||||
|
@ -14,14 +14,18 @@ namespace Chill\MainBundle\Routing\MenuBuilder;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||
{
|
||||
private Security $security;
|
||||
|
||||
public function __construct(Security $security)
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(Security $security, TranslatorInterface $translator)
|
||||
{
|
||||
$this->security = $security;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters)
|
||||
@ -44,6 +48,17 @@ class UserMenuBuilder implements LocalMenuBuilderInterface
|
||||
'order' => -9999999,
|
||||
'icon' => 'map-marker',
|
||||
]);
|
||||
|
||||
$menu
|
||||
->addChild(
|
||||
$this->translator->trans('My notifications'),
|
||||
['route' => 'chill_main_notification_show']
|
||||
)
|
||||
->setExtras([
|
||||
'order' => 600,
|
||||
'icon' => 'envelope'
|
||||
]);
|
||||
|
||||
$menu
|
||||
->addChild(
|
||||
'Change password',
|
||||
|
Loading…
x
Reference in New Issue
Block a user