src/Entity/User.php line 17

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\Validator\Constraints as Assert;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class User implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     const DEFAULT_ROLE 'ROLE_USER';
  17.     const ADMIN_ROLE 'ROLE_ADMIN';
  18.     const DELIVERY_ROLE 'ROLE_DELIVERY';
  19.     const ROLES = [
  20.         'Usuario' => self::DEFAULT_ROLE,
  21.         'Administrador' => self::ADMIN_ROLE,
  22.         'Domiciliario' => self::DELIVERY_ROLE,
  23.     ];
  24.     /**
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue
  27.      * @ORM\Column(type="integer")
  28.      */
  29.     private $id;
  30.     /**
  31.      * @ORM\Column(type="string", length=180)
  32.      * @Assert\NotNull
  33.      */
  34.     private $username;
  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.     //  * @var string The hashed password
  46.     //  * @Assert\Type("string")
  47.     //  * @Assert\NotBlank
  48.     //  */
  49.     // private $plainPassword;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      * @Assert\NotBlank
  53.      */
  54.     private $nombre;
  55.     /**
  56.      * @ORM\Column(type="integer")
  57.      */
  58.     private $codvendedor;
  59.     /**
  60.      * @ORM\OneToMany(targetEntity=Cabecera::class, mappedBy="user")
  61.      */
  62.     private $cabeceras;
  63.     /**
  64.      * @ORM\Column(type="boolean", nullable=true)
  65.      */
  66.     private $isEnabled;
  67.     /**
  68.      * @ORM\OneToMany(targetEntity=Domicilios::class, mappedBy="user")
  69.      */
  70.     private $domicilios;
  71.     public function __construct()
  72.     {
  73.         $this->cabeceras = new ArrayCollection();
  74.         $this->domicilios = new ArrayCollection();
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     /**
  81.      * A visual identifier that represents this user.
  82.      *
  83.      * @see UserInterface
  84.      */
  85.     public function getUserIdentifier(): string
  86.     {
  87.         return (string) $this->username;
  88.     }
  89.     public function __toString(): string
  90.     {
  91.         return $this->username;
  92.     }
  93.     /**
  94.      * A visual identifier that represents this user.
  95.      *
  96.      * @see UserInterface
  97.      */
  98.     public function getUsername(): string
  99.     {
  100.         return (string) $this->username;
  101.     }
  102.     public function setUsername(string $username): self
  103.     {
  104.         $this->username $username;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @see UserInterface
  109.      */
  110.     public function getRoles(): array
  111.     {
  112.         $roles $this->roles;
  113.         // guarantee every user at least has ROLE_USER
  114.         // $roles[] = 'ROLE_USER';
  115.         return array_unique($roles);
  116.     }
  117.     public function setRoles(array $roles): self
  118.     {
  119.         $this->roles $roles;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @see PasswordAuthenticatedUserInterface
  124.      */
  125.     public function getPassword(): string
  126.     {
  127.         return $this->password;
  128.     }
  129.     public function setPassword(string $password): self
  130.     {
  131.         $this->password $password;
  132.         return $this;
  133.     }
  134.     /**
  135.      * Returning a salt is only needed, if you are not using a modern
  136.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  137.      *
  138.      * @see UserInterface
  139.      */
  140.     public function getSalt(): ?string
  141.     {
  142.         return null;
  143.     }
  144.     /**
  145.      * @see UserInterface
  146.      */
  147.     public function eraseCredentials()
  148.     {
  149.         // If you store any temporary, sensitive data on the user, clear it here
  150.         // $this->plainPassword = null;
  151.     }
  152.     // /**
  153.     //  * Get the hashed password
  154.     //  *
  155.     //  * @return  string
  156.     //  */ 
  157.     // public function getPlainPassword()
  158.     // {
  159.     //     return $this->plainPassword;
  160.     // }
  161.     // /**
  162.     //  * Set the hashed password
  163.     //  *
  164.     //  * @param  string  $plainPassword  The hashed password
  165.     //  *
  166.     //  * @return  self
  167.     //  */ 
  168.     // public function setPlainPassword(string $plainPassword)
  169.     // {
  170.     //     $this->plainPassword = $plainPassword;
  171.     //     return $this;
  172.     // }
  173.     public function getNombre(): ?string
  174.     {
  175.         return $this->nombre;
  176.     }
  177.     public function setNombre(?string $nombre): self
  178.     {
  179.         $this->nombre $nombre;
  180.         return $this;
  181.     }
  182.     public function getCodvendedor(): ?int
  183.     {
  184.         return $this->codvendedor;
  185.     }
  186.     public function setCodvendedor(int $codvendedor): self
  187.     {
  188.         $this->codvendedor $codvendedor;
  189.         return $this;
  190.     }
  191.     /**
  192.      * @return Collection|Cabecera[]
  193.      */
  194.     public function getCabeceras(): Collection
  195.     {
  196.         return $this->cabeceras;
  197.     }
  198.     public function addCabecera(Cabecera $cabecera): self
  199.     {
  200.         if (!$this->cabeceras->contains($cabecera)) {
  201.             $this->cabeceras[] = $cabecera;
  202.             $cabecera->setUser($this);
  203.         }
  204.         return $this;
  205.     }
  206.     public function removeCabecera(Cabecera $cabecera): self
  207.     {
  208.         if ($this->cabeceras->removeElement($cabecera)) {
  209.             // set the owning side to null (unless already changed)
  210.             if ($cabecera->getUser() === $this) {
  211.                 $cabecera->setUser(null);
  212.             }
  213.         }
  214.         return $this;
  215.     }
  216.     public function getIsEnabled(): ?bool
  217.     {
  218.         return $this->isEnabled;
  219.     }
  220.     public function setIsEnabled(?bool $isEnabled): self
  221.     {
  222.         $this->isEnabled $isEnabled;
  223.         return $this;
  224.     }
  225.     /**
  226.      * @return Collection<int, Domicilios>
  227.      */
  228.     public function getDomicilios(): Collection
  229.     {
  230.         return $this->domicilios;
  231.     }
  232.     public function addDomicilio(Domicilios $domicilio): self
  233.     {
  234.         if (!$this->domicilios->contains($domicilio)) {
  235.             $this->domicilios[] = $domicilio;
  236.             $domicilio->setUser($this);
  237.         }
  238.         return $this;
  239.     }
  240.     public function removeDomicilio(Domicilios $domicilio): self
  241.     {
  242.         if ($this->domicilios->removeElement($domicilio)) {
  243.             // set the owning side to null (unless already changed)
  244.             if ($domicilio->getUser() === $this) {
  245.                 $domicilio->setUser(null);
  246.             }
  247.         }
  248.         return $this;
  249.     }
  250.     public function isIsEnabled(): ?bool
  251.     {
  252.         return $this->isEnabled;
  253.     }
  254. }