src/Entity/User.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Almacen\AplicacionArticulo;
  4. use App\Repository\UserRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use App\Entity\Almacen\Deposito;
  12. use App\Entity\Mantenimiento\Departamento;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use App\Entity\Mantenimiento\SectorPlanta;
  15. /**
  16.  * @ORM\Entity(repositoryClass=UserRepository::class)
  17.  * @ORM\Table(name="users_system")
  18.  * @UniqueEntity(fields={"username"}, message="There is already an account with this username")
  19.  */
  20. class User implements UserInterfacePasswordAuthenticatedUserInterface
  21. {
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue
  25.      * @ORM\Column(type="integer")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=180, unique=true)
  30.      * @Assert\NotNull(message="El campo es requerido")
  31.      */
  32.     private $username;
  33.     /**
  34.      * @ORM\Column(type="json")
  35.      */
  36.     private $roles = [];
  37.     /**
  38.      * @var string The hashed password
  39.      * @ORM\Column(type="string")
  40.      */
  41.     private $password;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=Deposito::class)
  44.      * @ORM\JoinColumn(name="id_default", referencedColumnName="id", nullable=true)
  45.      */
  46.     private $default;
  47.     /**
  48.      * @ORM\ManyToMany(targetEntity=SectorPlanta::class)
  49.      * @ORM\JoinTable(name="users_sectores_system",
  50.      *      joinColumns={@ORM\JoinColumn(name="id_user", referencedColumnName="id")},
  51.      *      inverseJoinColumns={@ORM\JoinColumn(name="id_sector", referencedColumnName="id")}
  52.      *      )
  53.      */
  54.     private $sectores;
  55.     /**
  56.      * @ORM\ManyToMany(targetEntity=Departamento::class)
  57.      * @ORM\JoinTable(name="users_departamentos_system",
  58.      *      joinColumns={@ORM\JoinColumn(name="id_user", referencedColumnName="id")},
  59.      *      inverseJoinColumns={@ORM\JoinColumn(name="id_departamento", referencedColumnName="id")}
  60.      *      )
  61.      */
  62.     private $departamentos;
  63.     /**
  64.      * @ORM\ManyToMany(targetEntity=AplicacionArticulo::class)
  65.      * @ORM\JoinTable(name="gral_usuarios_aplicacion",
  66.      *      joinColumns={@ORM\JoinColumn(name="id_usuario", referencedColumnName="id")},
  67.      *      inverseJoinColumns={@ORM\JoinColumn(name="id_aplicacion", referencedColumnName="id")}
  68.      *      )
  69.      */
  70.     private $aplicaciones;
  71.     public function __construct()
  72.     {
  73.         $this->sectores = new ArrayCollection();
  74.         $this->departamentos = new ArrayCollection();
  75.         $this->aplicaciones = new ArrayCollection();
  76.     }
  77.     
  78.     public function getIdDefaultDeposito()
  79.     {
  80.         return $this->default $this->default->getId() : null ;
  81.     }
  82.     public function getId(): ?int
  83.     {
  84.         return $this->id;
  85.     }
  86.     /**
  87.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  88.      */
  89.     public function getUsername(): string
  90.     {
  91.         return (string) $this->username;
  92.     }
  93.     public function setUsername(?string $username): self
  94.     {
  95.         $this->username $username;
  96.         return $this;
  97.     }
  98.     /**
  99.      * A visual identifier that represents this user.
  100.      *
  101.      * @see UserInterface
  102.      */
  103.     public function getUserIdentifier(): string
  104.     {
  105.         return (string) $this->username;
  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.     public function getDefault(): ?Deposito
  153.     {
  154.         return $this->default;
  155.     }
  156.     public function setDefault(?Deposito $default): self
  157.     {
  158.         $this->default $default;
  159.         return $this;
  160.     }
  161.     /**
  162.      * @return Collection<int, SectorPlanta>
  163.      */
  164.     public function getSectores(): Collection
  165.     {
  166.         return $this->sectores;
  167.     }
  168.     public function addSectore(SectorPlanta $sectore): self
  169.     {
  170.         if (!$this->sectores->contains($sectore)) {
  171.             $this->sectores[] = $sectore;
  172.         }
  173.         return $this;
  174.     }
  175.     public function removeSectore(SectorPlanta $sectore): self
  176.     {
  177.         $this->sectores->removeElement($sectore);
  178.         return $this;
  179.     }
  180.     /**
  181.      * @return Collection<int, Departamento>
  182.      */
  183.     public function getDepartamentos(): Collection
  184.     {
  185.         return $this->departamentos;
  186.     }
  187.     public function addDepartamento(Departamento $departamento): self
  188.     {
  189.         if (!$this->departamentos->contains($departamento)) {
  190.             $this->departamentos[] = $departamento;
  191.         }
  192.         return $this;
  193.     }
  194.     public function removeDepartamento(Departamento $departamento): self
  195.     {
  196.         $this->departamentos->removeElement($departamento);
  197.         return $this;
  198.     }
  199.     /**
  200.      * @return Collection<int, AplicacionArticulo>
  201.      */
  202.     public function getAplicaciones(): Collection
  203.     {
  204.         return $this->aplicaciones;
  205.     }
  206.     public function addAplicacione(AplicacionArticulo $aplicacione): self
  207.     {
  208.         if (!$this->aplicaciones->contains($aplicacione)) {
  209.             $this->aplicaciones[] = $aplicacione;
  210.         }
  211.         return $this;
  212.     }
  213.     public function removeAplicacione(AplicacionArticulo $aplicacione): self
  214.     {
  215.         $this->aplicaciones->removeElement($aplicacione);
  216.         return $this;
  217.     }
  218. }