From 160d382e075c3924754f93119845d7269e6cbb6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 4 Jan 2022 17:14:09 +0100 Subject: [PATCH] notification: add notification sent to widget which list notifications ont an entity --- .../Notification/NotificationPresence.php | 8 +++++--- .../Repository/NotificationRepository.php | 9 +++++++-- .../extension_list_notifications_for.html.twig | 6 +++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Notification/NotificationPresence.php b/src/Bundle/ChillMainBundle/Notification/NotificationPresence.php index afb6eba19..91bea3197 100644 --- a/src/Bundle/ChillMainBundle/Notification/NotificationPresence.php +++ b/src/Bundle/ChillMainBundle/Notification/NotificationPresence.php @@ -36,11 +36,13 @@ class NotificationPresence */ public function getNotificationsForClassAndEntity(string $relatedEntityClass, int $relatedEntityId): array { - if ($this->security->getUser() instanceof User) { - return $this->notificationRepository->findNotificationAsAddresseeByRelatedEntityAndUser( + $user = $this->security->getUser(); + + if ($user instanceof User) { + return $this->notificationRepository->findNotificationByRelatedEntityAndUserAssociated( $relatedEntityClass, $relatedEntityId, - $this->security->getUser() + $user ); } diff --git a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php index ce9e3b9e9..e2452dced 100644 --- a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php @@ -148,7 +148,7 @@ final class NotificationRepository implements ObjectRepository /** * @return array|Notification[] */ - public function findNotificationAsAddresseeByRelatedEntityAndUser(string $relatedEntityClass, int $relatedEntityId, User $user): array + public function findNotificationByRelatedEntityAndUserAssociated(string $relatedEntityClass, int $relatedEntityId, User $user): array { $qb = $this->repository->createQueryBuilder('n'); @@ -156,7 +156,12 @@ final class NotificationRepository implements ObjectRepository ->select('n') ->where($qb->expr()->eq('n.relatedEntityClass', ':relatedEntityClass')) ->andWhere($qb->expr()->eq('n.relatedEntityId', ':relatedEntityId')) - ->andWhere($qb->expr()->isMemberOf(':user', 'n.addressees')) + ->andWhere( + $qb->expr()->orX( + $qb->expr()->isMemberOf(':user', 'n.addressees'), + $qb->expr()->eq('n.sender', ':user') + ) + ) ->setParameter('relatedEntityClass', $relatedEntityClass) ->setParameter('relatedEntityId', $relatedEntityId) ->setParameter('user', $user); diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig index 5e5d1dba8..b57aab322 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/extension_list_notifications_for.html.twig @@ -2,7 +2,11 @@ {% for notification in notifications %}
{% if not notification.isSystem %} -
{{ 'notification.you were notified by %sender%'|trans({'%sender%': notification.sender|chill_entity_render_string }) }}
+ {% if notification.sender == app.user %} +
You sent notification to: {% for a in notification.addressees %}{{ a|chill_entity_render_string }}{% if not loop.last %}, {% endif %}{% endfor %}
+ {% else %} +
{{ 'notification.you were notified by %sender%'|trans({'%sender%': notification.sender|chill_entity_render_string }) }}
+ {% endif %} {% else %}
{{ 'notification.you were notified by system'|trans }}
{% endif %}