<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
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;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="`user`")
* @UniqueEntity(fields={"telephone"}, message="There is already an account with this telephone")
* @ApiResource(
* normalizationContext={"groups"={"user:read"}},
* denormalizationContext={"groups"={"user:write"}}
* )
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"user:read"})
* @Groups({"commandes:read","produit:read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Groups({"user:read","commandes:read","produit:read","user:write"})
*/
private $telephone;
/**
* @ORM\Column(type="json")
* @Groups({"user:read","commandes:read","produit:read"})
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*
*/
private $password;
/**
* @Groups("user:write")
* @SerializedName("password")
*/
protected $plainPassword;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"user:read","commandes:read","produit:read","user:write"})
*/
private $nom;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"user:read","commandes:read","produit:read","user:write"})
*/
private $prenoms;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"user:read","commandes:read","produit:read","user:write"})
*/
private $email;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"user:read","commandes:read","produit:read","user:write"})
*/
private $sexe;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"user:read","produit:read","user:write"})
*/
private $adresse;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"user:read","commandes:read","produit:read","user:write"})
*/
private $secteurActivite;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"user:read","commandes:read","produit:read","user:write"})
*/
private $terminal;
/**
* @ORM\OneToMany(targetEntity=Produits::class, mappedBy="utilisateur")
* @Groups({"user:read"})
*/
private $produits;
/**
* @ORM\OneToMany(targetEntity=Commandes::class, mappedBy="client")
*
*/
private $commandes;
/**
* @ORM\OneToMany(targetEntity=AdresseLivraison::class, mappedBy="client")
*
*/
private $adresseLivraisons;
/**
* @ORM\Column(type="boolean")
* @Groups({"user:read"})
*/
private $isVerified = false;
/**
* @ORM\OneToMany(targetEntity=ApiToken::class, mappedBy="utilisateur")
*
*/
private $fcm_tokens;
/**
* @ORM\ManyToOne(targetEntity=Quartier::class, inversedBy="user")
* @Groups({"user:read","user:write"})
*
*/
private $localite;
/**
* @Groups("user:read","user:write")
*
*
*/
protected $localites;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"user:read"})
*/
private $fcm_token;
/**
* @ORM\OneToMany(targetEntity=FavorisProduits::class, mappedBy="utilisateurs")
* @Groups({"user:read","favoris:read"})
*/
private $favoris;
public function __construct()
{
$this->produits = new ArrayCollection();
$this->commandes = new ArrayCollection();
$this->adresseLivraisons = new ArrayCollection();
$this->fcm_tokens = new ArrayCollection();
$this->favoris = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTelephone(): ?string
{
return $this->telephone;
}
public function setTelephone(string $telephone): self
{
$this->telephone = $telephone;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string)$this->nom;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string)$this->telephone;
}
/**
* @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 getNom(): ?string
{
return $this->nom;
}
public function setNom(?string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getPrenoms(): ?string
{
return $this->prenoms;
}
public function setPrenoms(?string $prenoms): self
{
$this->prenoms = $prenoms;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getSexe(): ?string
{
return $this->sexe;
}
public function setSexe(?string $sexe): self
{
$this->sexe = $sexe;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getSecteurActivite(): ?string
{
return $this->secteurActivite;
}
public function setSecteurActivite(?string $secteurActivite): self
{
$this->secteurActivite = $secteurActivite;
return $this;
}
public function getTerminal(): ?string
{
return $this->terminal;
}
public function setTerminal(?string $terminal): self
{
$this->terminal = $terminal;
return $this;
}
/**
* @return Collection<int, Produits>
*/
public function getProduits(): Collection
{
return $this->produits;
}
public function addProduit(Produits $produit): self
{
if (!$this->produits->contains($produit)) {
$this->produits[] = $produit;
$produit->setUtilisateur($this);
}
return $this;
}
public function removeProduit(Produits $produit): self
{
if ($this->produits->removeElement($produit)) {
// set the owning side to null (unless already changed)
if ($produit->getUtilisateur() === $this) {
$produit->setUtilisateur(null);
}
}
return $this;
}
/**
* @return Collection<int, Commandes>
*/
public function getCommandes(): Collection
{
return $this->commandes;
}
public function addCommande(Commandes $commande): self
{
if (!$this->commandes->contains($commande)) {
$this->commandes[] = $commande;
$commande->setClient($this);
}
return $this;
}
public function removeCommande(Commandes $commande): self
{
if ($this->commandes->removeElement($commande)) {
// set the owning side to null (unless already changed)
if ($commande->getClient() === $this) {
$commande->setClient(null);
}
}
return $this;
}
/**
* @return Collection<int, AdresseLivraison>
*/
public function getAdresseLivraisons(): Collection
{
return $this->adresseLivraisons;
}
public function addAdresseLivraison(AdresseLivraison $adresseLivraison): self
{
if (!$this->adresseLivraisons->contains($adresseLivraison)) {
$this->adresseLivraisons[] = $adresseLivraison;
$adresseLivraison->setClient($this);
}
return $this;
}
public function removeAdresseLivraison(AdresseLivraison $adresseLivraison): self
{
if ($this->adresseLivraisons->removeElement($adresseLivraison)) {
// set the owning side to null (unless already changed)
if ($adresseLivraison->getClient() === $this) {
$adresseLivraison->setClient(null);
}
}
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
/**
* @return Collection<int, ApiToken>
*/
public function getFcmTokens(): Collection
{
return $this->fcm_tokens;
}
public function addFcmTokens(ApiToken $fcmTokens): self
{
if (!$this->fcm_tokens->contains($fcmTokens)) {
$this->fcm_tokens[] = $fcmTokens;
$fcmTokens->setUtilisateur($this);
}
return $this;
}
public function removeFcmTokens(ApiToken $fcmTokens): self
{
if ($this->fcm_token->removeElement($fcmTokens)) {
// set the owning side to null (unless already changed)
if ($fcmTokens->getUtilisateur() === $this) {
$fcmTokens->setUtilisateur(null);
}
}
return $this;
}
/**
* @return mixed
*/
public function getPlainPassword()
{
return $this->plainPassword;
}
/**
* @param mixed $plainPassword
*/
public function setPlainPassword($plainPassword): void
{
$this->plainPassword = $plainPassword;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
public function getLocalite()
{
return $this->localite;
}
// /**
// * @Groups({"user:read"})
// */
// public function getLocalites():?Quartier
// {
//
// return $this->localite;
// }
public function setLocalite(?Quartier $localite): self
{
$this->localite = $localite;
return $this;
}
public function getFcmToken(): ?string
{
return $this->fcm_token;
}
public function setFcmToken(?string $fcm_token): self
{
$this->fcm_token = $fcm_token;
return $this;
}
/**
* @return Collection<int, FavorisProduits>
*/
public function getFavoris(): Collection
{
return $this->favoris;
}
public function addFavori(FavorisProduits $favori): self
{
if (!$this->favoris->contains($favori)) {
$this->favoris[] = $favori;
$favori->setUtilisateurs($this);
}
return $this;
}
public function removeFavori(FavorisProduits $favori): self
{
if ($this->favoris->removeElement($favori)) {
// set the owning side to null (unless already changed)
if ($favori->getUtilisateurs() === $this) {
$favori->setUtilisateurs(null);
}
}
return $this;
}
}