Skip to content

Commit

Permalink
Add membershipstatus (#154)
Browse files Browse the repository at this point in the history
* Add membershipstatus

The members lacked a status field which made it hard
to keep track of whether members were ex-members, members,
expelled, cancelled their membership etc.

This introduces arbitrary fields of membership statuses
that are being able to be set by the administrators.

The migration makes a single membership type in advance
which is called "Lid" (member) and everyone by default
will be made member and get access to the login.

You can make additional membership types which can't
login to the system at all.
  • Loading branch information
rrooij authored Feb 19, 2024
1 parent f99328b commit 35cfe8f
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 10 deletions.
36 changes: 36 additions & 0 deletions migrations/Version20240218160940.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

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

final class Version20240218160940 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add membership status';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE admin_membershipstatus (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(150) NOT NULL, allowed_access TINYINT(1) DEFAULT \'0\' NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE admin_member ADD current_membership_status_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE admin_member ADD CONSTRAINT FK_2D2CCB81E1F48A9F FOREIGN KEY (current_membership_status_id) REFERENCES admin_membershipstatus (id)');
$this->addSql('CREATE INDEX IDX_2D2CCB81E1F48A9F ON admin_member (current_membership_status_id)');
$this->addSql("INSERT INTO admin_membershipstatus VALUES (1, 'Lid', TRUE)");
$this->addSql("UPDATE admin_member SET current_membership_status_id = 1");
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE admin_member DROP FOREIGN KEY FK_2D2CCB81E1F48A9F');
$this->addSql('DROP TABLE admin_membershipstatus');
$this->addSql('DROP INDEX IDX_2D2CCB81E1F48A9F ON admin_member');
$this->addSql('ALTER TABLE admin_member DROP current_membership_status_id');
}
}
2 changes: 2 additions & 0 deletions src/Controller/Admin/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Symfony\Component\HttpFoundation\Response;
use EasyCorp\Bundle\EasyAdminBundle\Config\{ Crud, Dashboard, MenuItem };
use App\Entity\{ Member, SupportMember, MembershipApplication, Division, Email, EmailDomain, Event };
use App\Entity\Membership\MembershipStatus;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Asset\Packages;
Expand Down Expand Up @@ -62,6 +63,7 @@ public function configureMenuItems(): iterable
MenuItem::linkToCrud('Steunleden', 'fa fa-users', SupportMember::class)->setPermission('ROLE_ADMIN'),
MenuItem::linkToCrud('Aanmeldingen', 'fa fa-user-plus', MembershipApplication::class)->setPermission('ROLE_ADMIN'),
MenuItem::linkToCrud('Groepen', 'fa fa-building', Division::class)->setPermission('ROLE_ADMIN'),
MenuItem::linkToCrud('Lidmaatschapstypes', 'fa fa-building', MembershipStatus::class)->setPermission('ROLE_ADMIN'),

MenuItem::section('Technisch')->setPermission('ROLE_ADMIN'),
MenuItem::linkToCrud('E-mailadressen', 'fa fa-at', Email::class)->setPermission('ROLE_ADMIN'),
Expand Down
26 changes: 17 additions & 9 deletions src/Controller/Admin/MemberCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular('lid')
->setEntityLabelInPlural('Leden')
->setSearchFields(['id', 'firstName', 'lastName', 'email', 'phone', 'city', 'postCode'])
->setSearchFields(['id', 'firstName', 'lastName', 'email', 'phone', 'city', 'postCode', 'currentMembershipStatus.name'])
;
}

public function configureFilters(Filters $filters): Filters
{
$filters->add(EntityFilter::new('division'));
return $filters;
return $filters
->add(EntityFilter::new('division'))
->add(EntityFilter::new('currentMembershipStatus'));
}

