src/Entity/User.php line 20

Open in your IDE?
  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 Gedmo\Mapping\Annotation as Gedmo;
  8. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. /**
  13.  *
  14.  * @ORM\Entity(repositoryClass=UserRepository::class)
  15.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  16.  */
  17. class User implements UserInterfacePasswordAuthenticatedUserInterface
  18. {
  19.     use TimestampableEntity;
  20.     public const ANONIMIZE_FIELDS = [
  21.         'name',
  22.         'lastName',
  23.         'email',
  24.     ];
  25.     /**
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     private $id;
  31.     /**
  32.      * @ORM\Column(type="string", length=180, unique=true)
  33.      */
  34.     private $email;
  35.     /**
  36.      * @ORM\Column(type="json")
  37.      */
  38.     private $roles = [];
  39.     /**
  40.      * @var string The hashed password
  41.      * @ORM\Column(type="string")
  42.      */
  43.     private $password;
  44.     /**
  45.      * @ORM\Column(type="string", length=128, nullable=true)
  46.      */
  47.     private $name;
  48.     /**
  49.      * @ORM\Column(type="string", length=128, nullable=true)
  50.      */
  51.     private $lastName;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity=News::class, mappedBy="author")
  54.      */
  55.     private $news;
  56.     /**
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      */
  59.     private $type;
  60.     /**
  61.      * @ORM\Column(type="string", length=64, nullable=true)
  62.      */
  63.     private $lang;
  64.     /**
  65.      * @ORM\Column(type="boolean", nullable=true)
  66.      */
  67.     private $enabled;
  68.     /**
  69.      * @var ArrayCollection
  70.      * @ORM\OneToMany(targetEntity="App\Entity\TokenUser", mappedBy="user",cascade={"persist", "remove"})
  71.      */
  72.     private $tokens;
  73.     /**
  74.      * @ORM\ManyToMany(targetEntity=Player::class, inversedBy="users", cascade={"persist", "remove"})
  75.      */
  76.     private $favoritePlayers;
  77.     /**
  78.      * @ORM\ManyToOne(targetEntity=Country::class, inversedBy="users")
  79.      * @ORM\JoinColumn(nullable=false)
  80.      */
  81.     private $country;
  82.     /**
  83.      * @ORM\Column(type="boolean", nullable=true)
  84.      */
  85.     private $assistance;
  86.     /**
  87.      * @ORM\Column(type="string", length=128, nullable=true)
  88.      */
  89.     private $yearOfBirth;
  90.     /**
  91.      * @ORM\Column(type="string", length=32, nullable=true)
  92.      */
  93.     private $gender;
  94.     /**
  95.      * @ORM\Column(type="datetime", nullable=true)
  96.      * @var \DateTime|null
  97.      */
  98.     protected $deletedAt;
  99.     /**
  100.      * @ORM\OneToMany(targetEntity=Award::class, mappedBy="user")
  101.      */
  102.     private $awards;
  103.     /**
  104.      * @ORM\OneToMany(targetEntity=Ticket::class, mappedBy="user")
  105.      */
  106.     private $tickets;
  107.    
  108.   
  109.     /**
  110.      * Set or clear the deleted at timestamp.
  111.      *
  112.      * @param \DateTime|null $deletedAt
  113.      * @return self
  114.      */
  115.     public function setDeletedAt(\DateTime $deletedAt null): User
  116.     {
  117.         $this->deletedAt $deletedAt;
  118.         return $this;
  119.     }
  120.     /**
  121.      * Get the deleted at timestamp value. Will return null if
  122.      * the entity has not been soft deleted.
  123.      *
  124.      * @return \DateTime|null
  125.      */
  126.     public function getDeletedAt(): ?\DateTime
  127.     {
  128.         return $this->deletedAt;
  129.     }
  130.     public function __construct()
  131.     {
  132.         $this->news = new ArrayCollection();
  133.         $this->tokens = new ArrayCollection();
  134.         $this->favoritePlayers = new ArrayCollection();
  135.         $this->lang 'es';
  136.         $this->awards = new ArrayCollection();
  137.         $this->tickets = new ArrayCollection();
  138.         
  139.     }
  140.     public function __toString()
  141.     {
  142.         return $this->email;
  143.     }
  144.     public function getId(): ?int
  145.     {
  146.         return $this->id;
  147.     }
  148.     public function getEmail(): ?string
  149.     {
  150.         return $this->email;
  151.     }
  152.     public function setEmail(string $email): self
  153.     {
  154.         $this->email $email;
  155.         return $this;
  156.     }
  157.     /**
  158.      * A visual identifier that represents this user.
  159.      *
  160.      * @see UserInterface
  161.      */
  162.     public function getUserIdentifier(): string
  163.     {
  164.         return (string) $this->email;
  165.     }
  166.     /**
  167.      * @see UserInterface
  168.      */
  169.     public function getRoles(): array
  170.     {
  171.         $roles $this->roles;
  172.         // guarantee every user at least has ROLE_USER
  173.         $roles[] = 'ROLE_USER';
  174.         return array_unique($roles);
  175.     }
  176.     public function setRoles(array $roles): self
  177.     {
  178.         $this->roles $roles;
  179.         return $this;
  180.     }
  181.     /**
  182.      * @see PasswordAuthenticatedUserInterface
  183.      */
  184.     public function getPassword(): string
  185.     {
  186.         return $this->password;
  187.     }
  188.     public function setPassword(string $password): self
  189.     {
  190.         $this->password $password;
  191.         return $this;
  192.     }
  193.     /**
  194.      * Returning a salt is only needed, if you are not using a modern
  195.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  196.      *
  197.      * @see UserInterface
  198.      */
  199.     public function getSalt(): ?string
  200.     {
  201.         return null;
  202.     }
  203.     /**
  204.      * @see UserInterface
  205.      */
  206.     public function eraseCredentials()
  207.     {
  208.         // If you store any temporary, sensitive data on the user, clear it here
  209.         // $this->plainPassword = null;
  210.     }
  211.     public function getName(): ?string
  212.     {
  213.         return $this->name;
  214.     }
  215.     public function setName(string $name): self
  216.     {
  217.         $this->name $name;
  218.         return $this;
  219.     }
  220.     public function getLastName(): ?string
  221.     {
  222.         return $this->lastName;
  223.     }
  224.     public function setLastName(?string $lastName): self
  225.     {
  226.         $this->lastName $lastName;
  227.         return $this;
  228.     }
  229.     /**
  230.      * @return Collection
  231.      */
  232.     public function getNews(): Collection
  233.     {
  234.         return $this->news;
  235.     }
  236.     public function addNews(News $news): self
  237.     {
  238.         if (!$this->news->contains($news)) {
  239.             $this->news[] = $news;
  240.             $news->setAuthor($this);
  241.         }
  242.         return $this;
  243.     }
  244.     public function removeNews(News $news): self
  245.     {
  246.         if ($this->news->removeElement($news)) {
  247.             // set the owning side to null (unless already changed)
  248.             if ($news->getAuthor() === $this) {
  249.                 $news->setAuthor(null);
  250.             }
  251.         }
  252.         return $this;
  253.     }
  254.     public function getType(): ?string
  255.     {
  256.         return $this->type;
  257.     }
  258.     public function setType(?string $type): self
  259.     {
  260.         $this->type $type;
  261.         return $this;
  262.     }
  263.     public function getLang(): ?string
  264.     {
  265.         return $this->lang ?? 'es';
  266.     }
  267.     public function setLang(?string $lang): self
  268.     {
  269.         $this->lang $lang;
  270.         return $this;
  271.     }
  272.     public function getUsername(): ?string
  273.     {
  274.         return $this->getEmail();
  275.     }
  276.     public function isEnabled(): ?bool
  277.     {
  278.         return $this->enabled;
  279.     }
  280.     public function setEnabled(?bool $enabled): self
  281.     {
  282.         $this->enabled $enabled;
  283.         return $this;
  284.     }
  285.     public function getTokens(): ArrayCollection
  286.     {
  287.         return $this->tokens;
  288.     }
  289.     /**
  290.      * @return $this
  291.      */
  292.     public function addToken(TokenUser $tokenUser): self
  293.     {
  294.         $tokenUser->setUser($this);
  295.         return $this;
  296.     }
  297.     /**
  298.      * @return $this
  299.      */
  300.     public function removeTokenUser(TokenUser $tokenUser): self
  301.     {
  302.         if ($tokenUser->getUser() === $this) {
  303.             $tokenUser->setUser(null);
  304.         }
  305.         return $this;
  306.     }
  307.     /**
  308.      * @return Collection|Player[]
  309.      */
  310.     public function getFavoritePlayers(): Collection
  311.     {
  312.         return $this->favoritePlayers;
  313.     }
  314.     public function addFavoritePlayer(Player $favoritePlayer): self
  315.     {
  316.         if (!$this->favoritePlayers->contains($favoritePlayer)) {
  317.             $this->favoritePlayers[] = $favoritePlayer;
  318.         }
  319.         return $this;
  320.     }
  321.     public function removeFavoritePlayer(Player $favoritePlayer): self
  322.     {
  323.         $this->favoritePlayers->removeElement($favoritePlayer);
  324.         return $this;
  325.     }
  326.     public function getFullName(): ?string
  327.     {
  328.         return $this->name ' ' $this->lastName;
  329.     }
  330.     public function getCountry(): ?Country
  331.     {
  332.         return $this->country;
  333.     }
  334.     public function setCountry(?Country $country): self
  335.     {
  336.         $this->country $country;
  337.         return $this;
  338.     }
  339.     public function getAssistance(): ?bool
  340.     {
  341.         return $this->assistance;
  342.     }
  343.     public function setAssistance(bool $assistance): self
  344.     {
  345.         $this->assistance $assistance;
  346.         return $this;
  347.     }
  348.     public function getYearOfBirth(): ?string
  349.     {
  350.         return $this->yearOfBirth;
  351.     }
  352.     public function setYearOfBirth(string $yearOfBirth): self
  353.     {
  354.         $this->yearOfBirth $yearOfBirth;
  355.         return $this;
  356.     }
  357.     public function getGender(): ?string
  358.     {
  359.         return $this->gender;
  360.     }
  361.     public function setGender(string $gender): self
  362.     {
  363.         $this->gender $gender;
  364.         return $this;
  365.     }
  366.     /**
  367.      * @return Collection|Award[]
  368.      */
  369.     public function getAwards(): Collection
  370.     {
  371.         return $this->awards;
  372.     }
  373.     public function addAward(Award $award): self
  374.     {
  375.         if (!$this->awards->contains($award)) {
  376.             $this->awards[] = $award;
  377.             $award->setUser($this);
  378.         }
  379.         return $this;
  380.     }
  381.     public function removeAward(Award $award): self
  382.     {
  383.         if ($this->awards->removeElement($award)) {
  384.             // set the owning side to null (unless already changed)
  385.             if ($award->getUser() === $this) {
  386.                 $award->setUser(null);
  387.             }
  388.         }
  389.         return $this;
  390.     }
  391.     /**
  392.      * @return Collection|Ticket[]
  393.      */
  394.     public function getTickets(): Collection
  395.     {
  396.         return $this->tickets;
  397.     }
  398.     public function addTicket(Ticket $ticket): self
  399.     {
  400.         if (!$this->tickets->contains($ticket)) {
  401.             $this->tickets[] = $ticket;
  402.             $ticket->setUser($this);
  403.         }
  404.         return $this;
  405.     }
  406.     public function removeTicket(Ticket $ticket): self
  407.     {
  408.         if ($this->tickets->removeElement($ticket)) {
  409.             // set the owning side to null (unless already changed)
  410.             if ($ticket->getUser() === $this) {
  411.                 $ticket->setUser(null);
  412.             }
  413.         }
  414.         return $this;
  415.     }
  416. }