src/Entity/User.php line 19

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use App\Traits\UpdateInfoTrait;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. #[ORM\Table(name'`user`')]
  13. #[ORM\Entity(repositoryClassUserRepository::class)]
  14. #[Gedmo\Loggable]
  15. #[UniqueEntity(fields'email'message"Cet email est déjà utilisé !")]
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     // Attention: Ne pas supprimer
  19.     use UpdateInfoTrait;
  20.     #[ORM\OneToMany(mappedBy"user"targetEntityReservation::class)]
  21.     private Collection $liste_reservations;
  22.     #[ORM\OneToMany(mappedBy"user"targetEntityDons::class)]
  23.     private Collection $liste_dons;
  24.     #[Gedmo\Versioned]
  25.     #[ORM\Column(name'email'typeTypes::STRINGlength255uniquetrue)]
  26.     private string $email;
  27.     #[Gedmo\Versioned]
  28.     #[ORM\Column(name'roles'typeTypes::JSON)]
  29.     private array $roles = [];
  30.     #[Gedmo\Versioned]
  31.     #[ORM\Column(name'password'typeTypes::STRINGlength255nullabletrue)]
  32.     private ?string $password;
  33.     #[Gedmo\Versioned]
  34.     #[ORM\Column(name'lastname'typeTypes::STRINGlength255)]
  35.     private string $lastname;
  36.     #[Gedmo\Versioned]
  37.     #[ORM\Column(name'firstname'typeTypes::STRINGlength255)]
  38.     private string $firstname;
  39.     #[Gedmo\Versioned]
  40.     #[ORM\Column(name'phone'typeTypes::STRINGlength255)]
  41.     private string $phone;
  42.     #[ORM\Column(name'address'typeTypes::STRINGlength255nullablefalse)]
  43.     private string $address;
  44.     #[ORM\Column(name'address_complement'typeTypes::STRINGlength255nullabletrue)]
  45.     private ?string $address_complement;
  46.     #[ORM\Column(name'zip_code'typeTypes::STRINGlength255nullablefalse)]
  47.     private string $zip_code;
  48.     #[ORM\Column(name'city'typeTypes::STRINGlength255nullablefalse)]
  49.     private string $city;
  50.     #[ORM\ManyToOne(targetEntityPays::class)]
  51.     #[ORM\JoinColumn(nullabletrue)]
  52.     private Pays $pays;
  53.     public function __construct() { $this->setRoles(['ROLE_USER']); }
  54.     public function getListeReservations(): Collection
  55.     {
  56.         return $this->liste_reservations;
  57.     }
  58.     public function setListeReservations(Collection $liste_reservations): User
  59.     {
  60.         $this->liste_reservations $liste_reservations;
  61.         return $this;
  62.     }
  63.     public function getListeDons(): Collection
  64.     {
  65.         return $this->liste_dons;
  66.     }
  67.     public function setListeDons(Collection $liste_dons): User
  68.     {
  69.         $this->liste_dons $liste_dons;
  70.         return $this;
  71.     }
  72.     public function getEmail(): ?string { return $this->email; }
  73.     public function setEmail(string $email): self
  74.     {
  75.         $this->email $email;
  76.         return $this;
  77.     }
  78.     public function getUserIdentifier(): string { return (string) $this->email; }
  79.     public function getRoles(): array
  80.     {
  81.         $roles $this->roles;
  82.         // guarantee every user at least has ROLE_USER
  83.         $roles[] = 'ROLE_USER';
  84.         return array_unique($roles);
  85.     }
  86.     public function setRoles(array $roles): self
  87.     {
  88.         $this->roles $roles;
  89.         return $this;
  90.     }
  91.     public function getPassword(): ?string { return $this->password; }
  92.     public function setPassword(?string $password): self
  93.     {
  94.         $this->password $password;
  95.         return $this;
  96.     }
  97.     public function getLastname(): ?string { return $this->lastname; }
  98.     public function setLastname(string $lastname): self
  99.     {
  100.         $this->lastname $lastname;
  101.         return $this;
  102.     }
  103.     public function getFirstname(): ?string { return $this->firstname; }
  104.     public function setFirstname(string $firstname): self
  105.     {
  106.         $this->firstname $firstname;
  107.         return $this;
  108.     }
  109.     public function getPhone(): ?string { return $this->phone; }
  110.     public function setPhone(string $phone): self
  111.     {
  112.         $this->phone $phone;
  113.         return $this;
  114.     }
  115.     public function getAddress(): string { return $this->address; }
  116.     public function setAddress(string $address): User
  117.     {
  118.         $this->address $address;
  119.         return $this;
  120.     }
  121.     public function getAddressComplement(): ?string { return $this->address_complement; }
  122.     public function setAddressComplement(?string $address_complement): User
  123.     {
  124.         $this->address_complement $address_complement;
  125.         return $this;
  126.     }
  127.     public function getZipCode(): string { return $this->zip_code; }
  128.     public function setZipCode(string $zip_code): User
  129.     {
  130.         $this->zip_code $zip_code;
  131.         return $this;
  132.     }
  133.     public function getCity(): string { return $this->city; }
  134.     public function setCity(string $city): User
  135.     {
  136.         $this->city $city;
  137.         return $this;
  138.     }
  139.     public function eraseCredentials()
  140.     {
  141.         // If you store any temporary, sensitive data on the user, clear it here
  142.         // $this->plainPassword = null;
  143.     }
  144.     public function hasRole(string $string): bool
  145.     {
  146.         return in_array($string$this->getRoles());
  147.     }
  148.     public function getPays(): Pays
  149.     {
  150.         return $this->pays;
  151.     }
  152.     public function setPays(Pays $pays): void
  153.     {
  154.         $this->pays $pays;
  155.     }
  156. }