public function configureActions(Actions $actions): Actions {
Expand Down Expand Up @@ -162,7 +163,7 @@ public function configureFields(string $pageName): iterable
{
$isAdmin = $this->isGranted('ROLE_ADMIN');

return [
$fields = [
IdField::new('id', 'Lidnummer')
->setDisabled(!$isAdmin)
->setRequired(false)
Expand All @@ -172,10 +173,17 @@ public function configureFields(string $pageName): iterable
TextField::new('lastName', 'Achternaam')->setDisabled(!$isAdmin),
DateField::new('dateOfBirth', 'Geboortedatum')->setDisabled(!$isAdmin)->hideOnIndex(),
DateField::new('registrationTime', 'Inschrijfdatum')
->setDisabled(!$isAdmin)->setFormat(DateTimeField::FORMAT_SHORT),
AssociationField::new('division', 'Groep')->setDisabled(!$isAdmin),
BooleanField::new('isAdmin', 'Toegang tot administratie')->setDisabled(!$isAdmin)->hideOnIndex(),
->setFormat(DateTimeField::FORMAT_SHORT)
->hideOnIndex(),
];

if ($isAdmin) {
$fields[] = AssociationField::new('currentMembershipStatus', 'Lidmaatschapstype');
$fields[] = AssociationField::new('division', 'Afdeling');
$fields[] = BooleanField::new('isAdmin', 'Toegang tot administratie')
->hideOnIndex();
}
array_push($fields,
FormField::addPanel('Contactinformatie'),
EmailField::new('email', 'E-mailadres')->setDisabled(!$isAdmin),
TextField::new('phone', 'Telefoonnummer')->setDisabled(!$isAdmin),
Expand Down Expand Up @@ -203,7 +211,7 @@ public function configureFields(string $pageName): iterable
'allow_delete' => false
])
->hideOnIndex()
];
);
return $fields;
}

}
36 changes: 36 additions & 0 deletions src/Controller/Admin/Membership/MembershipStatusCrud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
namespace App\Controller\Admin\Membership;

use App\Entity\Membership\MembershipStatus;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\{ IdField, FormField, BooleanField, DateField, DateTimeField, CollectionField, ChoiceField, TextField, TextEditorField, EmailField, AssociationField, MoneyField };
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;

class MembershipStatusCrud extends AbstractCrudController
{
// it must return a FQCN (fully-qualified class name) of a Doctrine ORM entity
public static function getEntityFqcn(): string
{
return MembershipStatus::class;
}

public function configureCrud(Crud $crud): Crud
{
return $crud
->setEntityLabelInSingular('Lidmaatschapstype')
->setEntityLabelInPlural('Lidmaatschapstypes')
->setEntityPermission('ROLE_ADMIN')
;
}

public function configureFields(string $pageName): iterable
{
return [
IdField::new('id', 'ID')->hideOnForm(),
TextField::new('name', 'Naam'),
BooleanField::new('allowedAccess', 'Heeft toegang'),
];
}
}
18 changes: 17 additions & 1 deletion src/Entity/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Entity;

use App\Entity\Membership\MembershipStatus;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\{ ArrayCollection, Collection };
use Symfony\Component\Validator\Constraints as Assert;
Expand Down Expand Up @@ -151,6 +152,11 @@ class Member implements UserInterface {
*/
private Collection $managingEmails;

/**
* @ORM\ManyToOne(targetEntity="App\Entity\Membership\MembershipStatus", inversedBy="members")
*/
private ?MembershipStatus $currentMembershipStatus = null;

/**
* @ORM\Column(type="boolean", nullable=false, options={"default": false})
*/
Expand Down Expand Up @@ -290,13 +296,23 @@ public function getManagingEmails(): Collection {
return $this->managingEmails;
}

public function getCurrentMembershipStatus(): ?MembershipStatus {
return $this->currentMembershipStatus;
}

public function setCurrentMembershipStatus(?MembershipStatus $membershipStatus): void {
$this->currentMembershipStatus = $membershipStatus;
}

/** @see UserInterface */
public function getUsername(): string { return $this->id; }

/** @see UserInterface */
public function getRoles(): array {
$roles = $this->roles;
$roles[] = 'ROLE_USER';
if ($this->getCurrentMembershipStatus() === null || $this->currentMembershipStatus->getAllowedAccess()) {
$roles[] = 'ROLE_USER';
}
if (!is_null($this->getDivision())) {
$isContactOfAnyDivision = $this->getDivision()->getContacts()->exists(
function ($key, $division) {
Expand Down
50 changes: 50 additions & 0 deletions src/Entity/Membership/MembershipStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
namespace App\Entity\Membership;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\{ ArrayCollection, Collection };
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Member;

/**
* @ORM\Entity
* @ORM\Table("admin_membershipstatus")
*/
class MembershipStatus {

/**
* @ORM\Column(type="integer", options={ "unsigned": false })
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private ?int $id = null;

/**
* @ORM\Column(type="string", length=150)
*/
private string $name = '';

/**
* @ORM\OneToMany(targetEntity="App\Entity\Member", mappedBy="currentMembershipStatus")
*/
private Collection $members;

/**
* @ORM\Column(type="boolean", nullable=false, options={"default": false})
*/
private bool $allowedAccess = false;

public function __toString() {
return $this->name;
}

public function getId(): ?int { return $this->id; }

public function getName(): string { return $this->name; }
public function setName(string $name): void { $this->name = $name; }

public function getAllowedAccess(): bool { return $this->allowedAccess; }
public function setAllowedAccess(bool $allowedAccess): void { $this->allowedAccess = $allowedAccess; }

public function getMembers(): Collection { return $this->members; }
}

0 comments on commit 35cfe8f

Please sign in to comment.