<?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;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @method string getUserIdentifier()
* @UniqueEntity(fields={"email"}, message="Il semble que vous ayez déjà un compte")
* @UniqueEntity(fields={"Cin"}, message="Il semble que vous ayez déjà un compte avec ce CIN.")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
const ROLE_CLIENT = 'ROLE_CLIENT';
const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
const ROLE_ADMIN = 'ROLE_ADMIN';
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true , nullable=true)
* @Assert\Email()
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string", nullable=true)
*/
private $password;
/**
* @var string The plain password
*
* @Assert\Length(
* min=6,
* allowEmptyString=true,
* )
*/
private $plainPassword;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(
* max = 25,
* maxMessage = "Le prénom ne peut pas dépasser {{ limit }} caractères"
* )
* @Assert\Regex(
* pattern="/^[a-zA-ZÀ-ÖØ-öø-ÿ\- ]*$/",
* message="Le prénom doit contenir uniquement des lettres."
* )
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(
* max = 25,
* maxMessage = "Le nom ne peut pas dépasser {{ limit }} caractères"
* )
* @Assert\Regex(
* pattern="/^[a-zA-ZÀ-ÖØ-öø-ÿ\- ]*$/",
* message="Le nom doit contenir uniquement des lettres."
* )
*/
private $lastName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $mobile;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $annuler;
/**
* @ORM\Column(type="string", length=255 , unique=true )
*/
private $Cin;
/**
* @ORM\Column(type="string", nullable=true)
* @Assert\Regex(
* pattern="/^\d{24}$/",
* message="Le RIB doit être composé de 24 chiffres.",
* )
*/
private $rib;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(
* max = 25,
* maxMessage = "La Banque ne peut pas dépasser {{ limit }} caractères"
* )
* @Assert\Regex(
* pattern="/^[a-zA-ZÀ-ÖØ-öø-ÿ\- ]*$/",
* message="Le Banque doit contenir uniquement des lettres."
* )
*/
private $banque;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Assert\Length(
* max = 25,
* maxMessage = "La Ville ne peut pas dépasser {{ limit }} caractères"
* )
* @Assert\Regex(
* pattern="/^[a-zA-ZÀ-ÖØ-öø-ÿ\- ]*$/",
* message="Le Ville doit contenir uniquement des lettres."
* )
*/
private $ville;
/**
* @ORM\Column(type="string", length=10, nullable=true)
*/
private $gendre;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $datenaissance;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $adresse;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="users")
*/
private $referral;
/**
* @ORM\OneToMany(targetEntity=User::class, mappedBy="referral")
*/
private $users;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $matrecul;
/**
* @ORM\Column(type="datetime",nullable=true))
*/
private $dateaffiliate;
/**
* @ORM\Column(type="string", length=255, nullable=true))
*/
private $status;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $picture;
/**
* @ORM\OneToMany(targetEntity=Orders::class, mappedBy="user")
*/
private $orders;
/**
* @ORM\OneToMany(targetEntity=Commission::class, mappedBy="user")
*/
private $commissions;
/**
* @ORM\OneToMany(targetEntity=Bonus::class, mappedBy="user")
*/
private $bonuses;
/**
* @ORM\OneToMany(targetEntity=Paiement::class, mappedBy="user")
*/
private $paiements;
/**
* @ORM\Column(type="decimal", precision=10, scale=2, nullable=true)
*/
private $Balance;
/**
* @ORM\OneToMany(targetEntity=UserGift::class, mappedBy="user")
*/
private $userGifts;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $resetPasswordToken;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $resetPasswordTokenExpiresAt;
/**
* @ORM\OneToMany(targetEntity=PasswordResetRequest::class, mappedBy="user")
*/
private $passwordResetRequests;
public function __construct()
{
$this->users = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->commissions = new ArrayCollection();
$this->bonuses = new ArrayCollection();
$this->paiements = new ArrayCollection();
$this->userGifts = new ArrayCollection();
$this->passwordResetRequests = 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 getUsername(): string
{
return (string)$this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = self::ROLE_CLIENT;
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function addRole(string $role): self
{
if (array_search($role, $this->getRoles()) === FALSE)
$this->roles[] = $role;
return $this;
}
public function hasRole(string $role): bool
{
return array_search($role, $this->getRoles()) !== FALSE;
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string)$this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(string $plainPassword): self
{
$this->plainPassword = $plainPassword;
return $this;
}
/**
* @see UserInterface
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @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 getMobile(): ?string
{
return $this->mobile;
}
public function setMobile(?string $mobile): self
{
$this->mobile = $mobile;
return $this;
}
public function stringRole()
{
$role = 'Client';
if ($this->hasRole(self::ROLE_ADMIN)) {
$role = 'Admin';
}elseif ($this->hasRole(self::ROLE_SUPER_ADMIN)) {
$role = 'Super Admin';
}
return $role;
}
public function getStringRole(): string
{
if ($this->hasRole(self::ROLE_ADMIN)) {
return 'Admin';
} elseif ($this->hasRole(self::ROLE_SUPER_ADMIN)) {
return 'Super Admin';
} elseif ($this->hasRole(self::ROLE_CLIENT)) {
return 'Client';
}
// Retour par défaut si aucun rôle ne correspond
return 'Unknown Role';
}
public function getAnnuler(): ?bool
{
return $this->annuler;
}
public function setAnnuler(?bool $annuler): self
{
$this->annuler = $annuler;
return $this;
}
public function isAnnuler(): ?bool
{
return $this->annuler;
}
public function getCin(): ?string
{
return $this->Cin;
}
public function setCin(string $Cin): self
{
$this->Cin = $Cin;
return $this;
}
public function getBanque(): ?string
{
return $this->banque;
}
public function setBanque(?string $banque): self
{
$this->banque = $banque;
return $this;
}
public function getVille(): ?string
{
return $this->ville;
}
public function setVille(?string $ville): self
{
$this->ville = $ville;
return $this;
}
public function getGendre(): ?string
{
return $this->gendre;
}
public function setGendre(?string $gendre): self
{
$this->gendre = $gendre;
return $this;
}
public function getDatenaissance(): ?\DateTimeInterface
{
return $this->datenaissance;
}
public function setDatenaissance(?\DateTimeInterface $datenaissance): self
{
$this->datenaissance = $datenaissance;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(?string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getReferral(): ?self
{
return $this->referral;
}
public function setReferral(?self $referral): self
{
$this->referral = $referral;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(self $user): self
{
if (!$this->users->contains($user)) {
$this->users[] = $user;
$user->setReferral($this);
}
return $this;
}
public function removeUser(self $user): self
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getReferral() === $this) {
$user->setReferral(null);
}
}
return $this;
}
public function getMatrecul(): ?string
{
return $this->matrecul;
}
public function setMatrecul(?string $matrecul): self
{
$this->matrecul = $matrecul;
return $this;
}
public function getDateaffiliate(): ?\DateTimeInterface
{
return $this->dateaffiliate;
}
public function setDateaffiliate(\DateTimeInterface $dateaffiliate): self
{
$this->dateaffiliate = $dateaffiliate;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getPicture(): ?string
{
return $this->picture;
}
public function setPicture(?string $picture): self
{
$this->picture = $picture;
return $this;
}
/**
* @return mixed
*/
public function getRib()
{
return $this->rib;
}
/**
* @param mixed $rib
*/
public function setRib($rib): void
{
$this->rib = $rib;
}
/**
* @return Collection<int, Orders>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Orders $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setUser($this);
}
return $this;
}
public function removeOrder(Orders $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;
}
/**
* @return Collection<int, Commission>
*/
public function getCommissions(): Collection
{
return $this->commissions;
}
public function addCommission(Commission $commission): self
{
if (!$this->commissions->contains($commission)) {
$this->commissions[] = $commission;
$commission->setUser($this);
}
return $this;
}
public function removeCommission(Commission $commission): self
{
if ($this->commissions->removeElement($commission)) {
// set the owning side to null (unless already changed)
if ($commission->getUser() === $this) {
$commission->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Bonus>
*/
public function getBonuses(): Collection
{
return $this->bonuses;
}
public function addBonus(Bonus $bonus): self
{
if (!$this->bonuses->contains($bonus)) {
$this->bonuses[] = $bonus;
$bonus->setUser($this);
}
return $this;
}
public function removeBonus(Bonus $bonus): self
{
if ($this->bonuses->removeElement($bonus)) {
// set the owning side to null (unless already changed)
if ($bonus->getUser() === $this) {
$bonus->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Paiement>
*/
public function getPaiements(): Collection
{
return $this->paiements;
}
public function addPaiement(Paiement $paiement): self
{
if (!$this->paiements->contains($paiement)) {
$this->paiements[] = $paiement;
$paiement->setUser($this);
}
return $this;
}
public function removePaiement(Paiement $paiement): self
{
if ($this->paiements->removeElement($paiement)) {
// set the owning side to null (unless already changed)
if ($paiement->getUser() === $this) {
$paiement->setUser(null);
}
}
return $this;
}
public function getBalance(): ?string
{
return $this->Balance;
}
public function setBalance(?string $Balance): self
{
$this->Balance = $Balance;
return $this;
}
/**
* @return Collection<int, UserGift>
*/
public function getUserGifts(): Collection
{
return $this->userGifts;
}
public function addUserGift(UserGift $userGift): self
{
if (!$this->userGifts->contains($userGift)) {
$this->userGifts[] = $userGift;
$userGift->setUser($this);
}
return $this;
}
public function removeUserGift(UserGift $userGift): self
{
if ($this->userGifts->removeElement($userGift)) {
// set the owning side to null (unless already changed)
if ($userGift->getUser() === $this) {
$userGift->setUser(null);
}
}
return $this;
}
public function getResetPasswordToken(): ?string
{
return $this->resetPasswordToken;
}
public function setResetPasswordToken(?string $resetPasswordToken): self
{
$this->resetPasswordToken = $resetPasswordToken;
return $this;
}
public function getResetPasswordTokenExpiresAt(): ?\DateTimeInterface
{
return $this->resetPasswordTokenExpiresAt;
}
public function setResetPasswordTokenExpiresAt(?\DateTimeInterface $resetPasswordTokenExpiresAt): self
{
$this->resetPasswordTokenExpiresAt = $resetPasswordTokenExpiresAt;
return $this;
}
/**
* @return Collection<int, PasswordResetRequest>
*/
public function getPasswordResetRequests(): Collection
{
return $this->passwordResetRequests;
}
public function addPasswordResetRequest(PasswordResetRequest $passwordResetRequest): self
{
if (!$this->passwordResetRequests->contains($passwordResetRequest)) {
$this->passwordResetRequests[] = $passwordResetRequest;
$passwordResetRequest->setUser($this);
}
return $this;
}
public function removePasswordResetRequest(PasswordResetRequest $passwordResetRequest): self
{
if ($this->passwordResetRequests->removeElement($passwordResetRequest)) {
// set the owning side to null (unless already changed)
if ($passwordResetRequest->getUser() === $this) {
$passwordResetRequest->setUser(null);
}
}
return $this;
}
}