<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraints as Assert;
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]
private int $id;
#[ORM\Column(length: 180, unique: true)]
#[Assert\NotBlank]
#[Assert\Email]
private string $email;
#[ORM\Column]
private array $roles = ['User'];
#[ORM\Column]
private string $password;
#[ORM\Column(length: 255)]
#[Assert\NotBlank]
private string $firstname;
#[ORM\Column(length: 255)]
#[Assert\NotBlank]
private string $lastname;
#[ORM\Column(length: 255)]
#[Assert\NotBlank]
private string $city;
#[ORM\Column(length: 255)]
#[Assert\NotBlank]
private string $street;
#[ORM\Column(length: 255, nullable: true)]
private ?string $street2 = null;
#[ORM\Column(length: 255)]
#[Assert\NotBlank]
private string $country;
#[ORM\Column(length: 255)]
#[Assert\NotBlank]
private string $zipcode;
#[ORM\OneToMany(mappedBy: 'userId', targetEntity: Order::class)]
private Collection $orders;
#[ORM\Column]
private bool $terms;
#[ORM\Column(length: 255, nullable: true)]
private ?string $ip = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $token = null;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column(length: 255)]
private ?string $phone = null;
public function __construct()
{
$this->orders = 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 getFirstname(): string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getCity(): string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = $city;
return $this;
}
public function getStreet(): string
{
return $this->street;
}
public function setStreet(string $street): self
{
$this->street = $street;
return $this;
}
public function getStreet2(): ?string
{
return $this->street2;
}
public function setStreet2(?string $street2): self
{
$this->street2 = $street2;
return $this;
}
public function getCountry(): string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
public function getZipcode(): string
{
return $this->zipcode;
}
public function setZipcode(string $zipcode): self
{
$this->zipcode = $zipcode;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setUser($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getUser() === $this) {
$order->setUser(null);
}
}
return $this;
}
public function isTerms(): ?bool
{
return $this->terms;
}
public function setTerms(bool $terms): self
{
$this->terms = $terms;
return $this;
}
public function isVerified(): ?bool
{
return $this->isVerified;
}
public function getIp(): ?string
{
return $this->ip;
}
public function setIp(?string $ip): self
{
$this->ip = $ip;
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(?string $token): self
{
$this->token = $token;
return $this;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getPhone(): string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
}