<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\HasLifecycleCallbacks()
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const DEFAULT_ROLE = 'ROLE_USER';
const ADMIN_ROLE = 'ROLE_ADMIN';
const DELIVERY_ROLE = 'ROLE_DELIVERY';
const ROLES = [
'Usuario' => self::DEFAULT_ROLE,
'Administrador' => self::ADMIN_ROLE,
'Domiciliario' => self::DELIVERY_ROLE,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180)
* @Assert\NotNull
*/
private $username;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
// /**
// * @var string The hashed password
// * @Assert\Type("string")
// * @Assert\NotBlank
// */
// private $plainPassword;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\NotBlank
*/
private $nombre;
/**
* @ORM\Column(type="integer")
*/
private $codvendedor;
/**
* @ORM\OneToMany(targetEntity=Cabecera::class, mappedBy="user")
*/
private $cabeceras;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isEnabled;
/**
* @ORM\OneToMany(targetEntity=Domicilios::class, mappedBy="user")
*/
private $domicilios;
public function __construct()
{
$this->cabeceras = new ArrayCollection();
$this->domicilios = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->username;
}
public function __toString(): string
{
return $this->username;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return (string) $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
/**
* @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;
}
// /**
// * Get the hashed password
// *
// * @return string
// */
// public function getPlainPassword()
// {
// return $this->plainPassword;
// }
// /**
// * Set the hashed password
// *
// * @param string $plainPassword The hashed password
// *
// * @return self
// */
// public function setPlainPassword(string $plainPassword)
// {
// $this->plainPassword = $plainPassword;
// return $this;
// }
public function getNombre(): ?string
{
return $this->nombre;
}
public function setNombre(?string $nombre): self
{
$this->nombre = $nombre;
return $this;
}
public function getCodvendedor(): ?int
{
return $this->codvendedor;
}
public function setCodvendedor(int $codvendedor): self
{
$this->codvendedor = $codvendedor;
return $this;
}
/**
* @return Collection|Cabecera[]
*/
public function getCabeceras(): Collection
{
return $this->cabeceras;
}
public function addCabecera(Cabecera $cabecera): self
{
if (!$this->cabeceras->contains($cabecera)) {
$this->cabeceras[] = $cabecera;
$cabecera->setUser($this);
}
return $this;
}
public function removeCabecera(Cabecera $cabecera): self
{
if ($this->cabeceras->removeElement($cabecera)) {
// set the owning side to null (unless already changed)
if ($cabecera->getUser() === $this) {
$cabecera->setUser(null);
}
}
return $this;
}
public function getIsEnabled(): ?bool
{
return $this->isEnabled;
}
public function setIsEnabled(?bool $isEnabled): self
{
$this->isEnabled = $isEnabled;
return $this;
}
/**
* @return Collection<int, Domicilios>
*/
public function getDomicilios(): Collection
{
return $this->domicilios;
}
public function addDomicilio(Domicilios $domicilio): self
{
if (!$this->domicilios->contains($domicilio)) {
$this->domicilios[] = $domicilio;
$domicilio->setUser($this);
}
return $this;
}
public function removeDomicilio(Domicilios $domicilio): self
{
if ($this->domicilios->removeElement($domicilio)) {
// set the owning side to null (unless already changed)
if ($domicilio->getUser() === $this) {
$domicilio->setUser(null);
}
}
return $this;
}
public function isIsEnabled(): ?bool
{
return $this->isEnabled;
}
}