<?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)]
#[ORM\Table(name: '`user`')]
#[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 = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
#[ORM\Column]
private array $roles = [];
/**
* @var string The hashed password
*/
#[ORM\Column]
private ?string $password = null;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column(length: 255)]
private ?string $nom = null;
#[ORM\Column(length: 255)]
private ?string $phone = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $genre = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $ville = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $adresse = null;
#[ORM\Column]
private ?\DateTimeImmutable $created_at = null;
#[ORM\Column]
private ?bool $actif = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Boutiques::class)]
private Collection $boutiques;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?Boutiques $boutique = null;
#[ORM\OneToMany(mappedBy: 'recepteur', targetEntity: Notifications::class)]
private Collection $notifications;
#[ORM\OneToMany(mappedBy: 'auteur', targetEntity: Commandes::class)]
private Collection $commandes;
#[ORM\Column(length: 255, nullable: true)]
private ?string $clear = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Article::class, orphanRemoval: true)]
private Collection $articles;
public function __construct()
{
$this->boutiques = new ArrayCollection();
$this->notifications = new ArrayCollection();
$this->commandes = new ArrayCollection();
$this->articles = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): static
{
$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): static
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): static
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): static
{
$this->isVerified = $isVerified;
return $this;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): static
{
$this->nom = $nom;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(string $phone): static
{
$this->phone = $phone;
return $this;
}
public function getGenre(): ?string
{
return $this->genre;
}
public function setGenre(?string $genre): static
{
$this->genre = $genre;
return $this;
}
public function getVille(): ?string
{
return $this->ville;
}
public function setVille(?string $ville): static
{
$this->ville = $ville;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): static
{
$this->adresse = $adresse;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): static
{
$this->created_at = $created_at;
return $this;
}
public function isActif(): ?bool
{
return $this->actif;
}
public function setActif(bool $actif): static
{
$this->actif = $actif;
return $this;
}
/**
* @return Collection<int, Boutiques>
*/
public function getBoutiques(): Collection
{
return $this->boutiques;
}
public function addBoutique(Boutiques $boutique): static
{
if (!$this->boutiques->contains($boutique)) {
$this->boutiques->add($boutique);
$boutique->setUser($this);
}
return $this;
}
public function removeBoutique(Boutiques $boutique): static
{
if ($this->boutiques->removeElement($boutique)) {
// set the owning side to null (unless already changed)
if ($boutique->getUser() === $this) {
$boutique->setUser(null);
}
}
return $this;
}
public function getBoutique(): ?Boutiques
{
return $this->boutique;
}
public function setBoutique(?Boutiques $boutique): static
{
$this->boutique = $boutique;
return $this;
}
/**
* @return Collection<int, Notifications>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notifications $notification): static
{
if (!$this->notifications->contains($notification)) {
$this->notifications->add($notification);
$notification->setRecepteur($this);
}
return $this;
}
public function removeNotification(Notifications $notification): static
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getRecepteur() === $this) {
$notification->setRecepteur(null);
}
}
return $this;
}
/**
* @return Collection<int, Commandes>
*/
public function getCommandes(): Collection
{
return $this->commandes;
}
public function addCommande(Commandes $commande): static
{
if (!$this->commandes->contains($commande)) {
$this->commandes->add($commande);
$commande->setAuteur($this);
}
return $this;
}
public function removeCommande(Commandes $commande): static
{
if ($this->commandes->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getAuteur() === $this) {
$commande->setAuteur(null);
}
}
return $this;
}
public function getClear(): ?string
{
return $this->clear;
}
public function setClear(?string $clear): static
{
$this->clear = $clear;
return $this;
}
/**
* @return Collection<int, Article>
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): static
{
if (!$this->articles->contains($article)) {
$this->articles->add($article);
$article->setUser($this);
}
return $this;
}
public function removeArticle(Article $article): static
{
if ($this->articles->removeElement($article)) {
// set the owning side to null (unless already changed)
if ($article->getUser() === $this) {
$article->setUser(null);
}
}
return $this;
}
}