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. use Doctrine\DBAL\Types\Types;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. #[ORM\Table(name'`user`')]
  13. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     
  17.     const ROLE_ADMIN 'ROLE_ADMIN';
  18.     const ROLE_USER 'ROLE_USER';
  19.     
  20.     const LOGIN_SOCIAL_NULL 0;
  21.     const LOGIN_SOCIAL_TWITTER 1;
  22.     const LOGIN_SOCIAL_GOOGLE 2;
  23.     const LOGIN_SOCIAL_FACEBOOK 3;
  24.     
  25.     
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue]
  28.     #[ORM\Column]
  29.     private ?int $id null;
  30.     #[ORM\Column(length180uniquetrue)]
  31.     private ?string $email null;
  32.     
  33.     #[ORM\Column(length180nullabletrue)]
  34.     private ?string $apelido null;
  35.     
  36.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  37.     private ?string $avatar null;
  38.     
  39.     #[ORM\Column]
  40.     private array $roles = [];
  41.     /**
  42.      * @var string The hashed password
  43.      */
  44.     #[ORM\Column]
  45.     private ?string $password null;
  46.     #[ORM\Column(type'boolean')]
  47.     private $isVerified false;
  48.     #[ORM\OneToMany(mappedBy'Usuario'targetEntityToken::class, orphanRemovaltrue)]
  49.     private Collection $tokens;
  50.     
  51.     #[ORM\ManyToOne(inversedBy'Usuarios'targetEntityPerfil::class)]
  52.     #[ORM\JoinColumn(nullabletrue)]
  53.     private ?Perfil $Perfil null;
  54.     
  55.     #[ORM\Column(type'boolean')]
  56.     private $isExpired false;
  57.     
  58.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  59.     private ?\DateTimeInterface $lastlogin null;
  60.     
  61.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  62.     private ?\DateTimeInterface $created_at null;
  63.     
  64.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  65.     private ?\DateTimeInterface $updated_at null;
  66.     #[ORM\OneToMany(mappedBy'Usuario'targetEntityJogosUsuario::class)]
  67.     private Collection $JogosUsuarios;
  68.     #[ORM\Column(nullabletrue)]
  69.     private ?float $saldo null;
  70.     #[ORM\OneToMany(mappedBy'User'targetEntityCreditos::class)]
  71.     private Collection $Creditos;
  72.     #[ORM\OneToMany(mappedBy'User'targetEntityConvites::class)]
  73.     private Collection $Convites;
  74.     #[ORM\OneToMany(mappedBy'UserEuConvidei'targetEntityConexoes::class)]
  75.     private Collection $ConexoesConvidantes;
  76.     #[ORM\OneToMany(mappedBy'Desafiador'targetEntityDesafios::class)]
  77.     private Collection $Desafiador;
  78.     #[ORM\OneToMany(mappedBy'User'targetEntityUserPalavras::class)]
  79.     private Collection $UserPalavras;
  80.     
  81.     #[ORM\OneToMany(mappedBy'User'targetEntityUserParametros::class)]
  82.     private Collection $UserParametros;
  83.     #[ORM\Column]
  84.     private ?int $loginsocial null;
  85.     #[ORM\Column(length255)]
  86.     private ?string $deviceId null;
  87.     #[ORM\Column(nullabletrue)]
  88.     private ?int $pontos null;
  89.     #[ORM\Column(nullabletrue)]
  90.     private ?array $configuracoes null;
  91.     #[ORM\Column(length255)]
  92.     private ?string $tokenPush null;
  93.     #[ORM\Column(length255)]
  94.     private ?string $tokenTipo null;
  95.     #[ORM\Column]
  96.     private ?int $tentativaPush null;
  97.     public function __construct()
  98.     {
  99.         $this->tokens = new ArrayCollection();
  100.         $this->JogosUsuarios = new ArrayCollection();
  101.         $this->Creditos = new ArrayCollection();
  102.         $this->Convites = new ArrayCollection();
  103.         $this->ConexoesConvidantes = new ArrayCollection();
  104.         $this->Desafiador = new ArrayCollection();
  105.         $this->UserPalavras = new ArrayCollection();
  106.         $this->UserParametros = new ArrayCollection();
  107.     }
  108.     public function getId(): ?int
  109.     {
  110.         return $this->id;
  111.     }
  112.     
  113.     public function getPerfil(): ?Perfil
  114.     {
  115.         return $this->Perfil;
  116.     }
  117.     public function setPerfil(?Perfil $Perfil): self
  118.     {
  119.         $this->Perfil $Perfil;
  120.         return $this;
  121.     }
  122.     public function getEmail(): ?string
  123.     {
  124.         return $this->email;
  125.     }
  126.     public function setEmail(string $email): self
  127.     {
  128.         $this->email $email;
  129.         return $this;
  130.     }
  131.     
  132.     public function getApelido(): ?string
  133.     {
  134.         return $this->apelido;
  135.     }
  136.     public function setApelido(string $apelido): self
  137.     {
  138.         $this->apelido $apelido;
  139.         return $this;
  140.     }
  141.     
  142.     public function getAvatar(): ?string
  143.     {
  144.         return $this->avatar;
  145.     }
  146.     public function setAvatar(string $avatar): self
  147.     {
  148.         $this->avatar $avatar;
  149.         return $this;
  150.     }
  151.     /**
  152.      * A visual identifier that represents this user.
  153.      *
  154.      * @see UserInterface
  155.      */
  156.     public function getUserIdentifier(): string
  157.     {
  158.         return (string) $this->email;
  159.     }
  160.     /**
  161.      * @see UserInterface
  162.      */
  163.     public function getRoles(): array
  164.     {
  165.         $roles $this->roles;
  166.         
  167.         return array_unique($roles);
  168.     }
  169.     public function setRoles(array $roles): self
  170.     {
  171.         $this->roles $roles;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @see PasswordAuthenticatedUserInterface
  176.      */
  177.     public function getPassword(): string
  178.     {
  179.         return $this->password;
  180.     }
  181.     public function setPassword(string $password): self
  182.     {
  183.         $this->password $password;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @see UserInterface
  188.      */
  189.     public function eraseCredentials()
  190.     {
  191.         // If you store any temporary, sensitive data on the user, clear it here
  192.         // $this->plainPassword = null;
  193.     }
  194.     public function isVerified(): bool
  195.     {
  196.         return $this->isVerified;
  197.     }
  198.     public function setIsVerified(bool $isVerified): self
  199.     {
  200.         $this->isVerified $isVerified;
  201.         return $this;
  202.     }
  203.     
  204.     public function isExpired(): bool
  205.     {
  206.         return $this->isExpired;
  207.     }
  208.     public function setIsExpired(bool $isExpired): self
  209.     {
  210.         $this->isExpired $isExpired;
  211.         return $this;
  212.     }
  213.     /**
  214.      * @return Collection<int, Token>
  215.      */
  216.     public function getTokens(): Collection
  217.     {
  218.         return $this->tokens;
  219.     }
  220.     public function addToken(Token $token): self
  221.     {
  222.         if (!$this->tokens->contains($token)) {
  223.             $this->tokens->add($token);
  224.             $token->setUsuario($this);
  225.         }
  226.         return $this;
  227.     }
  228.     public function removeToken(Token $token): self
  229.     {
  230.         if ($this->tokens->removeElement($token)) {
  231.             // set the owning side to null (unless already changed)
  232.             if ($token->getUsuario() === $this) {
  233.                 $token->setUsuario(null);
  234.             }
  235.         }
  236.         return $this;
  237.     }
  238.     
  239.     public function getLastlogin(): ?\DateTimeInterface
  240.     {
  241.         return $this->lastlogin;
  242.     }
  243.     public function setLastlogin(\DateTimeInterface $lastlogin): self
  244.     {
  245.         $this->lastlogin $lastlogin;
  246.         return $this;
  247.     }
  248.     
  249.     public function getCreatedAt(): ?\DateTimeInterface
  250.     {
  251.         return $this->created_at;
  252.     }
  253.     public function setCreatedAt(): self
  254.     {
  255.         $this->created_at = new \DateTime('now');
  256.         return $this;
  257.     }
  258.     
  259.     public function getUpdatedAt(): ?\DateTimeInterface
  260.     {
  261.         return $this->updated_at;
  262.     }
  263.     public function setUpdatedAt(): self
  264.     {
  265.         $this->updated_at = new \DateTime('now');
  266.         return $this;
  267.     }
  268.     
  269.     public function isAdmin()
  270.     {
  271.         return $this->checkRole(self::ROLE_ADMIN);
  272.     }
  273.     
  274.     public function isUser()
  275.     {
  276.         return $this->checkRole(self::ROLE_USER);
  277.     }    
  278.     
  279.     private function checkRole($role)
  280.     {
  281.         $filtered_array = [];
  282.         if(is_array($this->getRoles())){
  283.             $filtered_array array_filter($this->getRoles(), function($value$key) use ($role) {
  284.                 return $value == $role;
  285.             }, ARRAY_FILTER_USE_BOTH);
  286.         }
  287.         
  288.         return count($filtered_array) == 1;
  289.     }
  290.     /**
  291.      * @return Collection<int, JogosUsuario>
  292.      */
  293.     public function getJogosUsuarios(): Collection
  294.     {
  295.         return $this->JogosUsuarios;
  296.     }
  297.     public function addJogosUsuario(JogosUsuario $jogosUsuario): self
  298.     {
  299.         if (!$this->JogosUsuarios->contains($jogosUsuario)) {
  300.             $this->JogosUsuarios->add($jogosUsuario);
  301.             $jogosUsuario->setUsuario($this);
  302.         }
  303.         return $this;
  304.     }
  305.     public function removeJogosUsuario(JogosUsuario $jogosUsuario): self
  306.     {
  307.         if ($this->JogosUsuarios->removeElement($jogosUsuario)) {
  308.             // set the owning side to null (unless already changed)
  309.             if ($jogosUsuario->getUsuario() === $this) {
  310.                 $jogosUsuario->setUsuario(null);
  311.             }
  312.         }
  313.         return $this;
  314.     }
  315.     public function getSaldo(): ?float
  316.     {
  317.         return $this->saldo;
  318.     }
  319.     public function setSaldo(?float $saldo): self
  320.     {
  321.         $this->saldo $saldo;
  322.         return $this;
  323.     }
  324.     /**
  325.      * @return Collection<int, Creditos>
  326.      */
  327.     public function getCreditos(): Collection
  328.     {
  329.         return $this->Creditos;
  330.     }
  331.     public function addCredito(Creditos $credito): self
  332.     {
  333.         if (!$this->Creditos->contains($credito)) {
  334.             $this->Creditos->add($credito);
  335.             $credito->setUser($this);
  336.         }
  337.         return $this;
  338.     }
  339.     public function removeCredito(Creditos $credito): self
  340.     {
  341.         if ($this->Creditos->removeElement($credito)) {
  342.             // set the owning side to null (unless already changed)
  343.             if ($credito->getUser() === $this) {
  344.                 $credito->setUser(null);
  345.             }
  346.         }
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return Collection<int, Convites>
  351.      */
  352.     public function getConvites(): Collection
  353.     {
  354.         return $this->Convites;
  355.     }
  356.     public function addConvite(Convites $convite): self
  357.     {
  358.         if (!$this->Convites->contains($convite)) {
  359.             $this->Convites->add($convite);
  360.             $convite->setUser($this);
  361.         }
  362.         return $this;
  363.     }
  364.     public function removeConvite(Convites $convite): self
  365.     {
  366.         if ($this->Convites->removeElement($convite)) {
  367.             // set the owning side to null (unless already changed)
  368.             if ($convite->getUser() === $this) {
  369.                 $convite->setUser(null);
  370.             }
  371.         }
  372.         return $this;
  373.     }
  374.     /**
  375.      * @return Collection<int, Conexoes>
  376.      */
  377.     public function getConexoesConvidantes(): Collection
  378.     {
  379.         return $this->ConexoesConvidantes;
  380.     }
  381.     public function addConexoesConvidante(Conexoes $conexoesConvidante): self
  382.     {
  383.         if (!$this->ConexoesConvidantes->contains($conexoesConvidante)) {
  384.             $this->ConexoesConvidantes->add($conexoesConvidante);
  385.             $conexoesConvidante->setUserConvidante($this);
  386.         }
  387.         return $this;
  388.     }
  389.     public function removeConexoesConvidante(Conexoes $conexoesConvidante): self
  390.     {
  391.         if ($this->ConexoesConvidantes->removeElement($conexoesConvidante)) {
  392.             // set the owning side to null (unless already changed)
  393.             if ($conexoesConvidante->getUserConvidante() === $this) {
  394.                 $conexoesConvidante->setUserConvidante(null);
  395.             }
  396.         }
  397.         return $this;
  398.     }
  399.     /**
  400.      * @return Collection<int, Desafios>
  401.      */
  402.     public function getDesafiador(): Collection
  403.     {
  404.         return $this->Desafiador;
  405.     }
  406.     public function addDesafiador(Desafios $Desafiador): self
  407.     {
  408.         if (!$this->Desafiador->contains($Desafiador)) {
  409.             $this->Desafiador->add($Desafiador);
  410.             $Desafiador->setUser($this);
  411.         }
  412.         return $this;
  413.     }
  414.     public function removeDesafiador(Desafios $Desafiador): self
  415.     {
  416.         if ($this->Desafiador->removeElement($Desafiador)) {
  417.             // set the owning side to null (unless already changed)
  418.             if ($Desafiador->getUser() === $this) {
  419.                 $Desafiador->setUser(null);
  420.             }
  421.         }
  422.         return $this;
  423.     }
  424.     /**
  425.      * @return Collection<int, UserPalavras>
  426.      */
  427.     public function getUserPalavras(): Collection
  428.     {
  429.         return $this->UserPalavras;
  430.     }
  431.     public function addUserPalavra(UserPalavras $userPalavra): self
  432.     {
  433.         if (!$this->UserPalavras->contains($userPalavra)) {
  434.             $this->UserPalavras->add($userPalavra);
  435.             $userPalavra->setUser($this);
  436.         }
  437.         return $this;
  438.     }
  439.     public function removeUserPalavra(UserPalavras $userPalavra): self
  440.     {
  441.         if ($this->UserPalavras->removeElement($userPalavra)) {
  442.             // set the owning side to null (unless already changed)
  443.             if ($userPalavra->getUser() === $this) {
  444.                 $userPalavra->setUser(null);
  445.             }
  446.         }
  447.         return $this;
  448.     }
  449.     
  450.     /**
  451.      * @return Collection<int, UserParametros>
  452.      */
  453.     public function getUserParametros(): Collection
  454.     {
  455.         return $this->UserParametros;
  456.     }
  457.     public function addUserParametros(UserParametros $userParametros): self
  458.     {
  459.         if (!$this->UserParametros->contains($userParametros)) {
  460.             $this->UserParametros->add($userParametros);
  461.             $userParametros->setUser($this);
  462.         }
  463.         return $this;
  464.     }
  465.     public function removeUserParametros(UserParametros $userParametros): self
  466.     {
  467.         if ($this->UserParametros->removeElement($userParametros)) {
  468.             // set the owning side to null (unless already changed)
  469.             if ($userParametros->getUser() === $this) {
  470.                 $userParametros->setUser(null);
  471.             }
  472.         }
  473.         return $this;
  474.     }
  475.     public function getLoginsocial(): ?int
  476.     {
  477.         return $this->loginsocial;
  478.     }
  479.     public function setLoginsocial(int $loginsocial): self
  480.     {
  481.         $this->loginsocial $loginsocial;
  482.         return $this;
  483.     }
  484.     public function getDeviceId(): ?string
  485.     {
  486.         return $this->deviceId;
  487.     }
  488.     public function setDeviceId(string $deviceId): self
  489.     {
  490.         $this->deviceId $deviceId;
  491.         return $this;
  492.     }
  493.     public function getPontos(): ?int
  494.     {
  495.         return $this->pontos;
  496.     }
  497.     public function setPontos(int $pontos): static
  498.     {
  499.         $this->pontos $pontos;
  500.         return $this;
  501.     }
  502.     public function getConfiguracoes(): ?array
  503.     {
  504.         return $this->configuracoes;
  505.     }
  506.     public function setConfiguracoes(?array $configuracoes): static
  507.     {
  508.         $this->configuracoes $configuracoes;
  509.         return $this;
  510.     }
  511.     public function getTokenPush(): ?string
  512.     {
  513.         return $this->tokenPush;
  514.     }
  515.     public function setTokenPush(string $tokenPush): static
  516.     {
  517.         $this->tokenPush $tokenPush;
  518.         return $this;
  519.     }
  520.     public function getTokenTipo(): ?string
  521.     {
  522.         return $this->tokenTipo;
  523.     }
  524.     public function setTokenTipo(string $tokenTipo): static
  525.     {
  526.         $this->tokenTipo $tokenTipo;
  527.         return $this;
  528.     }
  529.     public function getTentativaPush(): ?int
  530.     {
  531.         return $this->tentativaPush;
  532.     }
  533.     public function setTentativaPush(int $tentativaPush 0): static
  534.     {
  535.         $this->tentativaPush $tentativaPush;
  536.         return $this;
  537.     }
  538. }