twig extension for listing notification on a given entity

This commit is contained in:
2021-12-30 01:02:16 +01:00
parent 1576507f7e
commit 7bc4ad9779
7 changed files with 148 additions and 3 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace Chill\MainBundle\Notification;
use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Repository\NotificationRepository;
use Symfony\Component\Security\Core\Security;
/**
* Helps to find if a notification exist for a given entity
*/
class NotificationPresence
{
private Security $security;
private NotificationRepository $notificationRepository;
public function __construct(Security $security, NotificationRepository $notificationRepository)
{
$this->security = $security;
$this->notificationRepository = $notificationRepository;
}
/**
* @return array|Notification[]
*/
public function getNotificationsForClassAndEntity(string $relatedEntityClass, int $relatedEntityId): array
{
if ($this->security->getUser() instanceof User) {
return $this->notificationRepository->findNotificationAsAddresseeByRelatedEntityAndUser(
$relatedEntityClass,
$relatedEntityId,
$this->security->getUser()
);
}
return [];
}
}