fix controller loading and add UserMenu entry

This commit is contained in:
2021-12-25 20:47:54 +01:00
parent 6a0ce72836
commit e972beee11
3 changed files with 39 additions and 16 deletions

View File

@@ -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;