Skip to content

Commit

Permalink
[142] Add workgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
Gwildor committed Mar 3, 2024
1 parent c0246f1 commit fca5c89
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Controller/Admin/MemberCrud.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ public function configureCrud(Crud $crud): Crud
return $crud
->setEntityLabelInSingular('lid')
->setEntityLabelInPlural('Leden')
->setSearchFields(['id', 'firstName', 'lastName', 'email', 'phone', 'city', 'postCode', 'currentMembershipStatus.name'])
->setSearchFields(['id', 'firstName', 'lastName', 'email', 'phone', 'city', 'postCode', 'currentMembershipStatus.name'])//, 'workGroups.name']) TODO: fix
;
}

public function configureFilters(Filters $filters): Filters
{
return $filters
->add(EntityFilter::new('division'))
->add(EntityFilter::new('currentMembershipStatus'));
->add(EntityFilter::new('division', 'Afdeling'))
->add(EntityFilter::new('currentMembershipStatus', 'Lidmaatschapstype'))
/* ->add(EntityFilter::new('workGroups', 'Werkgroepen')) */ TODO: fix
;
}

public function configureActions(Actions $actions): Actions {
Expand Down Expand Up @@ -183,7 +185,7 @@ public function configureFields(string $pageName): iterable
$fields[] = BooleanField::new('isAdmin', 'Toegang tot administratie')
->hideOnIndex();
}
array_push($fields,
array_push($fields,
FormField::addPanel('Contactinformatie'),
EmailField::new('email', 'E-mailadres')->setDisabled(!$isAdmin),
TextField::new('phone', 'Telefoonnummer')->setDisabled(!$isAdmin),
Expand Down
39 changes: 39 additions & 0 deletions src/Controller/Admin/WorkGroupCrud.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Controller\Admin;

use App\Entity\WorkGroup;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\{ IdField, FormField, BooleanField, TextField, UrlField, EmailField, AssociationField };
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;

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

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

public function configureFields(string $pageName): iterable
{
return [
IdField::new('id')->hideOnForm(),
TextField::new('name', 'Werkgroepnaam'),
AssociationField::new('contact', 'Contactpersoon'),
AssociationField::new('members', 'Leden')->hideOnIndex(),
FormField::addPanel('Contactinformatie'),
AssociationField::new('email', 'E-mailadres'),
];
}

}
75 changes: 75 additions & 0 deletions src/Entity/WorkGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
namespace App\Entity;

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

/**
* @ORM\Entity
* @ORM\Table("admin_workgroup")
*/
class WorkGroup {

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

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

/** @ORM\ManyToOne(targetEntity="Member")
* @ORM\JoinColumn(nullable=true)
*/
private ?Member $contact = null;

/**
* @ORM\ManyToMany(targetEntity="Member", mappedBy="workGroups")
*/
private Collection $members;

/**
* @ORM\ManyToOne(targetEntity="Email")
* @ORM\JoinColumn(nullable=true)
*/
private ?Email $email = null;

public function __construct() {
$this->members = new ArrayCollection();
}

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 getMembers(): Collection { return $this->members; }

public function addMember(Member $member): self {
if (!$this->members->contains($member)) {
$this->members[] = $member;
}
return $this;
}
public function removeMember(Member $member): self {
if ($this->members->contains($member)) {
$this->members->removeElement($member);
}
return $this;
}

public function getContact(): ?Member { return $this->contact; }
public function setContact(?Member $contact): void { $this->contact = $contact; }

public function getEmail(): ?Email { return $this->email; }
public function setEmail(?Email $email): void { $this->email = $email; }
}

0 comments on commit fca5c89

Please sign in to comment.