src/Entity/User.php line 13

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 Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. #[ORM\Entity(repositoryClassUserRepository::class)]
  10. class User implements UserInterfacePasswordAuthenticatedUserInterface
  11. {
  12.     const REGISTRO_EXITOSO 'Se ha registrado correctamente';
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length180uniquetrue)]
  18.     private ?string $email null;
  19.     #[ORM\Column]
  20.     private array $roles = [];
  21.     /**
  22.      * @var string The hashed password
  23.      */
  24.     #[ORM\Column]
  25.     private ?string $password null;
  26.     #[ORM\Column]
  27.     private ?bool $baneado false;
  28.     #[ORM\Column(length255)]
  29.     private ?string $nombre null;
  30.     #[ORM\OneToMany(mappedBy'user'targetEntityComentarios::class, orphanRemovaltrue)]
  31.     private Collection $comentarios;
  32.     #[ORM\OneToMany(mappedBy'user'targetEntityPosts::class, orphanRemovaltrue)]
  33.     private Collection $posts;
  34.     #[ORM\OneToMany(mappedBy'user'targetEntityProfesion::class, orphanRemovaltrue)]
  35.     private Collection $profesion;
  36.     public function __construct()
  37.     {
  38.     $this->baneado false;
  39.     $this->roles = ['ROLE_USER'];
  40.         $this->comentarios = new ArrayCollection();
  41.         $this->posts = new ArrayCollection();
  42.         $this->profesion = new ArrayCollection();
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getEmail(): ?string
  49.     {
  50.         return $this->email;
  51.     }
  52.     public function setEmail(string $email): static
  53.     {
  54.         $this->email $email;
  55.         return $this;
  56.     }
  57.     /**
  58.      * A visual identifier that represents this user.
  59.      *
  60.      * @see UserInterface
  61.      */
  62.     public function getUserIdentifier(): string
  63.     {
  64.         return (string) $this->email;
  65.     }
  66.     /**
  67.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  68.      */
  69.     public function getUsername(): string
  70.     {
  71.         return (string) $this->email;
  72.     }
  73.     /**
  74.      * @see UserInterface
  75.      */
  76.     public function getRoles(): array
  77.     {
  78.         $roles $this->roles;
  79.         // guarantee every user at least has ROLE_USER
  80.         $roles[] = 'ROLE_USER';
  81.         return array_unique($roles);
  82.     }
  83.     public function setRoles(array $roles): static
  84.     {
  85.         $this->roles $roles;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @see PasswordAuthenticatedUserInterface
  90.      */
  91.     public function getPassword(): string
  92.     {
  93.         return $this->password;
  94.     }
  95.     public function setPassword(string $password): static
  96.     {
  97.         $this->password $password;
  98.         return $this;
  99.     }
  100.     /**
  101.      * Returning a salt is only needed, if you are not using a modern
  102.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  103.      *
  104.      * @see UserInterface
  105.      */
  106.     public function getSalt(): ?string
  107.     {
  108.         return null;
  109.     }
  110.     /**
  111.      * @see UserInterface
  112.      */
  113.     public function eraseCredentials(): void
  114.     {
  115.         // If you store any temporary, sensitive data on the user, clear it here
  116.         // $this->plainPassword = null;
  117.     }
  118.     public function getNombre(): ?string
  119.     {
  120.         return $this->nombre;
  121.     }
  122.     public function setBaneado(bool $baneado): static
  123.     {
  124.         $this->baneado $baneado;
  125.         return $this;
  126.     }
  127.     public function getBaneado(): ?bool
  128.     {
  129.         return $this->baneado;
  130.     }
  131.     public function setNombre(string $nombre): static
  132.     {
  133.         $this->nombre $nombre;
  134.         return $this;
  135.     }
  136.     /**
  137.      * @return Collection<int, Comentarios>
  138.      */
  139.     public function getComentarios(): Collection
  140.     {
  141.         return $this->comentarios;
  142.     }
  143.     public function addComentario(Comentarios $comentario): static
  144.     {
  145.         if (!$this->comentarios->contains($comentario)) {
  146.             $this->comentarios->add($comentario);
  147.             $comentario->setUserId($this);
  148.         }
  149.         return $this;
  150.     }
  151.     public function removeComentario(Comentarios $comentario): static
  152.     {
  153.         if ($this->comentarios->removeElement($comentario)) {
  154.             // set the owning side to null (unless already changed)
  155.             if ($comentario->getUserId() === $this) {
  156.                 $comentario->setUserId(null);
  157.             }
  158.         }
  159.         return $this;
  160.     }
  161.     /**
  162.      * @return Collection<int, Posts>
  163.      */
  164.     public function getPosts(): Collection
  165.     {
  166.         return $this->posts;
  167.     }
  168.     public function addPost(Posts $post): static
  169.     {
  170.         if (!$this->posts->contains($post)) {
  171.             $this->posts->add($post);
  172.             $post->setUser($this);
  173.         }
  174.         return $this;
  175.     }
  176.     public function removePost(Posts $post): static
  177.     {
  178.         if ($this->posts->removeElement($post)) {
  179.             // set the owning side to null (unless already changed)
  180.             if ($post->getUser() === $this) {
  181.                 $post->setUser(null);
  182.             }
  183.         }
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return Collection<int, Profesion>
  188.      */
  189.     public function getProfesion(): Collection
  190.     {
  191.         return $this->profesion;
  192.     }
  193.     public function addProfesion(Profesion $profesion): static
  194.     {
  195.         if (!$this->profesion->contains($profesion)) {
  196.             $this->profesion->add($profesion);
  197.             $profesion->setUser($this);
  198.         }
  199.         return $this;
  200.     }
  201.     public function removeProfesion(Profesion $profesion): static
  202.     {
  203.         if ($this->profesion->removeElement($profesion)) {
  204.             // set the owning side to null (unless already changed)
  205.             if ($profesion->getUser() === $this) {
  206.                 $profesion->setUser(null);
  207.             }
  208.         }
  209.         return $this;
  210.     }
  211. }