<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use libphonenumber\PhoneNumberUtil;
use libphonenumber\NumberParseException;
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)]
#[UniqueEntity(fields: ['email'], message: 'Cette adresse mail est déjà associée à un compte.')]
#[UniqueEntity(fields: ['companyName'], message: 'Ce nom de compagnie est déjà associé à un compte.')]
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(length: 100)]
private ?string $firstName = null;
#[ORM\Column(length: 100)]
private ?string $lastName = null;
#[ORM\Column(type: 'boolean')]
private $isVerified = false;
#[ORM\Column(length: 255, nullable: true)]
private ?string $image = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Article::class)]
private Collection $articles;
#[ORM\Column(type: Types::TEXT)]
private ?string $customerKey = null;
#[ORM\Column(nullable: true)]
private ?float $credit = null;
#[ORM\Column(length: 100)]
private ?string $phoneNumber = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserPackage::class)]
private Collection $userPackages;
#[ORM\Column(nullable: true)]
private ?int $pbnId = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $customerSubjects = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Order::class, orphanRemoval: true)]
private Collection $orders;
#[ORM\Column(length: 100, nullable: true)]
private ?string $wordpressUsername = null;
#[ORM\Column(length: 150, nullable: true)]
private ?string $wordpressPassword = null;
#[ORM\Column(length: 100, nullable: true)]
private ?string $wordpressUrl = null;
#[ORM\Column(length: 60, nullable: true , options: ['default' => 'yoastseo'])]
private ?string $seoPlugin = null;
#[ORM\Column(options: ['default' => 0])]
private ?bool $autoPublish = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $creationDate = null;
#[ORM\Column(type: Types::SMALLINT, nullable: true, options: ['default' => 3])]
private ?int $numberOfTestArticle = null;
#[ORM\Column(length: 100, nullable: true, unique: true)]
private ?string $companyName = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $tempToken = null;
#[ORM\Column(options: ['default' => 0])]
private ?bool $memberOptionAutoPublish = null;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Sms::class, orphanRemoval: true)]
private Collection $sms;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: ProposedArticle::class, orphanRemoval: true)]
private Collection $proposedArticles;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: Notification::class)]
private Collection $notifications;
public function __construct()
{
$this->articles = new ArrayCollection();
$this->packages = new ArrayCollection();
$this->userPackages = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->sms = new ArrayCollection();
$this->proposedArticles = new ArrayCollection();
$this->notifications = 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 getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): static
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): static
{
$this->lastName = $lastName;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): static
{
$this->isVerified = $isVerified;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): static
{
$this->image = $image;
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;
}
public function getCustomerKey(): ?string
{
return $this->customerKey;
}
public function setCustomerKey(string $customerKey): static
{
$this->customerKey = $customerKey;
return $this;
}
public function getCredit(): ?float
{
return $this->credit;
}
public function setCredit(?float $credit): static
{
$this->credit = $credit;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(string $phoneNumber): self
{
/*
$phoneUtil = PhoneNumberUtil::getInstance();
try {
$numberProto = $phoneUtil->parse($phoneNumber, "FR");
if ($phoneUtil->isValidNumber($numberProto)) {
$this->phoneNumber = $phoneUtil->format($numberProto, \libphonenumber\PhoneNumberFormat::E164);
} else {
$this->phoneNumber = "null";
//throw new \InvalidArgumentException("Numéro de téléphone invalide.");
}
} catch (NumberParseException $e) {
$this->phoneNumber = "null";
//throw new \InvalidArgumentException("Erreur de parsing du numéro de téléphone: " . $e->getMessage());
}
return $this;*/
$this->phoneNumber = $phoneNumber;
return $this;
}
/**
* @return Collection<int, UserPackage>
*/
public function getUserPackages(): Collection
{
return $this->userPackages;
}
public function addUserPackage(UserPackage $userPackage): static
{
if (!$this->userPackages->contains($userPackage)) {
$this->userPackages->add($userPackage);
$userPackage->setUser($this);
}
return $this;
}
public function removeUserPackage(UserPackage $userPackage): static
{
if ($this->userPackages->removeElement($userPackage)) {
// set the owning side to null (unless already changed)
if ($userPackage->getUser() === $this) {
$userPackage->setUser(null);
}
}
return $this;
}
public function getPbnId(): ?int
{
return $this->pbnId;
}
public function setPbnId(?int $pbnId): static
{
$this->pbnId = $pbnId;
return $this;
}
public function getCustomerSubjects(): ?string
{
return $this->customerSubjects;
}
public function setCustomerSubjects(?string $customerSubjects): static
{
$this->customerSubjects = $customerSubjects;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): static
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setUser($this);
}
return $this;
}
public function removeOrder(Order $order): static
{
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 getWordpressUsername(): ?string
{
return $this->wordpressUsername;
}
public function setWordpressUsername(?string $wordpressUsername): static
{
$this->wordpressUsername = $wordpressUsername;
return $this;
}
public function getWordpressPassword(): ?string
{
return $this->wordpressPassword;
}
public function setWordpressPassword(?string $wordpressPassword): static
{
$this->wordpressPassword = $wordpressPassword;
return $this;
}
public function getWordpressUrl(): ?string
{
return $this->wordpressUrl;
}
public function setWordpressUrl(?string $wordpressUrl): static
{
$this->wordpressUrl = $wordpressUrl;
return $this;
}
public function getSeoPlugin(): ?string
{
return $this->seoPlugin;
}
public function setSeoPlugin(string $seoPlugin): static
{
$this->seoPlugin = $seoPlugin;
return $this;
}
public function isAutoPublish(): ?bool
{
return $this->autoPublish;
}
public function setAutoPublish(bool $autoPublish): static
{
$this->autoPublish = $autoPublish;
return $this;
}
public function getCreationDate(): ?\DateTimeInterface
{
return $this->creationDate;
}
public function setCreationDate(\DateTimeInterface $creationDate): static
{
$this->creationDate = $creationDate;
return $this;
}
public function getNumberOfTestArticle(): ?int
{
return $this->numberOfTestArticle;
}
public function setNumberOfTestArticle(?int $numberOfTestArticle): static
{
$this->numberOfTestArticle = $numberOfTestArticle;
return $this;
}
public function getCompanyName(): ?string
{
return $this->companyName;
}
public function setCompanyName(?string $companyName): static
{
$this->companyName = $companyName;
return $this;
}
public function getTempToken(): ?string
{
return $this->tempToken;
}
public function setTempToken(?string $tempToken): static
{
$this->tempToken = $tempToken;
return $this;
}
public function isMemberOptionAutoPublish(): ?bool
{
return $this->memberOptionAutoPublish;
}
public function setMemberOptionAutoPublish(bool $memberOptionAutoPublish): static
{
$this->memberOptionAutoPublish = $memberOptionAutoPublish;
return $this;
}
/**
* @return Collection<int, Sms>
*/
public function getSms(): Collection
{
return $this->sms;
}
public function addSms(Sms $sms): static
{
if (!$this->sms->contains($sms)) {
$this->sms->add($sms);
$sms->setUser($this);
}
return $this;
}
public function removeSms(Sms $sms): static
{
if ($this->sms->removeElement($sms)) {
// set the owning side to null (unless already changed)
if ($sms->getUser() === $this) {
$sms->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, ProposedArticle>
*/
public function getProposedArticles(): Collection
{
return $this->proposedArticles;
}
public function addProposedArticle(ProposedArticle $proposedArticle): static
{
if (!$this->proposedArticles->contains($proposedArticle)) {
$this->proposedArticles->add($proposedArticle);
$proposedArticle->setUser($this);
}
return $this;
}
public function removeProposedArticle(ProposedArticle $proposedArticle): static
{
if ($this->proposedArticles->removeElement($proposedArticle)) {
// set the owning side to null (unless already changed)
if ($proposedArticle->getUser() === $this) {
$proposedArticle->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): static
{
if (!$this->notifications->contains($notification)) {
$this->notifications->add($notification);
$notification->setUser($this);
}
return $this;
}
public function removeNotification(Notification $notification): static
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getUser() === $this) {
$notification->setUser(null);
}
}
return $this;
}
}