Files
COPILOT/src/Entity/Membre.php
BRAMAS Arthur 1b0601d724 add progression
2025-10-24 16:14:44 +02:00

121 lines
3.2 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\MembreRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: MembreRepository::class)]
#[ORM\Table(name: 'membre')]
#[UniqueEntity(fields: ['email'], message: 'Cet email est déjà utilisé.')]
class Membre
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 50)]
#[Assert\NotBlank(message: 'Le nom est obligatoire.')]
#[Assert\Length(max: 50, maxMessage: 'Le nom ne peut pas dépasser {{ limit }} caractères.')]
private ?string $nom = null;
#[ORM\Column(type: 'string', length: 50)]
#[Assert\NotBlank(message: 'Le prénom est obligatoire.')]
#[Assert\Length(max: 50, maxMessage: 'Le prénom ne peut pas dépasser {{ limit }} caractères.')]
private ?string $prenom = null;
#[ORM\Column(type: 'string', length: 100, unique: true)]
#[Assert\NotBlank(message: 'L\'email est obligatoire.')]
#[Assert\Email(message: 'L\'email {{ value }} n\'est pas valide.')]
#[Assert\Length(max: 100, maxMessage: 'L\'email ne peut pas dépasser {{ limit }} caractères.')]
private ?string $email = null;
#[ORM\OneToMany(targetEntity: Contribution::class, mappedBy: 'membre', cascade: ['persist'], orphanRemoval: true)]
private Collection $contributions;
public function __construct()
{
$this->contributions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
public function getPrenom(): ?string
{
return $this->prenom;
}
public function setPrenom(string $prenom): static
{
$this->prenom = $prenom;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$this->email = $email;
return $this;
}
/**
* @return Collection<int, Contribution>
*/
public function getContributions(): Collection
{
return $this->contributions;
}
public function addContribution(Contribution $contribution): static
{
if (!$this->contributions->contains($contribution)) {
$this->contributions->add($contribution);
$contribution->setMembre($this);
}
return $this;
}
public function removeContribution(Contribution $contribution): static
{
if ($this->contributions->removeElement($contribution)) {
// set the owning side to null (unless already changed)
if ($contribution->getMembre() === $this) {
$contribution->setMembre(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->prenom . ' ' . $this->nom;
}
}