<?php
namespace App\Entity;
use App\Repository\SubscriptionRepository;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, nullable=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=250, nullable=true)
*/
private $Nombre;
/**
* @ORM\Column(type="string", length=25, nullable=true)
*/
private $Apellido1;
/**
* @ORM\Column(type="string", length=25, nullable=true)
*/
private $Apellido2;
/**
* @ORM\Column(type="string", length=15, unique=true)
*/
private $tel1;
/**
* @ORM\Column(type="boolean", options={"default"=1})
*/
private $isActivo;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $updatedAt;
/**
* @ORM\Column(type="string", length=1000, nullable=true)
*/
private $comentarios;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $stripeId;
/**
* @ORM\OneToMany(targetEntity=Subscription::class, mappedBy="user")
*/
private $subscriptions;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $plainPassword;
/**
* @ORM\OneToMany(targetEntity=Subscription::class, mappedBy="seller")
*/
private $soldSubscriptions;
/**
* @ORM\OneToMany(targetEntity=Payout::class, mappedBy="seller")
*/
private $payouts;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $dob;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $resetPin;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $clienteId;
/**
* @ORM\OneToMany(targetEntity=Orden::class, mappedBy="user")
*/
private $ordenes;
/**
* @ORM\OneToMany(targetEntity=PaymentIntent::class, mappedBy="user")
*/
private $paymentIntents;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $subscriptionStatus;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $lastSubscriptionDate;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $lastExpiresAt;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $userId;
/**
* @ORM\OneToMany(targetEntity=MailingLog::class, mappedBy="user")
*/
private $mailingLogs;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $nombreCompleto;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $sendgridId;
/**
* @ORM\ManyToOne(targetEntity=MailingList::class, inversedBy="users")
*/
private $mailingList;
/**
* @ORM\ManyToOne(targetEntity=PromoCode::class, inversedBy="usedUsers")
*/
private $usedPromoCode;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $sendgridStatus;
/**
* @ORM\Column(type="boolean", options={"default"=0})
*/
private $sendgridIgnore;
/**
* @ORM\OneToMany(targetEntity=Solicitud::class, mappedBy="user")
*/
private $solicitudes;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $directCode;
public function __construct()
{
if(!$this->createdAt) $this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
if(!$this->password) $this->password = '1234';
$this->subscriptions = new ArrayCollection();
$this->soldSubscriptions = new ArrayCollection();
$this->payouts = new ArrayCollection();
$this->ordenes = new ArrayCollection();
$this->paymentIntents = new ArrayCollection();
$this->mailingLogs = new ArrayCollection();
if(!$this->sendgridStatus) $this->sendgridStatus = 'Renovado';
$this->solicitudes = 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->tel1;
}
/**
* @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;
}
public function getNombre(): ?string
{
return $this->Nombre;
}
public function setNombre(?string $Nombre): self
{
$this->Nombre = $Nombre;
return $this;
}
public function getApellido1(): ?string
{
return $this->Apellido1;
}
public function setApellido1(?string $Apellido1): self
{
$this->Apellido1 = $Apellido1;
return $this;
}
public function getApellido2(): ?string
{
return $this->Apellido2;
}
public function setApellido2(?string $Apellido2): self
{
$this->Apellido2 = $Apellido2;
return $this;
}
public function getTel1(): ?string
{
return $this->tel1;
}
public function setTel1(?string $tel1): self
{
$this->tel1 = $tel1;
return $this;
}
public function getIsActivo(): ?bool
{
return $this->isActivo;
}
public function setIsActivo(bool $isActivo): self
{
$this->isActivo = $isActivo;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getComentarios(): ?string
{
return $this->comentarios;
}
public function setComentarios(?string $comentarios): self
{
$this->comentarios = $comentarios;
return $this;
}
public function getStripeId(): ?string
{
return $this->stripeId;
}
public function setStripeId(?string $stripeId): self
{
$this->stripeId = $stripeId;
return $this;
}
public function __toString()
{
if($this->getNombre()){
return $this->getNombre() . ' ' . $this->getApellido1();
}else{
return $this->getNombreCompleto();
}
}
/**
* @return Collection<int, Subscription>
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function getActiveSubscriptions()
{
$r = [];
$r = $this->getSubscriptions()->filter(function (Subscription $sub) {
return $sub->getCurrentPlace() == 'Activa';
// return in_array($sub->getCurrentPlace(), ['Activa', 'Activa 15d']);
});
return $r->toArray();
}
public function getActive15Subscriptions()
{
$r = [];
$r = $this->getSubscriptions()->filter(function (Subscription $sub) {
return $sub->getCurrentPlace() == 'Activa 15d';
// return in_array($sub->getCurrentPlace(), ['Activa', 'Activa 15d']);
});
return $r->toArray();
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions[] = $subscription;
$subscription->setUser($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getUser() === $this) {
$subscription->setUser(null);
}
}
return $this;
}
public function getPlainPassword(): ?string
{
return $this->plainPassword;
}
public function setPlainPassword(?string $plainPassword): self
{
$this->plainPassword = $plainPassword;
return $this;
}
/**
* @return Collection<int, Subscription>
*/
public function getSoldSubscriptions(): Collection
{
return $this->soldSubscriptions;
}
public function addSoldSubscription(Subscription $soldSubscription): self
{
if (!$this->soldSubscriptions->contains($soldSubscription)) {
$this->soldSubscriptions[] = $soldSubscription;
$soldSubscription->setSeller($this);
}
return $this;
}
public function removeSoldSubscription(Subscription $soldSubscription): self
{
if ($this->soldSubscriptions->removeElement($soldSubscription)) {
// set the owning side to null (unless already changed)
if ($soldSubscription->getSeller() === $this) {
$soldSubscription->setSeller(null);
}
}
return $this;
}
/**
* @return Collection<int, Payout>
*/
public function getPayouts(): Collection
{
return $this->payouts;
}
public function addPayout(Payout $payout): self
{
if (!$this->payouts->contains($payout)) {
$this->payouts[] = $payout;
$payout->setSeller($this);
}
return $this;
}
public function removePayout(Payout $payout): self
{
if ($this->payouts->removeElement($payout)) {
// set the owning side to null (unless already changed)
if ($payout->getSeller() === $this) {
$payout->setSeller(null);
}
}
return $this;
}
public function getDob(): ?\DateTimeInterface
{
return $this->dob;
}
public function setDob(?\DateTimeInterface $dob): self
{
$this->dob = $dob;
return $this;
}
public function getResetPin(): ?bool
{
return $this->resetPin;
}
public function setResetPin(?bool $resetPin): self
{
$this->resetPin = $resetPin;
return $this;
}
public function isHasSubscriptionActiva(): ?bool
{
return $this->hasSubscriptionActiva;
}
public function setHasSubscriptionActiva(?bool $hasSubscriptionActiva): self
{
$this->hasSubscriptionActiva = $hasSubscriptionActiva;
return $this;
}
public function getClienteId(): ?int
{
return $this->clienteId;
}
public function setClienteId(?int $clienteId): self
{
$this->clienteId = $clienteId;
return $this;
}
/**
* @return Collection<int, Orden>
*/
public function getOrdenes(): Collection
{
return $this->ordenes;
}
public function addOrdene(Orden $ordene): self
{
if (!$this->ordenes->contains($ordene)) {
$this->ordenes[] = $ordene;
$ordene->setUser($this);
}
return $this;
}
public function removeOrdene(Orden $ordene): self
{
if ($this->ordenes->removeElement($ordene)) {
// set the owning side to null (unless already changed)
if ($ordene->getUser() === $this) {
$ordene->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, PaymentIntent>
*/
public function getPaymentIntents(): Collection
{
return $this->paymentIntents;
}
public function addPaymentIntent(PaymentIntent $paymentIntent): self
{
if (!$this->paymentIntents->contains($paymentIntent)) {
$this->paymentIntents[] = $paymentIntent;
$paymentIntent->setUser($this);
}
return $this;
}
public function removePaymentIntent(PaymentIntent $paymentIntent): self
{
if ($this->paymentIntents->removeElement($paymentIntent)) {
// set the owning side to null (unless already changed)
if ($paymentIntent->getUser() === $this) {
$paymentIntent->setUser(null);
}
}
return $this;
}
public function getSubscriptionStatus(): ?string
{
return $this->subscriptionStatus;
}
public function setSubscriptionStatus(?string $subscriptionStatus): self
{
$this->subscriptionStatus = $subscriptionStatus;
return $this;
}
public function getLastSubscriptionDate(): ?\DateTimeInterface
{
return $this->lastSubscriptionDate;
}
public function setLastSubscriptionDate(?\DateTimeInterface $lastSubscriptionDate): self
{
$this->lastSubscriptionDate = $lastSubscriptionDate;
return $this;
}
public function getLastExpiresAt(): ?\DateTimeImmutable
{
return $this->lastExpiresAt;
}
public function setLastExpiresAt(?\DateTimeImmutable $lastExpiresAt): self
{
$this->lastExpiresAt = $lastExpiresAt;
return $this;
}
public function getUserId(): ?int
{
return $this->userId;
}
public function setUserId(?int $userId): self
{
$this->userId = $userId;
return $this;
}
/**
* @return Collection<int, MailingLog>
*/
public function getMailingLogs(): Collection
{
return $this->mailingLogs;
}
public function addMailingLog(MailingLog $mailingLog): self
{
if (!$this->mailingLogs->contains($mailingLog)) {
$this->mailingLogs[] = $mailingLog;
$mailingLog->setUser($this);
}
return $this;
}
public function removeMailingLog(MailingLog $mailingLog): self
{
if ($this->mailingLogs->removeElement($mailingLog)) {
// set the owning side to null (unless already changed)
if ($mailingLog->getUser() === $this) {
$mailingLog->setUser(null);
}
}
return $this;
}
public function getNombreCompleto(): ?string
{
return $this->nombreCompleto;
}
public function setNombreCompleto(?string $nombreCompleto): self
{
$this->nombreCompleto = $nombreCompleto;
return $this;
}
public function getSendgridId(): ?string
{
return $this->sendgridId;
}
public function setSendgridId(?string $sendgridId): self
{
$this->sendgridId = $sendgridId;
return $this;
}
public function getMailingList(): ?MailingList
{
return $this->mailingList;
}
public function setMailingList(?MailingList $mailingList): self
{
$this->mailingList = $mailingList;
return $this;
}
public function getUsedPromoCode(): ?PromoCode
{
return $this->usedPromoCode;
}
public function setUsedPromoCode(?PromoCode $usedPromoCode): self
{
$this->usedPromoCode = $usedPromoCode;
return $this;
}
public function getSendgridStatus(): ?string
{
return $this->sendgridStatus;
}
public function setSendgridStatus(string $sendgridStatus): self
{
$this->sendgridStatus = $sendgridStatus;
return $this;
}
public function getSendgridIgnore(): ?bool
{
return $this->sendgridIgnore;
}
public function setSendgridIgnore(bool $sendgridIgnore): self
{
$this->sendgridIgnore = $sendgridIgnore;
return $this;
}
/**
* @return Collection<int, Solicitud>
*/
public function getSolicitudes(): Collection
{
return $this->solicitudes;
}
public function addSolicitude(Solicitud $solicitude): self
{
if (!$this->solicitudes->contains($solicitude)) {
$this->solicitudes[] = $solicitude;
$solicitude->setUser($this);
}
return $this;
}
public function removeSolicitude(Solicitud $solicitude): self
{
if ($this->solicitudes->removeElement($solicitude)) {
// set the owning side to null (unless already changed)
if ($solicitude->getUser() === $this) {
$solicitude->setUser(null);
}
}
return $this;
}
public function getDirectCode(): ?string
{
return $this->directCode;
}
public function setDirectCode(?string $directCode): self
{
$this->directCode = $directCode;
return $this;
}
}