<?php
namespace App\Entity;
use Serializable;
use App\Entity\Point;
use App\Entity\Contact;
use App\Entity\Purchase;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
*/
class User implements UserInterface
{
const NEWSLETTER_SUBSCRIBE = 1;
const NEWSLETTER_UNSUBSCRIBE = 0;
const EMAIL_CONFIRM = 1;
const PURCHASE_ACCEPT = 1;
const PURCHASE_DECLINE = 2;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, nullable=true)
*/
private $email;
/**
* @var string The hashed password
* @ORM\Column(type="string")
* @Assert\Length(
* min = 8,
* minMessage = "Votre mot de passe doit contenir au moins {{ limit }} caractères.",
* allowEmptyString = false
* )
*/
private $password;
/**
* @ORM\Column(type="smallint", nullable=true)
*/
private $gender;
/**
* @ORM\Column(type="string", length=255)
*/
private $civilite;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $firstName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $lastName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $address;
/**
* @ORM\Column(type="string", length=255)
* @Assert\Length(
* min = 5,
* minMessage = "Le code postal doit comporter 5 chiffres.",
* allowEmptyString = false
*
* )
*/
private $postalCode;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $city;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $phoneNumber;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updatedAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastDateAction;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isActive = true;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $resetToken;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $birthDate;
/**
* @ORM\Column(type="boolean")
*/
private $isEmailConfirm = false;
/**
* @var Point[]|ArrayCollection
*
* @ORM\OneToMany(targetEntity="App\Entity\Point", mappedBy="author", cascade={"persist", "remove"})
*/
private $points;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $isEmailConfirmDate;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $address2;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $country = 'France';
/**
* @ORM\OneToMany(targetEntity=Purchase::class, mappedBy="author", cascade={"persist"})
*/
private $purchases;
/**
* @Assert\Iban(
* message="L'IBAN renseigné est incorrect."
* )
* @ORM\Column(type="string", length=255, nullable=true)
*
*/
private $iban;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isNewsletter;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isCgu;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $isCguDate;
/**
* @ORM\OneToMany(targetEntity=Contact::class, mappedBy="author")
*/
private $contacts;
/**
* @ORM\OneToMany(targetEntity=Purchase::class, mappedBy="createdBy")
*/
private $purchasesCreatedBy;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isBlocked;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $doublonFirstNameLastName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $allDoublonFirstNameLastName;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $doublonLastNameZipCode;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $AllDoublonLastNameZipCode;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $isBlockedDate;
/**
* @ORM\ManyToOne(targetEntity=Operation::class, inversedBy="users")
*/
private $isBlockedOperation;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
public function __construct()
{
$this->points = new ArrayCollection();
$this->purchases = new ArrayCollection();
$this->contacts = new ArrayCollection();
$this->purchasesCreatedBy = new ArrayCollection();
$this->purchases = 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 getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
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 getGender(): ?int
{
return $this->gender;
}
public function setGender(int $gender): self
{
$this->gender = $gender;
return $this;
}
public function getCivilite(): ?string
{
return $this->civilite;
}
public function setCivilite(string $civilite): self
{
$this->civilite = $civilite;
return $this;
}
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 getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function setPostalCode(string $postalCode): self
{
$this->postalCode = $postalCode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(string $city): self
{
$this->city = $city;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
public function getIsNewsletter(): ?bool
{
return $this->isNewsletter;
}
public function setIsNewsletter(bool $isNewsletter): self
{
$this->isNewsletter = $isNewsletter;
return $this;
}
public function getIsNewsletterDate(): ?\DateTimeInterface
{
return $this->isNewsletterDate;
}
public function setIsNewsletterDate(?\DateTimeInterface $isNewsletterDate): self
{
$this->isNewsletterDate = $isNewsletterDate;
return $this;
}
public function getIsCgu(): ?bool
{
return $this->isCgu;
}
public function setIsCgu(bool $isCgu): self
{
$this->isCgu = $isCgu;
return $this;
}
public function getIsCguDate(): ?\DateTimeInterface
{
return $this->isCguDate;
}
public function setIsCguDate(?\DateTimeInterface $isCguDate): self
{
$this->isCguDate = $isCguDate;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getLastDateAction(): ?\DateTimeInterface
{
return $this->lastDateAction;
}
public function setLastDateAction(?\DateTimeInterface $lastDateAction): self
{
$this->lastDateAction = $lastDateAction;
return $this;
}
public function getIsActive(): ?bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): self
{
$this->isActive = $isActive;
return $this;
}
public function getResetToken(): ?string
{
return $this->resetToken;
}
public function setResetToken(?string $resetToken): self
{
$this->resetToken = $resetToken;
return $this;
}
public function getBirthDate(): ?\DateTimeInterface
{
return $this->birthDate;
}
public function setBirthDate(?\DateTimeInterface $birthDate): self
{
$this->birthDate = $birthDate;
return $this;
}
public function getIsEmailConfirm(): ?bool
{
return $this->isEmailConfirm;
}
public function setIsEmailConfirm(bool $isEmailConfirm): self
{
$this->isEmailConfirm = $isEmailConfirm;
return $this;
}
public function getIsEmailConfirmDate(): ?\DateTimeInterface
{
return $this->isEmailConfirmDate;
}
public function setIsEmailConfirmDate(?\DateTimeInterface $isEmailConfirmDate): self
{
$this->isEmailConfirmDate = $isEmailConfirmDate;
return $this;
}
/**
* @return Collection|Point[]
*/
public function getPoints(): Collection
{
return $this->points;
}
public function removePoint(Point $point): self
{
if ($this->points->contains($point)) {
$this->points->removeElement($point);
// set the owning side to null (unless already changed)
if ($point->getAuthor() === $this) {
$point->setAuthor(null);
}
}
return $this;
}
public function getTotalPoints()
{
$total = 0;
foreach ($this->points as $point) {
$total += $point->getValue();
}
return $total;
}
public function getTotalCreditPoints()
{
$total = 0;
foreach ($this->points as $point) {
if ($point->getValue() > 0)
$total += $point->getValue();
}
return $total;
}
public function getTotalDebitPoints()
{
$total = 0;
foreach ($this->points as $point) {
if ($point->getValue() < 0)
$total += $point->getValue();
}
return $total;
}
public function getAddress2(): ?string
{
return $this->address2;
}
public function setAddress2(?string $address2): self
{
$this->address2 = $address2;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
/**
* @return Collection|Purchase[]
*/
public function getPurchases(): Collection
{
return $this->purchases;
}
public function addPurchase(Purchase $purchase): self
{
if (!$this->purchases->contains($purchase)) {
$this->purchases[] = $purchase;
//$purchase->setAuthor($this);
}
return $this;
}
public function removePurchase(Purchase $purchase): self
{
if ($this->purchases->contains($purchase)) {
$this->purchases->removeElement($purchase);
// set the owning side to null (unless already changed)
if ($purchase->getAuthor() === $this) {
$purchase->setAuthor(null);
}
}
return $this;
}
public function getIban(): ?string
{
return $this->iban;
}
public function setIban(?string $iban): self
{
$this->iban = $iban;
return $this;
}
/**
* @return Collection|Contact[]
*/
public function getContacts(): Collection
{
return $this->contacts;
}
public function addContact(Contact $contact): self
{
if (!$this->contacts->contains($contact)) {
$this->contacts[] = $contact;
$contact->setAuthor($this);
}
return $this;
}
public function removeContact(Contact $contact): self
{
if ($this->contacts->removeElement($contact)) {
// set the owning side to null (unless already changed)
if ($contact->getAuthor() === $this) {
$contact->setAuthor(null);
}
}
return $this;
}
/**
* @return Collection|Purchase[]
*/
public function getPurchasesCreatedBy(): Collection
{
return $this->purchasesCreatedBy;
}
public function addPurchasesCreatedBy(Purchase $purchasesCreatedBy): self
{
if (!$this->purchasesCreatedBy->contains($purchasesCreatedBy)) {
$this->purchasesCreatedBy[] = $purchasesCreatedBy;
$purchasesCreatedBy->setCreatedBy($this);
}
return $this;
}
public function removePurchasesCreatedBy(Purchase $purchasesCreatedBy): self
{
if ($this->purchasesCreatedBy->removeElement($purchasesCreatedBy)) {
// set the owning side to null (unless already changed)
if ($purchasesCreatedBy->getCreatedBy() === $this) {
$purchasesCreatedBy->setCreatedBy(null);
}
}
return $this;
}
public function getIsBlocked(): ?bool
{
return $this->isBlocked;
}
public function setIsBlocked(?bool $isBlocked): self
{
$this->isBlocked = $isBlocked;
return $this;
}
/**
* @return Collection|Doublon[]
*/
public function getDoublons(): Collection
{
return $this->doublons;
}
public function addDoublon(Doublon $doublon): self
{
if (!$this->doublons->contains($doublon)) {
$this->doublons[] = $doublon;
$doublon->setUser($this);
}
return $this;
}
public function removeDoublon(Doublon $doublon): self
{
if ($this->doublons->removeElement($doublon)) {
// set the owning side to null (unless already changed)
if ($doublon->getUser() === $this) {
$doublon->setUser(null);
}
}
return $this;
}
public function getDoublonFirstNameLastName(): ?string
{
return $this->doublonFirstNameLastName;
}
public function setDoublonFirstNameLastName(?string $doublonFirstNameLastName): self
{
$this->doublonFirstNameLastName = $doublonFirstNameLastName;
return $this;
}
public function getAllDoublonFirstNameLastName(): ?string
{
return $this->allDoublonFirstNameLastName;
}
public function setAllDoublonFirstNameLastName(?string $allDoublonFirstNameLastName): self
{
$this->allDoublonFirstNameLastName = $allDoublonFirstNameLastName;
return $this;
}
public function getDoublonLastNameZipCode(): ?string
{
return $this->doublonLastNameZipCode;
}
public function setDoublonLastNameZipCode(?string $doublonLastNameZipCode): self
{
$this->doublonLastNameZipCode = $doublonLastNameZipCode;
return $this;
}
public function getAllDoublonLastNameZipCode(): ?string
{
return $this->AllDoublonLastNameZipCode;
}
public function setAllDoublonLastNameZipCode(?string $AllDoublonLastNameZipCode): self
{
$this->AllDoublonLastNameZipCode = $AllDoublonLastNameZipCode;
return $this;
}
public function getIsBlockedDate(): ?\DateTimeInterface
{
return $this->isBlockedDate;
}
public function setIsBlockedDate(?\DateTimeInterface $isBlockedDate): self
{
$this->isBlockedDate = $isBlockedDate;
return $this;
}
public function getIsBlockedOperation(): ?Operation
{
return $this->isBlockedOperation;
}
public function setIsBlockedOperation(?Operation $isBlockedOperation): self
{
$this->isBlockedOperation = $isBlockedOperation;
return $this;
}
/**
* The public representation of the user (e.g. a username, an email address, etc.)
*
* @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): self
{
$this->roles = $roles;
return $this;
}
}