<?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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: false, nullable: true)]
private $email;
#[ORM\Column(type: 'string', length: 180, unique: false, nullable: true)]
private $phone;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\Column(type: 'string', nullable: true)]
private $locale;
#[ORM\OneToMany(mappedBy: 'seller', targetEntity: Sales::class)]
private $sales;
#[ORM\Column(type: 'string', length: 255)]
private $username;
#[ORM\Column(type: 'string', length: 255)]
private $fullname;
#[ORM\OneToMany(mappedBy: 'seller', targetEntity: Invoice::class)]
private Collection $invoices;
public function __construct()
{
$this->sales = new ArrayCollection();
$this->invoices = new ArrayCollection();
}
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;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): 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;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getLocale(): ?string
{
return $this->locale;
}
public function setLocale(?string $locale): self
{
$this->locale = $locale;
return $this;
}
/**
* @return Collection<int, Sales>
*/
public function getSales(): Collection
{
return $this->sales;
}
public function addSale(Sales $sale): self
{
if (!$this->sales->contains($sale)) {
$this->sales[] = $sale;
$sale->setSeller($this);
}
return $this;
}
public function removeSale(Sales $sale): self
{
if ($this->sales->removeElement($sale)) {
// set the owning side to null (unless already changed)
if ($sale->getSeller() === $this) {
$sale->setSeller(null);
}
}
return $this;
}
public function getUsername(): ?string
{
return $this->username;
}
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}
public function getFullname(): ?string
{
return $this->fullname;
}
public function setFullname(string $fullname): self
{
$this->fullname = $fullname;
return $this;
}
public function getInvoices(): Collection
{
return $this->invoices;
}
public function setInvoices(Collection $invoices): void
{
$this->invoices = $invoices;
}
public function addInvoice(Invoice $invoice):self
{
if (!$this->invoices->contains($invoice)) {
$this->invoices->add($invoice);
}
return $this;
}
public function removeInvoice(Invoice $invoice):self{
if($this->invoices->contains($invoice)){
$this->invoices->removeElement($invoice);
}
return $this;
}
/**
* @return mixed
*/
public function getPhone()
{
return $this->phone;
}
/**
* @param mixed $phone
*/
public function setPhone($phone): void
{
$this->phone = $phone;
}
}