Skip to content

Commit

Permalink
Only send initial email once
Browse files Browse the repository at this point in the history
  • Loading branch information
pingiun committed May 19, 2024
1 parent 754c349 commit d3d7794
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 21 deletions.
31 changes: 31 additions & 0 deletions migrations/Version20240519140526.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20240519140526 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}
48 changes: 27 additions & 21 deletions src/Controller/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
8 changes: 8 additions & 0 deletions src/Entity/MembershipApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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; }

}

0 comments on commit d3d7794

Please sign in to comment.