<?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 Serializable;
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`")
*/
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @ORM\Table(name="`user`")
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
#[UniqueEntity(fields: ['email'], message: 'message="Ce compte existe déjà')]
class User implements UserInterface, PasswordAuthenticatedUserInterface, Serializable
{
/**
* @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\Column(type="string", length=255)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phoneNumber;
/**
* @ORM\ManyToMany(targetEntity=Role::class, inversedBy="users")
*/
private $userRoles;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="employees", cascade={"persist"})
*/
private $company;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isManager;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
/**
* @ORM\OneToOne(targetEntity=ImageManager::class, cascade={"persist", "remove"})
*/
private $avatar;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $googleId;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $hostedDomain;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $avatarFromRemote;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $linkedinId;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $facebookId;
/**
* @ORM\Column(type="array", nullable=true)
*/
private $deviceTokens = [];
/**
* @ORM\OneToMany(targetEntity=Payment::class, mappedBy="customer")
*/
private $payments;
/**
* @ORM\OneToMany(targetEntity=CustomerBpModelAffected::class, mappedBy="customer")
*/
private $customerBpModelAffecteds;
/**
* @ORM\ManyToMany(targetEntity=BPModel::class, mappedBy="customers")
*/
private $bpModels;
/**
* @ORM\OneToOne(targetEntity=CustomerBilling::class, inversedBy="user", cascade={"persist", "remove"})
*/
private $customerBilling;
public function __construct()
{
$this->userRoles = new ArrayCollection();
$this->payments = new ArrayCollection();
$this->customerBpModelAffecteds = new ArrayCollection();
$this->bpModels = 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 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;
//$roles = [];
foreach ($this->getUserRoles() as $role) {
$roles [] = $role->getCode();
}
// 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 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 getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
/**
* @return Collection<int, Role>
*/
public function getUserRoles(): Collection
{
return $this->userRoles;
}
public function addUserRole(Role $userRole): self
{
if (!$this->userRoles->contains($userRole)) {
$this->userRoles[] = $userRole;
}
return $this;
}
public function removeUserRole(Role $userRole): self
{
$this->userRoles->removeElement($userRole);
return $this;
}
public function getFullName(): ?string
{
return $this->getLastName().' '.$this->getFirstName();
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getIsManager(): ?bool
{
return $this->isManager;
}
public function setIsManager(?bool $isManager): self
{
$this->isManager = $isManager;
return $this;
}
public function serialize()
{
return serialize(array(
$this->id,
$this->email,
$this->password,
));
}
public function unserialize($serialized)
{
list(
$this->id,
$this->email,
$this->password,
) = unserialize($serialized);
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function getAvatar(): ?ImageManager
{
return $this->avatar;
}
public function setAvatar(?ImageManager $avatar): self
{
$this->avatar = $avatar;
return $this;
}
public function getGoogleId(): ?string
{
return $this->googleId;
}
public function setGoogleId(?string $googleId): self
{
$this->googleId = $googleId;
return $this;
}
public function getHostedDomain(): ?string
{
return $this->hostedDomain;
}
public function setHostedDomain(?string $hostedDomain): self
{
$this->hostedDomain = $hostedDomain;
return $this;
}
public function getAvatarFromRemote(): ?string
{
return $this->avatarFromRemote;
}
public function setAvatarFromRemote(?string $avatarFromRemote): self
{
$this->avatarFromRemote = $avatarFromRemote;
return $this;
}
public function getLinkedinId(): ?string
{
return $this->linkedinId;
}
public function setLinkedinId(?string $linkedinId): self
{
$this->linkedinId = $linkedinId;
return $this;
}
public function getFacebookId(): ?string
{
return $this->facebookId;
}
public function setFacebookId(?string $facebookId): self
{
$this->facebookId = $facebookId;
return $this;
}
public function isIsManager(): ?bool
{
return $this->isManager;
}
public function isIsVerified(): ?bool
{
return $this->isVerified;
}
/**
* @return array
*/
public function getDeviceTokens(): ?array
{
return $this->deviceTokens;
}
/**
* @param array $deviceTokens
*/
public function setDeviceTokens(array $deviceTokens): void
{
$this->deviceTokens = $deviceTokens;
}
/**
* @return Collection<int, Payment>
*/
public function getPayments(): Collection
{
return $this->payments;
}
public function addPayment(Payment $payment): self
{
if (!$this->payments->contains($payment)) {
$this->payments[] = $payment;
$payment->setCustomer($this);
}
return $this;
}
public function removePayment(Payment $payment): self
{
if ($this->payments->removeElement($payment)) {
// set the owning side to null (unless already changed)
if ($payment->getCustomer() === $this) {
$payment->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection<int, CustomerBpModelAffected>
*/
public function getCustomerBpModelAffecteds(): Collection
{
return $this->customerBpModelAffecteds;
}
public function addCustomerBpModelAffected(CustomerBpModelAffected $customerBpModelAffected): self
{
if (!$this->customerBpModelAffecteds->contains($customerBpModelAffected)) {
$this->customerBpModelAffecteds[] = $customerBpModelAffected;
$customerBpModelAffected->setCustomer($this);
}
return $this;
}
public function removeCustomerBpModelAffected(CustomerBpModelAffected $customerBpModelAffected): self
{
if ($this->customerBpModelAffecteds->removeElement($customerBpModelAffected)) {
// set the owning side to null (unless already changed)
if ($customerBpModelAffected->getCustomer() === $this) {
$customerBpModelAffected->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection<int, BPModel>
*/
public function getBpModels(): Collection
{
return $this->bpModels;
}
public function addBpModel(BPModel $bpModel): self
{
if (!$this->bpModels->contains($bpModel)) {
$this->bpModels[] = $bpModel;
$bpModel->addCustomer($this);
}
return $this;
}
public function removeBpModel(BPModel $bpModel): self
{
if ($this->bpModels->removeElement($bpModel)) {
$bpModel->removeCustomer($this);
}
return $this;
}
public function getCustomerBilling(): ?CustomerBilling
{
return $this->customerBilling;
}
public function setCustomerBilling(?CustomerBilling $customerBilling): self
{
$this->customerBilling = $customerBilling;
return $this;
}
}