From a4afe73efe3458631663583f2c8a49768d3bf22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 6 Apr 2022 13:35:24 +0200 Subject: [PATCH] take into account system notification in counter and fix hardcoded user id --- .../ChillMainBundle/Repository/NotificationRepository.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php index 9cfffb2cf..3f3b08f6c 100644 --- a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php @@ -56,17 +56,18 @@ final class NotificationRepository implements ObjectRepository if (null === $this->notificationByRelatedEntityAndUserAssociatedStatement) { $sql = 'SELECT - SUM((EXISTS (SELECT 1 AS c FROM chill_main_notification_addresses_unread cmnau WHERE user_id = 1812 and cmnau.notification_id = cmn.id))::int) AS unread, - SUM((cmn.sender_id = 1812)::int) AS sent, + SUM((EXISTS (SELECT 1 AS c FROM chill_main_notification_addresses_unread cmnau JOIN chill_main_notification cmn ON cmnau.notification_id = cmn.id WHERE user_id = :userid and cmnau.notification_id = cmn.id and cmn.sender_id IS NOT NULL))::int) AS unread, + SUM((cmn.sender_id = :userid)::int) AS sent, COUNT(cmn.*) AS total FROM chill_main_notification cmn WHERE relatedentityclass = :relatedEntityClass AND relatedentityid = :relatedEntityId AND sender_id IS NOT NULL'; + $this->notificationByRelatedEntityAndUserAssociatedStatement = $this->em->getConnection()->prepare($sql); } $results = $this->notificationByRelatedEntityAndUserAssociatedStatement - ->executeQuery(['relatedEntityClass' => $relatedEntityClass, 'relatedEntityId' => $relatedEntityId]); + ->executeQuery(['relatedEntityClass' => $relatedEntityClass, 'relatedEntityId' => $relatedEntityId, 'userid' => $user->getId()]); $result = $results->fetchAssociative();