<?php
namespace App\Entity;
use ApiPlatform\Core\Action\NotFoundAction;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\MeController;
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\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
#[ApiResource(
collectionOperations:[
'me'=>[
'pagination_enabled'=>false,
'path'=>'/me',
'method'=>'get',
'controller'=>MeController::class,
'read'=>false
]
],
itemOperations:[
'get'=>[
'controller'=>NotFoundAction::class,
'openapi_context'=>['summary'=>'hidden'],
'read'=>false,
'output'=>false
]
],
normalizationContext:['groups'=>['read:User']]
)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const roles=[
// 'Administrateur'=>'ROLE_ADMIN',
'Gérant'=>'ROLE_EDITOR',
// 'Client'=>'ROLE_CLIENT',
// 'Utilisateur'=>'ROLE_USER'
];
const status=[
'Activer'=>'Activer',
'Désactiver'=>'Désactiver',
'Delete'=>'Delete'
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
#[Groups(['read:User'])]
private $id;
/**
* @Assert\NotBlank()
* @ORM\Column(type="string", length=180, unique=true)
*/
#[Groups(['read:User'])]
private $email;
/**
* @Assert\NotBlank()
* @ORM\Column(type="json")
*/
#[Groups(['read:User'])]
private $roles = [];
/**
* @var string The hashed password
* @Assert\NotNull()
* @Assert\NotBlank()
* @ORM\Column(type="string")
*/
private $password;
/**
* password_verify
* @Assert\EqualTo(propertyPath="password", message="Le Mot de passe ne correspond pas")
* @var mixed
*/
private $password_verify;
/**
* @ORM\OneToMany(targetEntity=Comment::class, mappedBy="user", orphanRemoval=true)
*/
private $comments;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="user", orphanRemoval=true)
*/
private $orders;
/**
* @Assert\Valid
* @ORM\OneToOne(targetEntity=Client::class, mappedBy="user", cascade={"persist", "remove"})
*/
private $client;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\ManyToMany(targetEntity=Article::class, mappedBy="favori")
*/
private $favoris;
/**
* @ORM\OneToOne(targetEntity=DeliverySpace::class, inversedBy="user", cascade={"persist", "remove"})
*/
private $delivery_space;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $username;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank()
* @Assert\NotNull()
*/
private $phone_number;
/**
*
* @ORM\OneToMany(targetEntity=Phone::class, mappedBy="user")
*/
private $phones;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $last_login_at;
/**
* @ORM\Column(type="boolean")
*/
private $is_active = true;
/**
* @Assert\Valid
* @ORM\OneToOne(targetEntity=Adresse::class, inversedBy="user", cascade={"persist", "remove"})
*/
private $adresse;
/**
* @ORM\Column(type="string", length=255)
*/
private $cle;
/**
* @ORM\Column(type="string", length=255)
*/
private $status;
/**
* @ORM\Column(type="boolean")
*/
private $is_verified;
/**
* @ORM\Column(type="string", length=255)
*/
private $first_name;
/**
* @ORM\Column(type="string", length=255)
*/
private $last_name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $api_key;
public function __construct()
{
$this->comments = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->created_at = new \DateTime();
$this->favoris = new ArrayCollection();
$this->phones = new ArrayCollection();
$this->status = 'Activer';
$this->is_verified = false;
}
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;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): 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;
}
/**
* 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 Collection|Comment[]
*/
public function getComments(): Collection
{
return $this->comments;
}
public function addComment(Comment $comment): self
{
if (!$this->comments->contains($comment)) {
$this->comments[] = $comment;
$comment->setUser($this);
}
return $this;
}
public function removeComment(Comment $comment): self
{
if ($this->comments->removeElement($comment)) {
// set the owning side to null (unless already changed)
if ($comment->getUser() === $this) {
$comment->setUser(null);
}
}
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 getClient(): ?Client
{
return $this->client;
}
public function setClient(Client $client): self
{
// set the owning side of the relation if necessary
if ($client->getUser() !== $this) {
$client->setUser($this);
}
$this->client = $client;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
/**
* @return Collection|Article[]
*/
public function getFavoris(): Collection
{
return $this->favoris;
}
public function addFavori(Article $favori): self
{
if (!$this->favoris->contains($favori)) {
$this->favoris[] = $favori;
$favori->addFavori($this);
}
return $this;
}
public function removeFavori(Article $favori): self
{
if ($this->favoris->removeElement($favori)) {
$favori->removeFavori($this);
}
return $this;
}
public function getDeliverySpace(): ?DeliverySpace
{
return $this->delivery_space;
}
public function setDeliverySpace(?DeliverySpace $delivery_space): self
{
$this->delivery_space = $delivery_space;
return $this;
}
public function setUsername(?string $username): self
{
$this->username = $username;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phone_number;
}
public function setPhoneNumber(string $phone_number): self
{
$this->phone_number = $phone_number;
return $this;
}
/**
* Get the value of password_verify
*/
public function getPasswordVerify()
{
return $this->password_verify;
}
/**
* Set the value of password_verify
*
* @return self
*/
public function setPasswordVerify($password_verify)
{
$this->password_verify = $password_verify;
return $this;
}
public function getLastLoginAt(): ?\DateTime
{
return $this->last_login_at;
}
public function setLastLoginAt(?\DateTime $last_login_at): self
{
$this->last_login_at = $last_login_at;
return $this;
}
public function getIsActive(): ?bool
{
return $this->is_active;
}
public function setIsActive(bool $is_active): self
{
$this->is_active = $is_active;
return $this;
}
public function getAdresse(): ?Adresse
{
return $this->adresse;
}
public function setAdresse(?Adresse $adresse): self
{
$this->adresse = $adresse;
return $this;
}
/**
* @return Collection|Phone[]
*/
public function getPhones(): Collection
{
return $this->phones;
}
public function addPhone(Phone $phone): self
{
if (!$this->phones->contains($phone)) {
$this->phones[] = $phone;
$phone->setUser($this);
}
return $this;
}
public function removePhone(Phone $phone): self
{
if ($this->phones->removeElement($phone)) {
// set the owning side to null (unless already changed)
if ($phone->getUser() === $this) {
$phone->setUser(null);
}
}
return $this;
}
public function getCle(): ?string
{
return $this->cle;
}
public function setCle(string $cle): self
{
$this->cle = $cle;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getIsVerified(): ?bool
{
return $this->is_verified;
}
public function setIsVerified(bool $is_verified): self
{
$this->is_verified = $is_verified;
return $this;
}
public function getFullName(): ?string
{
return $this->first_name. ' ' . $this->last_name;
}
public function getFirstName(): ?string
{
return $this->first_name;
}
public function setFirstName(string $first_name): self
{
$this->first_name = $first_name;
return $this;
}
public function getLastName(): ?string
{
return $this->last_name;
}
public function setLastName(string $last_name): self
{
$this->last_name = $last_name;
return $this;
}
public function getApiKey(): ?string
{
return $this->api_key;
}
public function setApiKey(string $api_key): self
{
$this->api_key = $api_key;
return $this;
}
}