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.      * @ORM\OrderBy({"nombre" = "ASC"})
  54.      */
  55.     private $sectores;
  56.     /**
  57.      * @ORM\ManyToMany(targetEntity=Departamento::class)
  58.      * @ORM\JoinTable(name="users_departamentos_system",
  59.      *      joinColumns={@ORM\JoinColumn(name="id_user", referencedColumnName="id")},
  60.      *      inverseJoinColumns={@ORM\JoinColumn(name="id_departamento", referencedColumnName="id")}
  61.      *      )
  62.      */
  63.     private $departamentos;
  64.     /**
  65.      * @ORM\ManyToMany(targetEntity=AplicacionArticulo::class)
  66.      * @ORM\JoinTable(name="gral_usuarios_aplicacion",
  67.      *      joinColumns={@ORM\JoinColumn(name="id_usuario", referencedColumnName="id")},
  68.      *      inverseJoinColumns={@ORM\JoinColumn(name="id_aplicacion", referencedColumnName="id")}
  69.      *      )
  70.      */
  71.     private $aplicaciones;
  72.     public function __construct()
  73.     {
  74.         $this->sectores = new ArrayCollection();
  75.         $this->departamentos = new ArrayCollection();
  76.         $this->aplicaciones = new ArrayCollection();
  77.     }
  78.     public function getAllSectoresActivos()
  79.     {
  80.         $sectores = [];
  81.         foreach ($this->getSectores() as $sector) {
  82.             if ($sector->isActive()) 
  83.             {
  84.                 $sectores[] = $sector;
  85.             }
  86.         }
  87.         return $sectores;
  88.     }
  89.     
  90.     public function getAllDepartamentosActivos()
  91.     {
  92.         $departamentos = [];
  93.         foreach ($this->getDepartamentos() as $departamento) {
  94.             if ($departamento->isActivo()) 
  95.             {
  96.                 $departamentos[] = $departamento;
  97.             }
  98.         }
  99.         return $departamentos;
  100.     }
  101.     public function getIdDefaultDeposito()
  102.     {
  103.         return $this->default $this->default->getId() : null ;
  104.     }
  105.     public function getId(): ?int
  106.     {
  107.         return $this->id;
  108.     }
  109.     /**
  110.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  111.      */
  112.     public function getUsername(): string
  113.     {
  114.         return (string) $this->username;
  115.     }
  116.     public function setUsername(?string $username): self
  117.     {
  118.         $this->username $username;
  119.         return $this;
  120.     }
  121.     /**
  122.      * A visual identifier that represents this user.
  123.      *
  124.      * @see UserInterface
  125.      */
  126.     public function getUserIdentifier(): string
  127.     {
  128.         return (string) $this->username;
  129.     }
  130.     /**
  131.      * @see UserInterface
  132.      */
  133.     public function getRoles(): array
  134.     {
  135.         $roles $this->roles;
  136.         // guarantee every user at least has ROLE_USER
  137.         $roles[] = 'ROLE_USER';
  138.         return array_unique($roles);
  139.     }
  140.     public function setRoles(array $roles): self
  141.     {
  142.         $this->roles $roles;
  143.         return $this;
  144.     }
  145.     /**
  146.      * @see PasswordAuthenticatedUserInterface
  147.      */
  148.     public function getPassword(): string
  149.     {
  150.         return $this->password;
  151.     }
  152.     public function setPassword(string $password): self
  153.     {
  154.         $this->password $password;
  155.         return $this;
  156.     }
  157.     /**
  158.      * Returning a salt is only needed, if you are not using a modern
  159.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  160.      *
  161.      * @see UserInterface
  162.      */
  163.     public function getSalt(): ?string
  164.     {
  165.         return null;
  166.     }
  167.     /**
  168.      * @see UserInterface
  169.      */
  170.     public function eraseCredentials()
  171.     {
  172.         // If you store any temporary, sensitive data on the user, clear it here
  173.         // $this->plainPassword = null;
  174.     }
  175.     public function getDefault(): ?Deposito
  176.     {
  177.         return $this->default;
  178.     }
  179.     public function setDefault(?Deposito $default): self
  180.     {
  181.         $this->default $default;
  182.         return $this;
  183.     }
  184.     /**
  185.      * @return Collection<int, SectorPlanta>
  186.      */
  187.     public function getSectores(): Collection
  188.     {
  189.         return $this->sectores;
  190.     }
  191.     public function addSectore(SectorPlanta $sectore): self
  192.     {
  193.         if (!$this->sectores->contains($sectore)) {
  194.             $this->sectores[] = $sectore;
  195.         }
  196.         return $this;
  197.     }
  198.     public function removeSectore(SectorPlanta $sectore): self
  199.     {
  200.         $this->sectores->removeElement($sectore);
  201.         return $this;
  202.     }
  203.     /**
  204.      * @return Collection<int, Departamento>
  205.      */
  206.     public function getDepartamentos(): Collection
  207.     {
  208.         return $this->departamentos;
  209.     }
  210.     public function addDepartamento(Departamento $departamento): self
  211.     {
  212.         if (!$this->departamentos->contains($departamento)) {
  213.             $this->departamentos[] = $departamento;
  214.         }
  215.         return $this;
  216.     }
  217.     public function removeDepartamento(Departamento $departamento): self
  218.     {
  219.         $this->departamentos->removeElement($departamento);
  220.         return $this;
  221.     }
  222.     /**
  223.      * @return Collection<int, AplicacionArticulo>
  224.      */
  225.     public function getAplicaciones(): Collection
  226.     {
  227.         return $this->aplicaciones;
  228.     }
  229.     public function addAplicacione(AplicacionArticulo $aplicacione): self
  230.     {
  231.         if (!$this->aplicaciones->contains($aplicacione)) {
  232.             $this->aplicaciones[] = $aplicacione;
  233.         }
  234.         return $this;
  235.     }
  236.     public function removeAplicacione(AplicacionArticulo $aplicacione): self
  237.     {
  238.         $this->aplicaciones->removeElement($aplicacione);
  239.         return $this;
  240.     }
  241. }