<?php
namespace App\Entity;
use App\Entity\Almacen\AplicacionArticulo;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use App\Entity\Almacen\Deposito;
use App\Entity\Mantenimiento\Departamento;
use Symfony\Component\Validator\Constraints as Assert;
use App\Entity\Mantenimiento\SectorPlanta;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="users_system")
* @UniqueEntity(fields={"username"}, message="There is already an account with this username")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\NotNull(message="El campo es requerido")
*/
private $username;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\ManyToOne(targetEntity=Deposito::class)
* @ORM\JoinColumn(name="id_default", referencedColumnName="id", nullable=true)
*/
private $default;
/**
* @ORM\ManyToMany(targetEntity=SectorPlanta::class)
* @ORM\JoinTable(name="users_sectores_system",
* joinColumns={@ORM\JoinColumn(name="id_user", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="id_sector", referencedColumnName="id")}
* )
*/
private $sectores;
/**
* @ORM\ManyToMany(targetEntity=Departamento::class)
* @ORM\JoinTable(name="users_departamentos_system",
* joinColumns={@ORM\JoinColumn(name="id_user", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="id_departamento", referencedColumnName="id")}
* )
*/
private $departamentos;
/**
* @ORM\ManyToMany(targetEntity=AplicacionArticulo::class)
* @ORM\JoinTable(name="gral_usuarios_aplicacion",
* joinColumns={@ORM\JoinColumn(name="id_usuario", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="id_aplicacion", referencedColumnName="id")}
* )
*/
private $aplicaciones;
public function __construct()
{
$this->sectores = new ArrayCollection();
$this->departamentos = new ArrayCollection();
$this->aplicaciones = new ArrayCollection();
}
public function getIdDefaultDeposito()
{
return $this->default ? $this->default->getId() : null ;
}
public function getId(): ?int
{
return $this->id;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->username;
}
public function setUsername(?string $username): self
{
$this->username = $username;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getDefault(): ?Deposito
{
return $this->default;
}
public function setDefault(?Deposito $default): self
{
$this->default = $default;
return $this;
}
/**
* @return Collection<int, SectorPlanta>
*/
public function getSectores(): Collection
{
return $this->sectores;
}
public function addSectore(SectorPlanta $sectore): self
{
if (!$this->sectores->contains($sectore)) {
$this->sectores[] = $sectore;
}
return $this;
}
public function removeSectore(SectorPlanta $sectore): self
{
$this->sectores->removeElement($sectore);
return $this;
}
/**
* @return Collection<int, Departamento>
*/
public function getDepartamentos(): Collection
{
return $this->departamentos;
}
public function addDepartamento(Departamento $departamento): self
{
if (!$this->departamentos->contains($departamento)) {
$this->departamentos[] = $departamento;
}
return $this;
}
public function removeDepartamento(Departamento $departamento): self
{
$this->departamentos->removeElement($departamento);
return $this;
}
/**
* @return Collection<int, AplicacionArticulo>
*/
public function getAplicaciones(): Collection
{
return $this->aplicaciones;
}
public function addAplicacione(AplicacionArticulo $aplicacione): self
{
if (!$this->aplicaciones->contains($aplicacione)) {
$this->aplicaciones[] = $aplicacione;
}
return $this;
}
public function removeAplicacione(AplicacionArticulo $aplicacione): self
{
$this->aplicaciones->removeElement($aplicacione);
return $this;
}
}