diff --git a/migrations/Version20240218160940.php b/migrations/Version20240218160940.php new file mode 100644 index 0000000..4b0b82e --- /dev/null +++ b/migrations/Version20240218160940.php @@ -0,0 +1,36 @@ +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'); + } +} diff --git a/src/Controller/Admin/DashboardController.php b/src/Controller/Admin/DashboardController.php index 43f32fe..6c0b8bc 100644 --- a/src/Controller/Admin/DashboardController.php +++ b/src/Controller/Admin/DashboardController.php @@ -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; @@ -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'), diff --git a/src/Controller/Admin/MemberCrud.php b/src/Controller/Admin/MemberCrud.php index 499ffb1..44cb1a4 100644 --- a/src/Controller/Admin/MemberCrud.php +++ b/src/Controller/Admin/MemberCrud.php @@ -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 { @@ -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) @@ -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), @@ -203,7 +211,7 @@ public function configureFields(string $pageName): iterable 'allow_delete' => false ]) ->hideOnIndex() - ]; + ); + return $fields; } - } diff --git a/src/Controller/Admin/Membership/MembershipStatusCrud.php b/src/Controller/Admin/Membership/MembershipStatusCrud.php new file mode 100644 index 0000000..1b84833 --- /dev/null +++ b/src/Controller/Admin/Membership/MembershipStatusCrud.php @@ -0,0 +1,36 @@ +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'), + ]; + } +} diff --git a/src/Entity/Member.php b/src/Entity/Member.php index 11804d4..f4d4fbf 100644 --- a/src/Entity/Member.php +++ b/src/Entity/Member.php @@ -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; @@ -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}) */ @@ -290,13 +296,23 @@ public function getManagingEmails(): Collection { return $this->managingEmails; } + public function getCurrentMembershipStatus(): ?MembershipStatus { + return $this->currentMembershipStatus; + } + + public function setCurrentMembershipStatus(?MembershipStatus $membershipStatus) { + $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) { diff --git a/src/Entity/Membership/MembershipStatus.php b/src/Entity/Membership/MembershipStatus.php new file mode 100644 index 0000000..689f8ab --- /dev/null +++ b/src/Entity/Membership/MembershipStatus.php @@ -0,0 +1,50 @@ +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) { $this->allowedAccess = $allowedAccess; } + + public function getMembers(): Collection { return $this->members; } +}