diff --git a/migrations/Version20240519140526.php b/migrations/Version20240519140526.php new file mode 100644 index 0000000..121d08b --- /dev/null +++ b/migrations/Version20240519140526.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE admin_membership_application ADD has_sent_initial_email TINYINT(1) DEFAULT 0 NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE admin_membership_application DROP has_sent_initial_email'); + } +} diff --git a/src/Controller/MemberController.php b/src/Controller/MemberController.php index 6a4cd6b..82ce9d4 100644 --- a/src/Controller/MemberController.php +++ b/src/Controller/MemberController.php @@ -176,29 +176,35 @@ public function handleRedirect(Request $request, string $customerId): Response return $this->json(['success' => true]); } - $templatePrefix = ''; + if (!$membershipApplication->getHasSentInitialEmail()) { + $templatePrefix = ''; - if (is_dir($this->getParameter('kernel.project_dir') . '/templates/custom')) { - $templatePrefix = 'custom/'; - } + if (is_dir($this->getParameter('kernel.project_dir') . '/templates/custom')) { + $templatePrefix = 'custom/'; + } - $memberEmail = $membershipApplication->getEmail(); - $memberFullName = $membershipApplication->getFullName(); - $memberFirstName = $membershipApplication->getFirstName(); - - $emailSender = $this->getParameter('app.noReplyAddress'); - $organizationName = $this->getParameter('app.organizationEmail'); - $message = (new Email()) - ->subject("Bedankt voor je aanmelding bij $organizationName!") - ->to(new Address($memberEmail, $memberFullName)) - ->from(new Address($emailSender, $organizationName)) - ->html( - $this->renderView($templatePrefix . 'email/html/apply.html.twig', ['memberFirstName' => $memberFirstName]) - ) - ->text( - $this->renderView($templatePrefix . 'email/text/apply.txt.twig', ['memberFirstName' => $memberFirstName]) - ); - $this->mailer->send($message); + $memberEmail = $membershipApplication->getEmail(); + $memberFullName = $membershipApplication->getFullName(); + $memberFirstName = $membershipApplication->getFirstName(); + + $emailSender = $this->getParameter('app.noReplyAddress'); + $organizationName = $this->getParameter('app.organizationEmail'); + $message = (new Email()) + ->subject("Bedankt voor je aanmelding bij $organizationName!") + ->to(new Address($memberEmail, $memberFullName)) + ->from(new Address($emailSender, $organizationName)) + ->html( + $this->renderView($templatePrefix . 'email/html/apply.html.twig', ['memberFirstName' => $memberFirstName]) + ) + ->text( + $this->renderView($templatePrefix . 'email/text/apply.txt.twig', ['memberFirstName' => $memberFirstName]) + ); + $this->mailer->send($message); + $membershipApplication->setHasSentInitialEmail(true); + $em = $this->getDoctrine()->getManager(); + $em->persist($membershipApplication); + $em->flush(); + } return $this->render('user/member/finished.html.twig'); } diff --git a/src/Entity/MembershipApplication.php b/src/Entity/MembershipApplication.php index 35e9b13..d75a38a 100644 --- a/src/Entity/MembershipApplication.php +++ b/src/Entity/MembershipApplication.php @@ -112,6 +112,11 @@ class MembershipApplication { */ private ?bool $paid = false; + /** + * @ORM\Column(type="boolean", options={"default": false}) + */ + private bool $hasSentInitialEmail = false; + public function __construct() { $this->registrationTime = new DateTime(); } @@ -210,4 +215,7 @@ public function setContributionPeriod(int $contributionPeriod): void { $this->contributionPeriod = $contributionPeriod; } + public function getHasSentInitialEmail(): bool { return $this->hasSentInitialEmail; } + public function setHasSentInitialEmail(bool $hasSentInitialEmail): void { $this->hasSentInitialEmail = $hasSentInitialEmail; } + }