src/Entity/User.php line 27

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  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\Entity(repositoryClassUserRepository::class)]
  13. #[ORM\Table(name'`user`')]
  14. #[UniqueEntity(
  15.     fields: ['email'],
  16.     message'Désolé, un compte existe déjà avec cette adresse email',
  17.     errorPath'email',
  18. )]
  19. #[UniqueEntity(
  20.     fields: ['username'],
  21.     message'Désolé, un compte existe déjà avec ce pseudo',
  22.     errorPath'username',
  23. )]
  24. class User implements UserInterfacePasswordAuthenticatedUserInterface
  25. {
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue]
  28.     #[ORM\Column(type'integer')]
  29.     private $id;
  30.     #[ORM\Column(type'string'length180uniquetrue)]
  31.     private $email;
  32.     #[ORM\Column(type'string'length50uniquetrue)]
  33.     private $username;
  34.     #[ORM\Column(type'json')]
  35.     private $roles = [];
  36.     #[ORM\Column(type'string')]
  37.     private $password;
  38.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  39.     private ?\DateTimeInterface $created null;
  40.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  41.     private ?\DateTimeInterface $updated null;
  42.     #[ORM\OneToMany(mappedBy'user'targetEntityTheClone::class)]
  43.     private Collection $Clones;
  44.     #[ORM\Column]
  45.     private ?bool $is_newbie null;
  46.     #[ORM\OneToOne(mappedBy'user'cascade: ['persist''remove'])]
  47.     private ?UserRanking $userRanking null;
  48.     #[ORM\Column(length255nullabletrue)]
  49.     private ?string $avatar null;
  50.     #[ORM\ManyToMany(targetEntitySkillTree::class)]
  51.     private Collection $skills;
  52.     public function __construct()
  53.     {
  54.         $this->created = new DateTime();
  55.         $this->updated = new DateTime();
  56.         $this->Clones = new ArrayCollection();
  57.         $this->skills = new ArrayCollection();
  58.         $this->is_newbie true;
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getEmail(): ?string
  65.     {
  66.         return $this->email;
  67.     }
  68.     public function setEmail(string $email): self
  69.     {
  70.         $this->email $email;
  71.         return $this;
  72.     }
  73.     public function getUsername(): ?string
  74.     {
  75.         return $this->username;
  76.     }
  77.     public function setUsername(string $username): self
  78.     {
  79.         $this->username $username;
  80.         return $this;
  81.     }
  82.     /**
  83.      * A visual identifier that represents this user.
  84.      *
  85.      * @see UserInterface
  86.      */
  87.     public function getUserIdentifier(): string
  88.     {
  89.         return (string) $this->email;
  90.     }
  91.     /**
  92.      * @see UserInterface
  93.      */
  94.     public function getRoles(): array
  95.     {
  96.         $roles $this->roles;
  97.         // guarantee every user at least has ROLE_USER
  98.         $roles[] = 'ROLE_USER';
  99.         return array_unique($roles);
  100.     }
  101.     public function setRoles(array $roles): self
  102.     {
  103.         $this->roles $roles;
  104.         return $this;
  105.     }
  106.     /**
  107.      * @see PasswordAuthenticatedUserInterface
  108.      */
  109.     public function getPassword(): string
  110.     {
  111.         return $this->password;
  112.     }
  113.     public function setPassword(string $password): self
  114.     {
  115.         $this->password $password;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @see UserInterface
  120.      */
  121.     public function eraseCredentials()
  122.     {
  123.         // If you store any temporary, sensitive data on the user, clear it here
  124.         // $this->plainPassword = null;
  125.     }
  126.     public function getCreated(): ?\DateTimeInterface
  127.     {
  128.         return $this->created;
  129.     }
  130.     public function setCreated(\DateTimeInterface $created): self
  131.     {
  132.         $this->created $created;
  133.         return $this;
  134.     }
  135.     public function getUpdated(): ?\DateTimeInterface
  136.     {
  137.         return $this->updated;
  138.     }
  139.     public function setUpdated(\DateTimeInterface $updated): self
  140.     {
  141.         $this->updated $updated;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return Collection<int, TheClone>
  146.      */
  147.     public function getClones(): Collection
  148.     {
  149.         return $this->Clones;
  150.     }
  151.     public function addClone(TheClone $clone): self
  152.     {
  153.         if (!$this->Clones->contains($clone)) {
  154.             $this->Clones->add($clone);
  155.             $clone->setUser($this);
  156.         }
  157.         return $this;
  158.     }
  159.     public function removeClone(TheClone $clone): self
  160.     {
  161.         if ($this->Clones->removeElement($clone)) {
  162.             // set the owning side to null (unless already changed)
  163.             if ($clone->getUser() === $this) {
  164.                 $clone->setUser(null);
  165.             }
  166.         }
  167.         return $this;
  168.     }
  169.     public function isIsNewbie(): ?bool
  170.     {
  171.         return $this->is_newbie;
  172.     }
  173.     public function setIsNewbie(bool $is_newbie): static
  174.     {
  175.         $this->is_newbie $is_newbie;
  176.         return $this;
  177.     }
  178.     public function getUserRanking(): ?UserRanking
  179.     {
  180.         return $this->userRanking;
  181.     }
  182.     public function setUserRanking(UserRanking $userRanking): static
  183.     {
  184.         // set the owning side of the relation if necessary
  185.         if ($userRanking->getUser() !== $this) {
  186.             $userRanking->setUser($this);
  187.         }
  188.         $this->userRanking $userRanking;
  189.         return $this;
  190.     }
  191.     public function getAvatar(): ?string
  192.     {
  193.         return $this->avatar;
  194.     }
  195.     public function setAvatar(?string $avatar): static
  196.     {
  197.         $this->avatar $avatar;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return Collection<int, SkillTree>
  202.      */
  203.     public function getSkills(): Collection
  204.     {
  205.         return $this->skills;
  206.     }
  207.     public function addSkill(SkillTree $skill): static
  208.     {
  209.         if (!$this->skills->contains($skill)) {
  210.             $this->skills->add($skill);
  211.         }
  212.         return $this;
  213.     }
  214.     public function removeSkill(SkillTree $skill): static
  215.     {
  216.         $this->skills->removeElement($skill);
  217.         return $this;
  218.     }
  219. }