mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 02:53:50 +00:00
Resolve "Afficher les noms des usagers et l'entité concerné par l'entité notifiée dans la liste des notifications"
This commit is contained in:
@@ -15,10 +15,13 @@ use Chill\ActivityBundle\Entity\Activity;
|
||||
use Chill\ActivityBundle\Repository\ActivityRepository;
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\MainBundle\Notification\NotificationHandlerInterface;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||
use Symfony\Component\Translation\TranslatableMessage;
|
||||
use Symfony\Contracts\Translation\TranslatableInterface;
|
||||
|
||||
final readonly class ActivityNotificationHandler implements NotificationHandlerInterface
|
||||
{
|
||||
public function __construct(private ActivityRepository $activityRepository) {}
|
||||
public function __construct(private ActivityRepository $activityRepository, private TranslatableStringHelperInterface $translatableStringHelper) {}
|
||||
|
||||
public function getTemplate(Notification $notification, array $options = []): string
|
||||
{
|
||||
@@ -37,4 +40,30 @@ final readonly class ActivityNotificationHandler implements NotificationHandlerI
|
||||
{
|
||||
return Activity::class === $notification->getRelatedEntityClass();
|
||||
}
|
||||
|
||||
public function getTitle(Notification $notification, array $options = []): TranslatableInterface
|
||||
{
|
||||
if (null === $activity = $this->getRelatedEntity($notification)) {
|
||||
return new TranslatableMessage('activity.deleted');
|
||||
}
|
||||
|
||||
return new TranslatableMessage('activity.title', [
|
||||
'date' => $activity->getDate(),
|
||||
'type' => $this->translatableStringHelper->localize($activity->getActivityType()->getName()),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getAssociatedPersons(Notification $notification, array $options = []): array
|
||||
{
|
||||
if (null === $activity = $this->getRelatedEntity($notification)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $activity->getPersonsAssociated();
|
||||
}
|
||||
|
||||
public function getRelatedEntity(Notification $notification): ?Activity
|
||||
{
|
||||
return $this->activityRepository->find($notification->getRelatedEntityId());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user