src/Entity/User.php line 26

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\DBAL\Types\Types;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use App\Repository\UserRepository;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use ApiPlatform\Metadata\ApiSubresource;
  8. use Doctrine\Common\Collections\Collection;
  9. use Symfony\Component\HttpFoundation\File\File;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. use Symfony\Component\Security\Core\User\UserInterface;
  14. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  15. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
  18. #[ORM\Entity(repositoryClassUserRepository::class)]
  19. #[ApiResource(normalizationContext: ['groups' => ['user']])]
  20. #[UniqueEntity(fields: ['email'], message'Un compte existe déjà avec cet email')]
  21. #[UniqueEntity(fields: ['userName'], message'Ce pseudo est déjà utilisé')]
  22. #[ORM\HasLifecycleCallbacks()]
  23. class User implements UserInterfacePasswordAuthenticatedUserInterface
  24. {
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column]
  28.     #[Groups(["user"])]
  29.     private ?int $id null;
  30.     #[ORM\Column(length180uniquetrue)]
  31.     private ?string $email null;
  32.     #[ORM\Column]
  33.     private array $roles = [];
  34.     /**
  35.      * @var string The hashed password
  36.      */
  37.     #[ORM\Column]
  38.     private ?string $password null;
  39.     #[ORM\OneToMany(mappedBy'user'targetEntityObjectif::class)]
  40.     #[Groups(["user"])]
  41.     private Collection $objectifs;
  42.     #[ORM\ManyToMany(targetEntityObjectif::class, mappedBy'community')]
  43.     private Collection $joinObjectifs;
  44.     #[ORM\Column(length255nullabletrue)]
  45.     #[Groups(["user"])]
  46.     private ?string $userName null;
  47.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  48.     private ?\DateTimeInterface $registerAt null;
  49.     #[ORM\Column(length255nullabletrue)]
  50.     #[Groups(["user"])]
  51.     private ?string $avatar null;
  52.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  53.     private ?string $promesse null;
  54.     #[ORM\Column(nullabletrue)]
  55.     private ?bool $isPrivate null;
  56.     #[ORM\OneToMany(mappedBy'user'targetEntityGameScore::class)]
  57.     private Collection $successPoints;
  58.     #[ORM\ManyToMany(targetEntityself::class, inversedBy'users')]
  59.     private Collection $friends;
  60.     #[ORM\ManyToMany(targetEntityself::class, mappedBy'friends')]
  61.     private Collection $users;
  62.     #[ORM\Column(nullabletrue)]
  63.     private ?bool $isDailyMailEnabled null;
  64.     #[ORM\Column(length255nullabletrue)]
  65.     private ?string $stripeId null;
  66.     #[ORM\OneToOne(inversedBy'user'cascade: ['persist''remove'])]
  67.     private ?Subscription $subscription null;
  68.     public function __construct()
  69.     {
  70.         $this->objectifs = new ArrayCollection();
  71.         $this->joinObjectifs = new ArrayCollection();
  72.         $this->successPoints = new ArrayCollection();
  73.         $this->friends = new ArrayCollection();
  74.         $this->users = new ArrayCollection();
  75.     }
  76.     #[ORM\PrePersist]
  77.     public function prePersist()
  78.     {
  79.         if (empty($this->registerAt)) {
  80.             $this->registerAt = new \DateTime();
  81.             $this->isDailyMailEnabled true;
  82.         }
  83.     }
  84.     public function getId(): ?int
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function getEmail(): ?string
  89.     {
  90.         return $this->email;
  91.     }
  92.     public function setEmail(string $email): self
  93.     {
  94.         $this->email $email;
  95.         return $this;
  96.     }
  97.     public function __toString()
  98.     {
  99.         return strtoupper($this->email);
  100.     }
  101.     /**
  102.      * A visual identifier that represents this user.
  103.      *
  104.      * @see UserInterface
  105.      */
  106.     public function getUserIdentifier(): string
  107.     {
  108.         return (string) $this->email;
  109.     }
  110.     /**
  111.      * @see UserInterface
  112.      */
  113.     public function getRoles(): array
  114.     {
  115.         $roles $this->roles;
  116.         // guarantee every user at least has ROLE_USER
  117.         $roles[] = 'ROLE_USER';
  118.         return array_unique($roles);
  119.     }
  120.     public function setRoles(array $roles): self
  121.     {
  122.         $this->roles $roles;
  123.         return $this;
  124.     }
  125.     /**
  126.      * @see PasswordAuthenticatedUserInterface
  127.      */
  128.     public function getPassword(): string
  129.     {
  130.         return $this->password;
  131.     }
  132.     public function setPassword(string $password): self
  133.     {
  134.         $this->password $password;
  135.         return $this;
  136.     }
  137.     /**
  138.      * @see UserInterface
  139.      */
  140.     public function eraseCredentials()
  141.     {
  142.         // If you store any temporary, sensitive data on the user, clear it here
  143.         // $this->plainPassword = null;
  144.     }
  145.     /**
  146.      * @return Collection<int, Objectif>
  147.      */
  148.     public function getObjectifs(): Collection
  149.     {
  150.         return $this->objectifs;
  151.     }
  152.     public function addObjectif(Objectif $objectif): self
  153.     {
  154.         if (!$this->objectifs->contains($objectif)) {
  155.             $this->objectifs->add($objectif);
  156.             $objectif->setUser($this);
  157.         }
  158.         return $this;
  159.     }
  160.     public function removeObjectif(Objectif $objectif): self
  161.     {
  162.         if ($this->objectifs->removeElement($objectif)) {
  163.             // set the owning side to null (unless already changed)
  164.             if ($objectif->getUser() === $this) {
  165.                 $objectif->setUser(null);
  166.             }
  167.         }
  168.         return $this;
  169.     }
  170.     /**
  171.      * @return Collection<int, Objectif>
  172.      */
  173.     public function getJoinObjectifs(): Collection
  174.     {
  175.         return $this->joinObjectifs;
  176.     }
  177.     public function addJoinObjectif(Objectif $joinObjectif): self
  178.     {
  179.         if (!$this->joinObjectifs->contains($joinObjectif)) {
  180.             $this->joinObjectifs->add($joinObjectif);
  181.             $joinObjectif->addCommunity($this);
  182.         }
  183.         return $this;
  184.     }
  185.     public function removeJoinObjectif(Objectif $joinObjectif): self
  186.     {
  187.         if ($this->joinObjectifs->removeElement($joinObjectif)) {
  188.             $joinObjectif->removeCommunity($this);
  189.         }
  190.         return $this;
  191.     }
  192.     public function getUserName(): ?string
  193.     {
  194.         return $this->userName;
  195.     }
  196.     public function setUserName(?string $userName): self
  197.     {
  198.         $this->userName $userName;
  199.         return $this;
  200.     }
  201.     public function getRegisterAt(): ?\DateTimeInterface
  202.     {
  203.         return $this->registerAt;
  204.     }
  205.     public function setRegisterAt(\DateTimeInterface $registerAt): self
  206.     {
  207.         $this->registerAt $registerAt;
  208.         return $this;
  209.     }
  210.     public function getAvatar(): ?string
  211.     {
  212.         return $this->avatar;
  213.     }
  214.     public function setAvatar(?string $avatar): self
  215.     {
  216.         $this->avatar $avatar;
  217.         return $this;
  218.     }
  219.     public function getPromesse(): ?string
  220.     {
  221.         return $this->promesse;
  222.     }
  223.     public function setPromesse(?string $promesse): self
  224.     {
  225.         $this->promesse $promesse;
  226.         return $this;
  227.     }
  228.     public function isIsPrivate(): ?bool
  229.     {
  230.         return $this->isPrivate;
  231.     }
  232.     public function setIsPrivate(?bool $isPrivate): self
  233.     {
  234.         $this->isPrivate $isPrivate;
  235.         return $this;
  236.     }
  237.     /**
  238.      * @return Collection<int, GameScore>
  239.      */
  240.     public function getSuccessPoints(): Collection
  241.     {
  242.         return $this->successPoints;
  243.     }
  244.     public function addSuccessPoint(GameScore $successPoint): self
  245.     {
  246.         if (!$this->successPoints->contains($successPoint)) {
  247.             $this->successPoints->add($successPoint);
  248.             $successPoint->setUser($this);
  249.         }
  250.         return $this;
  251.     }
  252.     public function removeSuccessPoint(GameScore $successPoint): self
  253.     {
  254.         if ($this->successPoints->removeElement($successPoint)) {
  255.             // set the owning side to null (unless already changed)
  256.             if ($successPoint->getUser() === $this) {
  257.                 $successPoint->setUser(null);
  258.             }
  259.         }
  260.         return $this;
  261.     }
  262.     /**
  263.      * @return Collection<int, self>
  264.      */
  265.     public function getFriends(): Collection
  266.     {
  267.         return $this->friends;
  268.     }
  269.     public function addFriend(self $friend): self
  270.     {
  271.         if (!$this->friends->contains($friend)) {
  272.             $this->friends->add($friend);
  273.         }
  274.         return $this;
  275.     }
  276.     public function removeFriend(self $friend): self
  277.     {
  278.         $this->friends->removeElement($friend);
  279.         return $this;
  280.     }
  281.     /**
  282.      * @return Collection<int, self>
  283.      */
  284.     public function getUsers(): Collection
  285.     {
  286.         return $this->users;
  287.     }
  288.     public function addUser(self $user): self
  289.     {
  290.         if (!$this->users->contains($user)) {
  291.             $this->users->add($user);
  292.             $user->addFriend($this);
  293.         }
  294.         return $this;
  295.     }
  296.     public function removeUser(self $user): self
  297.     {
  298.         if ($this->users->removeElement($user)) {
  299.             $user->removeFriend($this);
  300.         }
  301.         return $this;
  302.     }
  303.     public function isIsDailyMailEnabled(): ?bool
  304.     {
  305.         return $this->isDailyMailEnabled;
  306.     }
  307.     public function setIsDailyMailEnabled(?bool $isDailyMailEnabled): self
  308.     {
  309.         $this->isDailyMailEnabled $isDailyMailEnabled;
  310.         return $this;
  311.     }
  312.     public function getStripeId(): ?string
  313.     {
  314.         return $this->stripeId;
  315.     }
  316.     public function setStripeId(?string $stripeId): self
  317.     {
  318.         $this->stripeId $stripeId;
  319.         return $this;
  320.     }
  321.     public function getSubscription(): ?Subscription
  322.     {
  323.         return $this->subscription;
  324.     }
  325.     public function setSubscription(?Subscription $subscription): self
  326.     {
  327.         $this->subscription $subscription;
  328.         return $this;
  329.     }
  330. }