mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
notification: store users which are unread instead of read, and in
dedicated table The query "which are the unread notification" is much more frequent than the read one. We then store the unread items in a dedicated table.
This commit is contained in:
@@ -118,9 +118,9 @@ class NotificationController extends AbstractController
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/my", name="chill_main_notification_my")
|
||||
* @Route("/inbox", name="chill_main_notification_my")
|
||||
*/
|
||||
public function myAction(): Response
|
||||
public function inboxAction(): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
|
||||
$currentUser = $this->security->getUser();
|
||||
@@ -134,21 +134,61 @@ class NotificationController extends AbstractController
|
||||
$offset = $paginator->getCurrentPage()->getFirstItemNumber()
|
||||
);
|
||||
|
||||
return $this->render('@ChillMain/Notification/list.html.twig', [
|
||||
'datas' => $this->itemsForTemplate($notifications),
|
||||
'notifications' => $notifications,
|
||||
'paginator' => $paginator,
|
||||
'step' => 'inbox',
|
||||
'unreads' => $this->countUnread(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/sent", name="chill_main_notification_sent")
|
||||
*/
|
||||
public function sentAction(): Response
|
||||
{
|
||||
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
|
||||
$currentUser = $this->security->getUser();
|
||||
|
||||
$notificationsNbr = $this->notificationRepository->countAllForSender($currentUser);
|
||||
$paginator = $this->paginatorFactory->create($notificationsNbr);
|
||||
|
||||
$notifications = $this->notificationRepository->findAllForSender(
|
||||
$currentUser,
|
||||
$limit = $paginator->getItemsPerPage(),
|
||||
$offset = $paginator->getCurrentPage()->getFirstItemNumber()
|
||||
);
|
||||
|
||||
return $this->render('@ChillMain/Notification/list.html.twig', [
|
||||
'datas' => $this->itemsForTemplate($notifications),
|
||||
'notifications' => $notifications,
|
||||
'paginator' => $paginator,
|
||||
'step' => 'sent',
|
||||
'unreads' => $this->countUnread(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function countUnread(): array
|
||||
{
|
||||
return [
|
||||
'sent' => $this->notificationRepository->countUnreadByUserWhereSender($this->security->getUser()),
|
||||
'inbox' => $this->notificationRepository->countUnreadByUserWhereAddressee($this->security->getUser()),
|
||||
];
|
||||
}
|
||||
|
||||
private function itemsForTemplate(array $notifications): array
|
||||
{
|
||||
$templateData = [];
|
||||
|
||||
foreach ($notifications as $notification) {
|
||||
$data = [
|
||||
$templateData[] = [
|
||||
'template' => $this->notificationHandlerManager->getTemplate($notification),
|
||||
'template_data' => $this->notificationHandlerManager->getTemplateData($notification),
|
||||
'notification' => $notification,
|
||||
];
|
||||
$templateData[] = $data;
|
||||
}
|
||||
|
||||
return $this->render('@ChillMain/Notification/show.html.twig', [
|
||||
'datas' => $templateData,
|
||||
'notifications' => $notifications,
|
||||
'paginator' => $paginator,
|
||||
]);
|
||||
return $templateData;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user