src/Entity/User.php line 17

  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. /**
  11.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  12.  */
  13. #[ORM\Entity(repositoryClassUserRepository::class)]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column(type'integer')]
  19.     private $id;
  20.     #[ORM\Column(type'string'length255)]
  21.     private $nickname;
  22.     
  23.     #[ORM\Column(type'string'length180uniquetrue)]
  24.     private $email;
  25.     #[ORM\Column(type'json')]
  26.     private $roles = [];
  27.     const ROLES = array(
  28.         'Administrateur' => 'ROLE_FATHER',
  29.         'MaĆ®tre de jeu' => 'ROLE_MASTER',
  30.         'Joueur' => 'ROLE_USER'
  31.     );
  32.     #[ORM\Column(type'string')]
  33.     private $password;
  34.     /**
  35.      * @ORM\Column(type="boolean")
  36.      */
  37.     private $isVerified false;
  38.     #[ORM\OneToMany(mappedBy'player'targetEntityPlayableEntity::class)]
  39.     private $playableEntities;
  40.     #[ORM\OneToOne(inversedBy'user'targetEntityPlayableEntity::class, cascade: ['persist''remove'])]
  41.     private $character;
  42.     #[ORM\Column(length255nullabletrue)]
  43.     private ?string $avatar null;
  44.     #[ORM\OneToOne(mappedBy'user'cascade: ['persist''remove'])]
  45.     private ?Image $image null;
  46.     #[ORM\OneToMany(mappedBy'sender'targetEntityUserMessage::class)]
  47.     private Collection $sent;
  48.     #[ORM\OneToMany(mappedBy'recipient'targetEntityUserMessage::class)]
  49.     private Collection $received;
  50.     public function __construct()
  51.     {
  52.         $this->playableEntities = new ArrayCollection();
  53.         $this->sent = new ArrayCollection();
  54.         $this->received = new ArrayCollection();
  55.     }
  56.     public function getId(): ?int
  57.     {
  58.         return $this->id;
  59.     }
  60.     public function getEmail(): ?string
  61.     {
  62.         return $this->email;
  63.     }
  64.     public function setEmail(string $email): self
  65.     {
  66.         $this->email $email;
  67.         return $this;
  68.     }
  69.     /**
  70.      * A visual identifier that represents this user.
  71.      *
  72.      * @see UserInterface
  73.      */
  74.     public function getUserIdentifier(): string
  75.     {
  76.         return (string) $this->email;
  77.     }
  78.     /**
  79.      * @see UserInterface
  80.      */
  81.     public function getRoles(): array
  82.     {
  83.         $roles $this->roles;
  84.         // guarantee every user at least has ROLE_USER
  85.         $roles[] = 'ROLE_USER';
  86.         return array_unique($roles);
  87.     }
  88.     public function setRoles(array $roles): self
  89.     {
  90.         $this->roles $roles;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @see PasswordAuthenticatedUserInterface
  95.      */
  96.     public function getPassword(): string
  97.     {
  98.         return $this->password;
  99.     }
  100.     public function setPassword(string $password): self
  101.     {
  102.         $this->password $password;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @see UserInterface
  107.      */
  108.     public function eraseCredentials()
  109.     {
  110.         // If you store any temporary, sensitive data on the user, clear it here
  111.         // $this->plainPassword = null;
  112.     }
  113.     public function getNickname(): ?string
  114.     {
  115.         return $this->nickname;
  116.     }
  117.     public function setNickname(string $nickname): self
  118.     {
  119.         $this->nickname $nickname;
  120.         return $this;
  121.     }
  122.     public function isVerified(): bool
  123.     {
  124.         return $this->isVerified;
  125.     }
  126.     public function setIsVerified(bool $isVerified): self
  127.     {
  128.         $this->isVerified $isVerified;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return Collection|PlayableEntity[]
  133.      */
  134.     public function getPlayableEntities(): Collection
  135.     {
  136.         return $this->playableEntities;
  137.     }
  138.     public function addPlayableEntity(PlayableEntity $playableEntity): self
  139.     {
  140.         if (!$this->playableEntities->contains($playableEntity)) {
  141.             $this->playableEntities[] = $playableEntity;
  142.             $playableEntity->setPlayer($this);
  143.         }
  144.         return $this;
  145.     }
  146.     public function removePlayableEntity(PlayableEntity $playableEntity): self
  147.     {
  148.         if ($this->playableEntities->removeElement($playableEntity)) {
  149.             // set the owning side to null (unless already changed)
  150.             if ($playableEntity->getPlayer() === $this) {
  151.                 $playableEntity->setPlayer(null);
  152.             }
  153.         }
  154.         return $this;
  155.     }
  156.     public function __toString()
  157.     {
  158.         return (string) $this->nickname;
  159.     }
  160.     public function getCharacter(): ?PlayableEntity
  161.     {
  162.         return $this->character;
  163.     }
  164.     public function setCharacter(?PlayableEntity $character): self
  165.     {
  166.         $this->character $character;
  167.         return $this;
  168.     }
  169.     public function getAvatar(): ?string
  170.     {
  171.         return $this->avatar;
  172.     }
  173.     public function setAvatar(?string $avatar): self
  174.     {
  175.         $this->avatar $avatar;
  176.         return $this;
  177.     }
  178.     public function getImage(): ?Image
  179.     {
  180.         return $this->image;
  181.     }
  182.     public function setImage(?Image $image): self
  183.     {
  184.         // unset the owning side of the relation if necessary
  185.         if ($image === null && $this->image !== null) {
  186.             $this->image->setUser(null);
  187.         }
  188.         // set the owning side of the relation if necessary
  189.         if ($image !== null && $image->getUser() !== $this) {
  190.             $image->setUser($this);
  191.         }
  192.         $this->image $image;
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return Collection<int, UserMessage>
  197.      */
  198.     public function getSent(): Collection
  199.     {
  200.         return $this->sent;
  201.     }
  202.     public function addSent(UserMessage $sent): self
  203.     {
  204.         if (!$this->sent->contains($sent)) {
  205.             $this->sent->add($sent);
  206.             $sent->setSender($this);
  207.         }
  208.         return $this;
  209.     }
  210.     public function removeSent(UserMessage $sent): self
  211.     {
  212.         if ($this->sent->removeElement($sent)) {
  213.             // set the owning side to null (unless already changed)
  214.             if ($sent->getSender() === $this) {
  215.                 $sent->setSender(null);
  216.             }
  217.         }
  218.         return $this;
  219.     }
  220.     /**
  221.      * @return Collection<int, UserMessage>
  222.      */
  223.     public function getReceived(): Collection
  224.     {
  225.         return $this->received;
  226.     }
  227.     public function addReceived(UserMessage $received): self
  228.     {
  229.         if (!$this->received->contains($received)) {
  230.             $this->received->add($received);
  231.             $received->setRecipient($this);
  232.         }
  233.         return $this;
  234.     }
  235.     public function removeReceived(UserMessage $received): self
  236.     {
  237.         if ($this->received->removeElement($received)) {
  238.             // set the owning side to null (unless already changed)
  239.             if ($received->getRecipient() === $this) {
  240.                 $received->setRecipient(null);
  241.             }
  242.         }
  243.         return $this;
  244.     }
  245. }