mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-09 14:59:43 +00:00
52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
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 NotificationRepository $notificationRepository;
|
|
|
|
private Security $security;
|
|
|
|
public function __construct(Security $security, NotificationRepository $notificationRepository)
|
|
{
|
|
$this->security = $security;
|
|
$this->notificationRepository = $notificationRepository;
|
|
}
|
|
|
|
/**
|
|
* @return array|Notification[]
|
|
*/
|
|
public function getNotificationsForClassAndEntity(string $relatedEntityClass, int $relatedEntityId): array
|
|
{
|
|
$user = $this->security->getUser();
|
|
|
|
if ($user instanceof User) {
|
|
return $this->notificationRepository->findNotificationByRelatedEntityAndUserAssociated(
|
|
$relatedEntityClass,
|
|
$relatedEntityId,
|
|
$user
|
|
);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
}
|