Skip to content

Commit

Permalink
Add membershipStatus to member revision
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Robin de Rooij committed Feb 24, 2024
1 parent 35cfe8f commit f982851
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
35 changes: 35 additions & 0 deletions migrations/Version20240224201202.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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 Version20240224201202 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_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');
}
}
17 changes: 17 additions & 0 deletions src/Entity/MemberDetailsRevision.php
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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');
}

Expand All @@ -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;
}

}

0 comments on commit f982851

Please sign in to comment.