src/Entity/User.php line 22
<?php
namespace App\Entity;
use App\Entity\Participation\Participation;
use App\Entity\Traits\TimestampableTrait;
use App\Repository\UserRepository;
use App\Service\ParticipationService;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
use App\Validator as AppAssert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[AppAssert\CheckLimitationParticipation()]
class User
{
use TimestampableTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 10, nullable: true)]
private ?string $civility = null;
#[ORM\Column(length: 80, nullable: true)]
#[Assert\Regex(pattern: "/^[\p{L}\-\s]+$/u", message: 'Ce champ est invalide')]
#[Groups(['consumer'])]
#[SerializedName('lastname')]
#[Assert\Length(
max: 14,
maxMessage: 'Le nombre de caractères ne doit pas dépasser 14',
)]
private ?string $lastname = null;
#[ORM\Column(length: 80, nullable: true)]
#[Assert\Regex(pattern: "/^[\p{L}\-\s]+$/u", message: 'Ce champ est invalide')]
#[Groups(['consumer'])]
#[Assert\Length(
max: 14,
maxMessage: 'Le nombre de caractères ne doit pas dépasser 14',
)]
private ?string $firstname = null;
#[ORM\Column(length: 50, nullable: false)]
#[Assert\NotBlank(message: "Le mail est obligatoire")]
#[Assert\Email(message: "Le mail est incorrect", mode: 'strict')]
#[Groups(['consumer'])]
private ?string $email;
#[ORM\Column(length: 50, nullable: true)]
#[SerializedName('phone')]
#[Groups(['consumer'])]
private ?string $phone = null;
#[ORM\Column(length: 255, nullable: true)]
#[Assert\Length(
max: 38,
maxMessage: 'Le nombre de caractères ne doit pas dépasser 38',
)]
#[SerializedName('address_3')]
#[Groups(['consumer'])]
private ?string $address;
#[ORM\Column(length: 40, nullable: true)]
#[Assert\Length(
max: 38,
maxMessage: 'Le nombre de caractères ne doit pas dépasser 38',
)]
#[SerializedName('address_1')]
#[Groups(['consumer'])]
private ?string $address2 = null;
#[ORM\Column(name: "zip_code", length: 10, nullable: true)]
#[SerializedName('postal_code')]
#[Assert\Regex(pattern: "/^[0-9]{5}$/", message: 'Ce champ est invalide')]
#[Groups(['consumer'])]
private ?string $zipcode;
#[ORM\Column(length: 80, nullable: true)]
#[Assert\Regex(pattern: "/^[\p{L}\-\'\s]+$/u", message: 'Ce champ est invalide')]
#[Groups(['consumer'])]
private ?string $city;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Participation::class)]
private Collection $participations;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Assert\LessThan(['value' => '-18 years', 'message' => "Tu dois être majeur pour participer"])]
private ?\DateTimeInterface $birthday = null;
#[ORM\Column(length: 255)]
private ?string $emailCleaned = null;
public function __construct()
{
$this->participations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCivility(): ?string
{
return $this->civility;
}
public function setCivility(?string $civility): self
{
$this->civility = $civility;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(?string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(?string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getEmail(): string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getAddress2(): ?string
{
return $this->address2;
}
public function setAddress2(?string $address2): self
{
$this->address2 = $address2;
return $this;
}
public function getZipcode(): ?string
{
return $this->zipcode;
}
public function setZipcode(?string $zipcode): self
{
$this->zipcode = $zipcode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): self
{
$this->city = $city;
return $this;
}
/**
* @return Collection<int, Participation>
*/
public function getParticipations(): Collection
{
return $this->participations;
}
public function addParticipation(Participation $participation): self
{
if (!$this->participations->contains($participation)) {
$this->participations->add($participation);
$participation->setUser($this);
}
return $this;
}
public function removeParticipation(Participation $participation): self
{
if ($this->participations->removeElement($participation)) {
// set the owning side to null (unless already changed)
if ($participation->getUser() === $this) {
$participation->setUser(null);
}
}
return $this;
}
public function getBirthday(): ?\DateTimeInterface
{
return $this->birthday;
}
public function setBirthday(?\DateTimeInterface $birthday): self
{
$this->birthday = $birthday;
return $this;
}
public function getEmailCleaned(): ?string
{
return $this->emailCleaned;
}
public function setEmailCleaned(?string $emailCleaned): self
{
$this->emailCleaned = $emailCleaned;
return $this;
}
public function __toString(): string
{
return $this->getEmail();
}
#[SerializedName('date_birthday')]
#[Groups(['consumer'])]
public function getDateBirthay(): ?string
{
return $this->birthday;
}
#[SerializedName('civility')]
#[Groups(['consumer'])]
public function getConsumerCivility(): ?string
{
return $this->civility ?? ParticipationService::translateCivility($this->civility, 2);
}
#[Assert\Callback]
public function validate(ExecutionContextInterface $context, $payload): void
{
if (!filter_var($this->email, FILTER_VALIDATE_EMAIL)) {
$context->buildViolation("Le format de l'e-mail ou les caractères insérés ne sont pas valides.")
->atPath('email')
->addViolation();
}
}
}