diff --git a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php index debf0f1be..8eb897f11 100644 --- a/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php +++ b/src/Bundle/ChillTaskBundle/Controller/SingleTaskController.php @@ -23,6 +23,7 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Privacy\PrivacyEvent; use Chill\TaskBundle\Entity\SingleTask; +use Chill\TaskBundle\Event\AssignTaskEvent; use Chill\TaskBundle\Event\TaskEvent; use Chill\TaskBundle\Event\UI\UIEvent; use Chill\TaskBundle\Form\SingleTaskType; @@ -525,6 +526,13 @@ final class SingleTaskController extends AbstractController $this->eventDispatcher->dispatch(new TaskEvent($task), TaskEvent::PERSIST); + if (null !== $task->getAssignee()) { + $this->eventDispatcher->dispatch( + new AssignTaskEvent($task, $user), + AssignTaskEvent::PERSIST + ); + } + $em->flush(); $this->addFlash('success', $this->translator->trans('The task is created')); diff --git a/src/Bundle/ChillTaskBundle/DependencyInjection/ChillTaskExtension.php b/src/Bundle/ChillTaskBundle/DependencyInjection/ChillTaskExtension.php index 0122861d6..8a9f95d14 100644 --- a/src/Bundle/ChillTaskBundle/DependencyInjection/ChillTaskExtension.php +++ b/src/Bundle/ChillTaskBundle/DependencyInjection/ChillTaskExtension.php @@ -42,6 +42,7 @@ class ChillTaskExtension extends Extension implements PrependExtensionInterface $loader->load('services/timeline.yaml'); $loader->load('services/fixtures.yaml'); $loader->load('services/form.yaml'); + $loader->load('services/notification.yaml'); } public function prepend(ContainerBuilder $container) diff --git a/src/Bundle/ChillTaskBundle/Event/AssignTaskEvent.php b/src/Bundle/ChillTaskBundle/Event/AssignTaskEvent.php new file mode 100644 index 000000000..ba582a9ed --- /dev/null +++ b/src/Bundle/ChillTaskBundle/Event/AssignTaskEvent.php @@ -0,0 +1,35 @@ +task; + } + + public function getAssignedUser(): User + { + return $this->assignedUser; + } +} diff --git a/src/Bundle/ChillTaskBundle/Event/TaskAssignEventSubscriber.php b/src/Bundle/ChillTaskBundle/Event/TaskAssignEventSubscriber.php new file mode 100644 index 000000000..701d3277b --- /dev/null +++ b/src/Bundle/ChillTaskBundle/Event/TaskAssignEventSubscriber.php @@ -0,0 +1,63 @@ + ['onTaskAssigned', 0], + ]; + } + + /** + * Send a notification when a user is assigned to a task. + * + * The notification will be sent to the newly assigned user + */ + public function onTaskAssigned(AssignTaskEvent $event): void + { + $task = $event->getTask(); + $assignedUser = $event->getAssignedUser(); + + $title = $task->getTitle(); + + $context = [ + 'task' => $task, + 'assignedUser' => $assignedUser, + 'title' => $title, + ]; + + $notification = new Notification(); + $notification + ->setRelatedEntityId($task->getId()) + ->setRelatedEntityClass(SingleTask::class) + ->setTitle($this->engine->render('@ChillTask/Notification/task_assignment_notification_title.txt.twig', $context)) + ->setMessage($this->engine->render('@ChillTask/Notification/task_assignment_notification_content.txt.twig', $context)) + ->addAddressee($assignedUser) + ->setType(AssignTaskNotificationFlagProvider::FLAG); + + $this->entityManager->persist($notification); + } +} diff --git a/src/Bundle/ChillTaskBundle/Notification/AssignTaskNotificationFlagProvider.php b/src/Bundle/ChillTaskBundle/Notification/AssignTaskNotificationFlagProvider.php new file mode 100644 index 000000000..2be454840 --- /dev/null +++ b/src/Bundle/ChillTaskBundle/Notification/AssignTaskNotificationFlagProvider.php @@ -0,0 +1,21 @@ + $task->getId()]); + return new TranslatableMessage('notification.task.title %title%', ['title' => $task->getTitle()]); } public function getAssociatedPersons(Notification $notification, array $options = []): array @@ -62,7 +62,7 @@ final readonly class TaskNotificationHandler implements NotificationHandlerInter return [$task->getPerson()]; } - public function getRelatedEntity(Notification $notification): ?SingleTask + public function getRelatedEntity(Notification $notification): object { return $this->taskRepository->find($notification->getRelatedEntityId()); } diff --git a/src/Bundle/ChillTaskBundle/Resources/views/Notification/task_assignment_notification_content.txt.twig b/src/Bundle/ChillTaskBundle/Resources/views/Notification/task_assignment_notification_content.txt.twig new file mode 100644 index 000000000..c338700d6 --- /dev/null +++ b/src/Bundle/ChillTaskBundle/Resources/views/Notification/task_assignment_notification_content.txt.twig @@ -0,0 +1,16 @@ +{{ assignedUser.label }}, + +Une tâche vous a été assignée. + +Titre de la tâche: "{{ task.title }}". +{% if task.endDate %} + +Vous êtes invités à accomplir cette tâche avant le {{ task.endDate|format_date('long') }} +{% endif %} + + +Vous pouvez visualiser la tâche sur cette page: + +{{ absolute_url(path('chill_task_single_task_show', {'id': task.id, '_locale': 'fr'})) }} + +Cordialement, diff --git a/src/Bundle/ChillTaskBundle/Resources/views/Notification/task_assignment_notification_title.txt.twig b/src/Bundle/ChillTaskBundle/Resources/views/Notification/task_assignment_notification_title.txt.twig new file mode 100644 index 000000000..b837536a1 --- /dev/null +++ b/src/Bundle/ChillTaskBundle/Resources/views/Notification/task_assignment_notification_title.txt.twig @@ -0,0 +1 @@ +Une tâche demande votre attention diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index_item.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index_item.html.twig index 87b9c4086..f9d52be1a 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index_item.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/List/index_item.html.twig @@ -18,14 +18,14 @@
{% if task.person is not null %} - {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { - targetEntity: { name: 'person', id: task.person.id }, - action: 'show', - displayBadge: true, - buttonText: task.person|chill_entity_render_string, - isDead: task.person.deathdate is not null - } %} - + {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with { + targetEntity: { name: 'person', id: task.person.id }, + action: 'show', + displayBadge: true, + buttonText: task.person|chill_entity_render_string, + isDead: task.person.deathdate is not null + } %} + {% elseif task.course is not null %}
{% for part in task.course.currentParticipations %} diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_show.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_show.html.twig index 26d269191..91a1c59bb 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_show.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/_show.html.twig @@ -110,4 +110,5 @@ {% endif %} -
+ +
diff --git a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/showInNotification.html.twig b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/showInNotification.html.twig index 8cd4a7d05..5bc868779 100644 --- a/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/showInNotification.html.twig +++ b/src/Bundle/ChillTaskBundle/Resources/views/SingleTask/showInNotification.html.twig @@ -6,10 +6,7 @@ {% endmacro %} {% if task is not null %} -
- {# TODO task item #} -

Some task

-
+{#
Todo : display task?
#} {% else %}
{{ 'You are getting a notification for a task which does not exist any more'|trans }} diff --git a/src/Bundle/ChillTaskBundle/config/services/event.yaml b/src/Bundle/ChillTaskBundle/config/services/event.yaml index 385d062cc..e6f55d5e0 100644 --- a/src/Bundle/ChillTaskBundle/config/services/event.yaml +++ b/src/Bundle/ChillTaskBundle/config/services/event.yaml @@ -1,7 +1,13 @@ services: + _defaults: + autowire: true + autoconfigure: true + Chill\TaskBundle\Event\Lifecycle\TaskLifecycleEvent: arguments: $em: '@Doctrine\ORM\EntityManagerInterface' $tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface' tags: - { name: kernel.event_subscriber } + + Chill\TaskBundle\Event\TaskAssignEventSubscriber: ~ diff --git a/src/Bundle/ChillTaskBundle/config/services/notification.yaml b/src/Bundle/ChillTaskBundle/config/services/notification.yaml new file mode 100644 index 000000000..cde5c357d --- /dev/null +++ b/src/Bundle/ChillTaskBundle/config/services/notification.yaml @@ -0,0 +1,7 @@ +services: + _defaults: + autowire: true + autoconfigure: true + + Chill\TaskBundle\Notification\TaskNotificationHandler: ~ + Chill\TaskBundle\Notification\AssignTaskNotificationFlagProvider: ~ diff --git a/src/Bundle/ChillTaskBundle/translations/messages.fr.yml b/src/Bundle/ChillTaskBundle/translations/messages.fr.yml index b0d155f59..fc99b4ca4 100644 --- a/src/Bundle/ChillTaskBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillTaskBundle/translations/messages.fr.yml @@ -116,3 +116,9 @@ CHILL_TASK_TASK_UPDATE: Modifier une tâche CHILL_TASK_TASK_CREATE_FOR_COURSE: Créer une tâche pour un parcours CHILL_TASK_TASK_CREATE_FOR_PERSON: Créer une tâche pour un usager +notification: + task: + title %title%: "Tâche: title" + flags: + task_assign: Lorsqu'un autre utilisateur m'assigne à une tâche. +