mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
notification: send an email to addressesEmails
This commit is contained in:
parent
24d28b0a52
commit
a41d6cf744
@ -65,6 +65,17 @@ class NotificationController extends AbstractController
|
|||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Route("/{id}/access_key", name="chill_main_notification_grant_access_by_access_key")
|
||||||
|
*/
|
||||||
|
public function getAccessByAccessKey(Notification $notification, Request $request): Response
|
||||||
|
{
|
||||||
|
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_REMEMBERED');
|
||||||
|
|
||||||
|
return new Response('Invalid access key');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/create", name="chill_main_notification_create")
|
* @Route("/create", name="chill_main_notification_create")
|
||||||
*/
|
*/
|
||||||
|
@ -183,6 +183,14 @@ class Notification implements TrackUpdateInterface
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getAddedAddresses(): array
|
||||||
|
{
|
||||||
|
return $this->addedAddresses;
|
||||||
|
}
|
||||||
|
|
||||||
public function addComment(NotificationComment $comment): self
|
public function addComment(NotificationComment $comment): self
|
||||||
{
|
{
|
||||||
if (!$this->comments->contains($comment)) {
|
if (!$this->comments->contains($comment)) {
|
||||||
|
@ -73,6 +73,17 @@ class NotificationMailer
|
|||||||
* Send a email after a notification is persisted.
|
* Send a email after a notification is persisted.
|
||||||
*/
|
*/
|
||||||
public function postPersistNotification(Notification $notification, LifecycleEventArgs $eventArgs): void
|
public function postPersistNotification(Notification $notification, LifecycleEventArgs $eventArgs): void
|
||||||
|
{
|
||||||
|
$this->sendNotificationEmailsToAddresses($notification);
|
||||||
|
$this->sendNotificationEmailsToAddressesEmails($notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postUpdateNotification(Notification $notification, LifecycleEventArgs $eventArgs): void
|
||||||
|
{
|
||||||
|
$this->sendNotificationEmailsToAddressesEmails($notification);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendNotificationEmailsToAddresses(Notification $notification): void
|
||||||
{
|
{
|
||||||
foreach ($notification->getAddressees() as $addressee) {
|
foreach ($notification->getAddressees() as $addressee) {
|
||||||
if (null === $addressee->getEmail()) {
|
if (null === $addressee->getEmail()) {
|
||||||
@ -108,4 +119,31 @@ class NotificationMailer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function sendNotificationEmailsToAddressesEmails(Notification $notification): void
|
||||||
|
{
|
||||||
|
foreach ($notification->getAddressesEmailsAdded() as $emailAddress) {
|
||||||
|
$email = new TemplatedEmail();
|
||||||
|
$email
|
||||||
|
->textTemplate('@ChillMain/Notification/email_non_system_notification_content_to_email.fr.md.twig')
|
||||||
|
->context([
|
||||||
|
'notification' => $notification,
|
||||||
|
'dest' => $emailAddress,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$email
|
||||||
|
->subject($notification->getTitle())
|
||||||
|
->to($emailAddress);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$this->mailer->send($email);
|
||||||
|
} catch (TransportExceptionInterface $e) {
|
||||||
|
$this->logger->warning('[NotificationMailer] could not send an email notification', [
|
||||||
|
'to' => $emailAddress,
|
||||||
|
'error_message' => $e->getMessage(),
|
||||||
|
'error_trace' => $e->getTraceAsString(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
{{ dest }},
|
||||||
|
|
||||||
|
{{ notification.sender.label }} a créé une notification pour vous:
|
||||||
|
|
||||||
|
> {{ notification.title }}
|
||||||
|
>
|
||||||
|
>
|
||||||
|
{%- for line in notification.message|split("\n") %}
|
||||||
|
> {{ line }}
|
||||||
|
{%- if not loop.last %}
|
||||||
|
>
|
||||||
|
{%- endif %}
|
||||||
|
{%- endfor %}
|
||||||
|
|
||||||
|
Vous pouvez cliquer sur ce lien pour obtenir un accès permanent à la notification:
|
||||||
|
|
||||||
|
{{ absolute_url(path('chill_main_notification_grant_access_by_access_key', {'_locale': 'fr', 'id': notification.id, 'accessKey': notification.accessKey, 'email': dest})) }}
|
||||||
|
|
||||||
|
--
|
||||||
|
Le logiciel Chill
|
@ -61,6 +61,15 @@ services:
|
|||||||
# set the 'lazy' option to TRUE to only instantiate listeners when they are used
|
# set the 'lazy' option to TRUE to only instantiate listeners when they are used
|
||||||
lazy: true
|
lazy: true
|
||||||
method: 'postPersistNotification'
|
method: 'postPersistNotification'
|
||||||
|
|
||||||
|
-
|
||||||
|
name: 'doctrine.orm.entity_listener'
|
||||||
|
event: 'postUpdate'
|
||||||
|
entity: 'Chill\MainBundle\Entity\Notification'
|
||||||
|
# set the 'lazy' option to TRUE to only instantiate listeners when they are used
|
||||||
|
lazy: true
|
||||||
|
method: 'postUpdateNotification'
|
||||||
|
|
||||||
-
|
-
|
||||||
name: 'doctrine.orm.entity_listener'
|
name: 'doctrine.orm.entity_listener'
|
||||||
event: 'postPersist'
|
event: 'postPersist'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user