From f9828510a6f85cc38f0789f064aa3b718b7bd2b8 Mon Sep 17 00:00:00 2001 From: Robin de Rooij Date: Sat, 24 Feb 2024 21:29:40 +0100 Subject: [PATCH] Add membershipStatus to member revision This way history is kept for changing memberships, which is interesting to view membership history over time. The event listener responsible for this was already implemented in: src/EventSubscriber/EasyAdminEventSubscriber.php as it simply called the constructor of the MemberDetailsRevision and passes a Membership as its argument. Therefore just adding the field, a migration and changing the constructor to add this makes this work. --- migrations/Version20240224201202.php | 35 ++++++++++++++++++++++++++++ src/Entity/MemberDetailsRevision.php | 17 ++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 migrations/Version20240224201202.php diff --git a/migrations/Version20240224201202.php b/migrations/Version20240224201202.php new file mode 100644 index 0000000..0cdec8c --- /dev/null +++ b/migrations/Version20240224201202.php @@ -0,0 +1,35 @@ +addSql('ALTER TABLE admin_member_revision ADD current_membership_status_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE admin_member_revision ADD CONSTRAINT FK_A66E5AC1E1F48A9F FOREIGN KEY (current_membership_status_id) REFERENCES admin_membershipstatus (id)'); + $this->addSql('CREATE INDEX IDX_A66E5AC1E1F48A9F ON admin_member_revision (current_membership_status_id)'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE admin_member_revision DROP FOREIGN KEY FK_A66E5AC1E1F48A9F'); + $this->addSql('DROP INDEX IDX_A66E5AC1E1F48A9F ON admin_member_revision'); + $this->addSql('ALTER TABLE admin_member_revision DROP current_membership_status_id'); + } +} diff --git a/src/Entity/MemberDetailsRevision.php b/src/Entity/MemberDetailsRevision.php index 604dccf..3120bc3 100644 --- a/src/Entity/MemberDetailsRevision.php +++ b/src/Entity/MemberDetailsRevision.php @@ -9,6 +9,8 @@ use Symfony\Component\Security\Core\User\UserInterface; use App\Repository\MemberRepository; +use App\Entity\Membership\MembershipStatus; + /** * @ORM\Entity * @ORM\Table("admin_member_revision") @@ -64,6 +66,11 @@ class MemberDetailsRevision { /** @ORM\Column(type="date", nullable=true) */ private ?DateTime $dateOfBirth = null; + /** + * @ORM\ManyToOne(targetEntity="App\Entity\Membership\MembershipStatus") + */ + private ?MembershipStatus $currentMembershipStatus = null; + public function __construct(Member $member, bool $own) { $this->member = $member; $this->own = $own; @@ -79,6 +86,7 @@ public function __construct(Member $member, bool $own) { $this->postCode = $member->getPostCode(); $this->country = $member->getCountry(); $this->dateOfBirth = $member->getDateOfBirth(); + $this->currentMembershipStatus = $member->getCurrentMembershipStatus(); } public function hasChanged(Member $member) { @@ -93,6 +101,7 @@ public function hasChanged(Member $member) { || $this->getEmail() !== $member->getEmail() || $this->getPostCode() !== $member->getPostCode() || $this->getCountry() !== $member->getCountry() + || $this->getCurrentMembershipStatus() !== $member->getCurrentMembershipStatus() || $this->getDateOfBirth()->format('Ymd') !== $member->getDateOfBirth('Ymd'); } @@ -111,4 +120,12 @@ public function getPostCode(): string { return $this->postCode; } public function getCountry(): string { return $this->country; } public function getDateOfBirth(): ?DateTime { return $this->dateOfBirth; } + public function getCurrentMembershipStatus(): ?MembershipStatus { + return $this->currentMembershipStatus; + } + + public function setCurrentMembershipStatus(?MembershipStatus $membershipStatus): void { + $this->currentMembershipStatus = $membershipStatus; + } + }