Refactor TaskNotificationHandler logic

This commit is contained in:
2025-08-12 10:25:47 +02:00
parent b6b03cfcec
commit 30e1416018

View File

@@ -13,17 +13,14 @@ namespace Chill\TaskBundle\Notification;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Notification\NotificationHandlerInterface; use Chill\MainBundle\Notification\NotificationHandlerInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
use Chill\TaskBundle\Entity\SingleTask; use Chill\TaskBundle\Entity\SingleTask;
use Chill\TaskBundle\Repository\SingleTaskAclAwareRepository;
use Chill\TaskBundle\Repository\SingleTaskRepository; use Chill\TaskBundle\Repository\SingleTaskRepository;
use Symfony\Component\Translation\TranslatableMessage; use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface; use Symfony\Contracts\Translation\TranslatableInterface;
final readonly class TaskNotificationHandler implements NotificationHandlerInterface final readonly class TaskNotificationHandler implements NotificationHandlerInterface
{ {
public function __construct(private SingleTaskRepository $repository) {} public function __construct(private SingleTaskRepository $taskRepository) {}
public function getTemplate(Notification $notification, array $options = []): string public function getTemplate(Notification $notification, array $options = []): string
{ {
@@ -34,7 +31,7 @@ final readonly class TaskNotificationHandler implements NotificationHandlerInter
{ {
return [ return [
'notification' => $notification, 'notification' => $notification,
'task' => $this->repository->find($notification->getRelatedEntityId()), 'task' => $this->taskRepository->find($notification->getRelatedEntityId()),
]; ];
} }
@@ -58,11 +55,15 @@ final readonly class TaskNotificationHandler implements NotificationHandlerInter
return []; return [];
} }
return $task->get; if (null !== $task->getCourse()) {
return $task->getCourse()->getParticipations()->getValues();
}
return [$task->getPerson()];
} }
public function getRelatedEntity(Notification $notification): ?AccompanyingPeriod public function getRelatedEntity(Notification $notification): ?SingleTask
{ {
return $this->accompanyingPeriodRepository->find($notification->getRelatedEntityId()); return $this->taskRepository->find($notification->getRelatedEntityId());
} }
} }