<?php
namespace App\Entity;
use App\Repository\UserClientRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserClientRepository::class)
* @UniqueEntity(fields={"email"}, message="Correo electrónico registrado anteriormente")
* @UniqueEntity(fields={"document"}, message="Número de documento registrado anteriormente")
*/
class UserClient extends BaseEntity implements UserInterface, PasswordAuthenticatedUserInterface
{
const USER_TYPE_CLIENT = 'user';
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\Length(max="180")
* @Assert\NotBlank()
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="text", nullable=true)
*/
private $name;
/**
* @ORM\Column(type="string", length=15, nullable=true, unique=true)
* @Assert\Length(max="15")
*/
private $document;
/**
* @ORM\Column(type="string", length=15, nullable=true)
* @Assert\Length(max="15")
*/
private $phone;
/**
* @ORM\Column(type="string", length=100, nullable=true)
* @Assert\Length(max="100")
*/
private $type;
/**
* @ORM\Column(type="string", nullable=true)
* @Assert\Length(max="255")
*/
private $address;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $next_play_on;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\OneToMany(targetEntity="RequestService", mappedBy="client")
*/
private $request_services;
/**
* @ORM\OneToMany(targetEntity="RequestSparePart", mappedBy="client")
*/
private $request_spare_parts;
/**
* UserClient constructor.
*/
public function __construct()
{
parent::__construct();
$this->request_services = new ArrayCollection();
$this->request_spare_parts = new ArrayCollection();
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @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 getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getDocument(): ?string
{
return $this->document;
}
public function setDocument(?string $document): self
{
$this->document = $document;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): self
{
$this->address = $address;
return $this;
}
public function getNextPlayOn(): ?\DateTimeInterface
{
return $this->next_play_on;
}
public function setNextPlayOn(?\DateTimeInterface $next_play_on): self
{
$this->next_play_on = $next_play_on;
return $this;
}
/**
* @return Collection<int, RequestService>
*/
public function getRequestServices(): Collection
{
return $this->request_services;
}
public function addRequestService(RequestService $requestService): self
{
if (!$this->request_services->contains($requestService)) {
$this->request_services[] = $requestService;
$requestService->setClient($this);
}
return $this;
}
public function removeRequestService(RequestService $requestService): self
{
if ($this->request_services->removeElement($requestService)) {
// set the owning side to null (unless already changed)
if ($requestService->getClient() === $this) {
$requestService->setClient(null);
}
}
return $this;
}
/**
* @return Collection<int, RequestSparePart>
*/
public function getRequestSpareParts(): Collection
{
return $this->request_spare_parts;
}
public function addRequestSparePart(RequestSparePart $requestSparePart): self
{
if (!$this->request_spare_parts->contains($requestSparePart)) {
$this->request_spare_parts[] = $requestSparePart;
$requestSparePart->setClient($this);
}
return $this;
}
public function removeRequestSparePart(RequestSparePart $requestSparePart): self
{
if ($this->request_spare_parts->removeElement($requestSparePart)) {
// set the owning side to null (unless already changed)
if ($requestSparePart->getClient() === $this) {
$requestSparePart->setClient(null);
}
}
return $this;
}
}