<?php
namespace App\Entity;
use App\Repository\UidRepository;
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=UidRepository::class)
* @UniqueEntity(fields={"email"}, message="E-mail déjà lié à un compte")
*/
class Uid implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\OneToOne(targetEntity=Address::class, mappedBy="uid", cascade={"persist", "remove"})
*/
private $address;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="boolean")
*/
private $isActiv;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastname;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $connectedAt;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
*/
private $orders;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $signature;
/**
* @ORM\Column(type="string", length=14)
*/
private $phone;
/**
* @ORM\OneToOne(targetEntity=Cart::class, mappedBy="customer")
*/
private ?Cart $cart = null;
public function __construct()
{
$this->orders = new ArrayCollection();
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getEmail(): ?string
{
return $this->email;
}
/**
* @param string $email
*
* @return self
*/
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;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) "$this->firstname $this->lastname";
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
/**
* @param array $roles
*
* @return self
*/
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;
}
/**
* @return Address|null
*/
public function getAddress(): ?Address
{
return $this->address;
}
/**
* @param Address $address
*
* @return self
*/
public function setAddress(Address $address): self
{
// set the owning side of the relation if necessary
if ($address->getUid() !== $this) {
$address->setUid($this);
}
$this->address = $address;
return $this;
}
/**
* @return \DateTimeImmutable|null
*/
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
/**
* @param \DateTimeImmutable $createdAt
*
* @return self
*/
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return bool|null
*/
public function getIsActiv(): ?bool
{
return $this->isActiv;
}
/**
* @param bool $isActiv
*
* @return self
*/
public function setIsActiv(bool $isActiv): self
{
$this->isActiv = $isActiv;
return $this;
}
/**
* @return string|null
*/
public function getFirstname(): ?string
{
return $this->firstname;
}
/**
* @param string $firstname
*
* @return self
*/
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
/**
* @return string|null
*/
public function getLastname(): ?string
{
return $this->lastname;
}
/**
* @param string $lastname
*
* @return self
*/
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
/**
* @return \DateTimeImmutable|null
*/
public function getConnectedAt(): ?\DateTimeImmutable
{
return $this->connectedAt;
}
/**
* @param \DateTimeImmutable|null $connectedAt
*
* @return self
*/
public function setConnectedAt(?\DateTimeImmutable $connectedAt): self
{
$this->connectedAt = $connectedAt;
return $this;
}
public function __toString()
{
return $this->firstname . ' ' . $this->lastname;
}
/**
* @return bool|null
*/
public function isVerified(): bool
{
return $this->isVerified;
}
/**
* @param bool $isVerified
*
* @return self
*/
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* @return Collection|Order[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $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 getSignature(): ?string
{
return $this->signature;
}
public function setSignature(?string $signature): self
{
$this->signature = $signature;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getCart(): ?Cart
{
return $this->cart;
}
public function setCart(Cart $cart): self
{
// set the owning side of the relation if necessary
if ($cart->getCustomer() !== $this) {
$cart->setCustomer($this);
}
$this->cart = $cart;
return $this;
}
}