src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\CreatedAtTrait;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. /////
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. #[ORM\Entity(repositoryClassUserRepository::class)]
  14. #[UniqueEntity(fields: ['email'], message'Il existe déjà un utilisateur avec cet email')]
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.   use CreatedAtTrait;
  18.   #[ORM\Id]
  19.   #[ORM\GeneratedValue]
  20.   #[ORM\Column]
  21.   #[Groups(['get_messages'])]
  22.   private ?int $id null;
  23.   #[ORM\Column(length180uniquetrue)]
  24.   private ?string $email null;
  25.   #[ORM\Column]
  26.   private array $roles = [];
  27.   /**
  28.    * @var string The hashed password
  29.    */
  30.   #[ORM\Column]
  31.   private ?string $password null;
  32.   #[ORM\Column(length100)]
  33.   #[Groups(['get_messages'])]
  34.   private ?string $lastname null;
  35.   #[ORM\Column(length100)]
  36.   #[Groups(['get_messages'])]
  37.   private ?string $firstname null;
  38.   #[ORM\Column(options: ['default' => 'CURRENT_TIMESTAMP'])]
  39.   private ?\DateTimeImmutable $updated_at null;
  40.   #[ORM\OneToMany(mappedBy'user'targetEntityTrick::class)]
  41.   private Collection $tricks;
  42.   #[ORM\OneToMany(mappedBy'user'targetEntityMessage::class)]
  43.   private Collection $messages;
  44.   #[ORM\OneToMany(mappedBy'user'targetEntityCategory::class)]
  45.   private Collection $categories;
  46.   #[ORM\Column(length150nullabletrue)]
  47.   #[Groups(['get_messages'])]
  48.   private ?string $avatar null;
  49.   #[ORM\Column(options: ['default' => false])]
  50.   private ?bool $is_verified false;
  51.   #[ORM\Column(length255nullabletrue)]
  52.   private ?string $registration_token null;
  53.   #[ORM\Column(length255nullabletrue)]
  54.   private ?string $password_recovery_token null;
  55.   #[ORM\Column(length255nullabletrue)]
  56.   private ?string $account_deletion_token null;
  57.   public function __construct()
  58.   {
  59.     $this->tricks = new ArrayCollection();
  60.     $this->messages = new ArrayCollection();
  61.     $this->created_at = new \DateTimeImmutable();
  62.     $this->updated_at = new \DateTimeImmutable();
  63.     $this->categories = new ArrayCollection();
  64.   }
  65.   public function getId(): ?int
  66.   {
  67.     return $this->id;
  68.   }
  69.   public function getEmail(): ?string
  70.   {
  71.     return $this->email;
  72.   }
  73.   public function setEmail(string $email): self
  74.   {
  75.     $this->email $email;
  76.     return $this;
  77.   }
  78.   /**
  79.    * A visual identifier that represents this user.
  80.    *
  81.    * @see UserInterface
  82.    */
  83.   public function getUserIdentifier(): string
  84.   {
  85.     return (string) $this->email;
  86.   }
  87.   /**
  88.    * @see UserInterface
  89.    */
  90.   public function getRoles(): array
  91.   {
  92.     $roles $this->roles;
  93.     // guarantee every user at least has ROLE_USER
  94.     $roles[] = 'ROLE_USER';
  95.     return array_unique($roles);
  96.   }
  97.   public function setRoles(array $roles): self
  98.   {
  99.     $this->roles $roles;
  100.     return $this;
  101.   }
  102.   /**
  103.    * @see PasswordAuthenticatedUserInterface
  104.    */
  105.   public function getPassword(): string
  106.   {
  107.     return $this->password;
  108.   }
  109.   public function setPassword(string $password): self
  110.   {
  111.     $this->password $password;
  112.     return $this;
  113.   }
  114.   /**
  115.    * @see UserInterface
  116.    */
  117.   public function eraseCredentials(): void
  118.   {
  119.     // If you store any temporary, sensitive data on the user, clear it here
  120.   }
  121.   public function getLastname(): ?string
  122.   {
  123.     return $this->lastname;
  124.   }
  125.   public function setLastname(string $lastname): self
  126.   {
  127.     $this->lastname $lastname;
  128.     return $this;
  129.   }
  130.   public function getFirstname(): ?string
  131.   {
  132.     return $this->firstname;
  133.   }
  134.   public function setFirstname(string $firstname): self
  135.   {
  136.     $this->firstname $firstname;
  137.     return $this;
  138.   }
  139.   public function getUpdatedAt(): ?\DateTimeImmutable
  140.   {
  141.     return $this->updated_at;
  142.   }
  143.   public function setUpdatedAt(\DateTimeImmutable $updated_at): self
  144.   {
  145.     $this->updated_at $updated_at;
  146.     return $this;
  147.   }
  148.   /**
  149.    * @return Collection<int, Trick>
  150.    */
  151.   public function getTricks(): Collection
  152.   {
  153.     return $this->tricks;
  154.   }
  155.   public function addTrick(Trick $trick): self
  156.   {
  157.     if (!$this->tricks->contains($trick)) {
  158.       $this->tricks->add($trick);
  159.       $trick->setUser($this);
  160.     }
  161.     return $this;
  162.   }
  163.   public function removeTrick(Trick $trick): self
  164.   {
  165.     if ($this->tricks->removeElement($trick)) {
  166.       // set the owning side to null (unless already changed)
  167.       if ($trick->getUser() === $this) {
  168.         $trick->setUser(null);
  169.       }
  170.     }
  171.     return $this;
  172.   }
  173.   /**
  174.    * @return Collection<int, Message>
  175.    */
  176.   public function getMessages(): Collection
  177.   {
  178.     return $this->messages;
  179.   }
  180.   public function addMessage(Message $message): self
  181.   {
  182.     if (!$this->messages->contains($message)) {
  183.       $this->messages->add($message);
  184.       $message->setUser($this);
  185.     }
  186.     return $this;
  187.   }
  188.   public function removeMessage(Message $message): self
  189.   {
  190.     if ($this->messages->removeElement($message)) {
  191.       // set the owning side to null (unless already changed)
  192.       if ($message->getUser() === $this) {
  193.         $message->setUser(null);
  194.       }
  195.     }
  196.     return $this;
  197.   }
  198.   /**
  199.    * @return Collection<int, Category>
  200.    */
  201.   public function getCategories(): Collection
  202.   {
  203.       return $this->categories;
  204.   }
  205.   public function addCategory(Category $category): self
  206.   {
  207.       if (!$this->categories->contains($category)) {
  208.           $this->categories->add($category);
  209.           $category->setUser($this);
  210.       }
  211.       return $this;
  212.   }
  213.   public function removeCategory(Category $category): self
  214.   {
  215.       if ($this->categories->removeElement($category)) {
  216.           // set the owning side to null (unless already changed)
  217.           if ($category->getUser() === $this) {
  218.               $category->setUser(null);
  219.           }
  220.       }
  221.       return $this;
  222.   }
  223.   public function getAvatar(): ?string
  224.   {
  225.       return $this->avatar;
  226.   }
  227.   public function setAvatar(?string $avatar): self
  228.   {
  229.       $this->avatar $avatar;
  230.       return $this;
  231.   }
  232.   public function getIsVerified(): ?bool
  233.   {
  234.       return $this->is_verified;
  235.   }
  236.   public function setIsVerified(bool $is_verified): self
  237.   {
  238.       $this->is_verified $is_verified;
  239.       return $this;
  240.   }
  241.   public function getRegistrationToken(): ?string
  242.   {
  243.       return $this->registration_token;
  244.   }
  245.   public function setRegistrationToken(string $registration_token): self
  246.   {
  247.       $this->registration_token $registration_token;
  248.       return $this;
  249.   }
  250.   public function getPasswordRecoveryToken(): ?string
  251.   {
  252.       return $this->password_recovery_token;
  253.   }
  254.   public function setPasswordRecoveryToken(string $password_recovery_token): self
  255.   {
  256.       $this->password_recovery_token $password_recovery_token;
  257.       return $this;
  258.   }
  259.   public function getAccountDeletionToken(): ?string
  260.   {
  261.       return $this->account_deletion_token;
  262.   }
  263.   public function setAccountDeletionToken(?string $account_deletion_token): self
  264.   {
  265.       $this->account_deletion_token $account_deletion_token;
  266.       return $this;
  267.   }
  268. }