src/Entity/User.php line 15

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length180uniquetrue)]
  19.     private ?string $email null;
  20.     #[ORM\Column]
  21.     private array $roles = [];
  22.     /**
  23.      * @var string The hashed password
  24.      */
  25.     #[ORM\Column]
  26.     private ?string $password null;
  27.     #[ORM\OneToMany(mappedBy'user'targetEntityReclamation::class)]
  28.     private Collection $reclamations;
  29.     #[ORM\Column(length255)]
  30.     private ?string $nom null;
  31.     #[ORM\Column(length255)]
  32.     private ?string $prenom null;
  33.     public function __construct()
  34.     {
  35.         $this->reclamations = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getEmail(): ?string
  42.     {
  43.         return $this->email;
  44.     }
  45.     public function setEmail(string $email): self
  46.     {
  47.         $this->email $email;
  48.         return $this;
  49.     }
  50.     /**
  51.      * A visual identifier that represents this user.
  52.      *
  53.      * @see UserInterface
  54.      */
  55.     public function getUserIdentifier(): string
  56.     {
  57.         return (string) $this->email;
  58.     }
  59.     /**
  60.      * @see UserInterface
  61.      */
  62.     public function getRoles(): array
  63.     {
  64.         $roles $this->roles;
  65.         // guarantee every user at least has ROLE_USER
  66.         $roles[] = 'ROLE_USER';
  67.         return array_unique($roles);
  68.     }
  69.     public function setRoles(array $roles): self
  70.     {
  71.         $this->roles $roles;
  72.         return $this;
  73.     }
  74.     /**
  75.      * @see PasswordAuthenticatedUserInterface
  76.      */
  77.     public function getPassword(): string
  78.     {
  79.         return $this->password;
  80.     }
  81.     public function setPassword(string $password): self
  82.     {
  83.         $this->password $password;
  84.         return $this;
  85.     }
  86.     /**
  87.      * @see UserInterface
  88.      */
  89.     public function eraseCredentials()
  90.     {
  91.         // If you store any temporary, sensitive data on the user, clear it here
  92.         // $this->plainPassword = null;
  93.     }
  94.     /**
  95.      * @return Collection<int, Reclamation>
  96.      */
  97.     public function getReclamations(): Collection
  98.     {
  99.         return $this->reclamations;
  100.     }
  101.     public function addReclamation(Reclamation $reclamation): self
  102.     {
  103.         if (!$this->reclamations->contains($reclamation)) {
  104.             $this->reclamations->add($reclamation);
  105.             $reclamation->setUser($this);
  106.         }
  107.         return $this;
  108.     }
  109.     public function removeReclamation(Reclamation $reclamation): self
  110.     {
  111.         if ($this->reclamations->removeElement($reclamation)) {
  112.             // set the owning side to null (unless already changed)
  113.             if ($reclamation->getUser() === $this) {
  114.                 $reclamation->setUser(null);
  115.             }
  116.         }
  117.         return $this;
  118.     }
  119.     public function getNom(): ?string
  120.     {
  121.         return $this->nom;
  122.     }
  123.     public function setNom(string $nom): static
  124.     {
  125.         $this->nom $nom;
  126.         return $this;
  127.     }
  128.     public function getPrenom(): ?string
  129.     {
  130.         return $this->prenom;
  131.     }
  132.     public function setPrenom(string $prenom): static
  133.     {
  134.         $this->prenom $prenom;
  135.         return $this;
  136.     }
  137. }