<?php
namespace App\Entity;
use App\Repository\SubscriptionRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=SubscriptionRepository::class)
*/
class Subscription
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $updatedAt;
/**
* @ORM\Column(type="datetime")
*/
private $expiresAt;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isActivo;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="subscriptions")
*/
private $user;
/**
* @ORM\ManyToOne(targetEntity=Product::class)
*/
private $producto;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isArchived;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="soldSubscriptions")
*/
private $seller;
/**
* @ORM\Column(type="string", length=1000, nullable=true)
*/
private $comentarios;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $currentPlace;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $hasFlag;
/**
* @ORM\OneToOne(targetEntity=PromoCodeUsage::class, mappedBy="subscription", cascade={"persist", "remove"})
*/
private $promoCodeUsage;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $stripeId;
/**
* @ORM\OneToOne(targetEntity=OrdenItem::class, mappedBy="subscription", cascade={"persist", "remove"})
*/
private $ordenItem;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $clienteId;
/**
* @ORM\ManyToOne(targetEntity=SubscriptionStatus::class, inversedBy="subscripciones")
*/
private $subscriptionStatus;
public function __construct()
{
if(!$this->createdAt) $this->setCreatedAt(new \DateTimeImmutable());
$this->setUpdatedAt(new \DateTimeImmutable());
if(!$this->hasFlag) $this->setHasFlag(0);
// if(!$this->currentPlace) $this->setCurrentPlace('Activa');
}
public function getId(): ?int
{
return $this->id;
}
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 getExpiresAt(): ?\DateTime
{
return $this->expiresAt;
}
public function setExpiresAt(\DateTime $expiresAt): self
{
$this->expiresAt = $expiresAt;
return $this;
}
public function updateLastExpireDate(): self
{
$u = $this->getUser();
$u->setLastSubscriptionDate($this->getExpiresAt());
return $this;
}
public function getIsActivo(): ?bool
{
return $this->isActivo;
}
public function setIsActivo(?bool $isActivo): self
{
$this->isActivo = $isActivo;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getProducto(): ?Product
{
return $this->producto;
}
public function setProducto(?Product $producto): self
{
$this->producto = $producto;
return $this;
}
public function __toString()
{
$prog = $this->getProducto() ? $this->getProducto()->getPrograma() : 'Producto Nulo';
return $prog . ': ' . $this->getExpiresAt()->format('d-M-Y');
}
public function isIsArchived(): ?bool
{
return $this->isArchived;
}
public function setIsArchived(?bool $isArchived): self
{
$this->isArchived = $isArchived;
return $this;
}
public function getSeller(): ?User
{
return $this->seller;
}
public function setSeller(?User $seller): self
{
$this->seller = $seller;
return $this;
}
public function getComentarios(): ?string
{
return $this->comentarios;
}
public function setComentarios(?string $comentarios): self
{
$this->comentarios = $comentarios;
return $this;
}
public function getCurrentPlace(): ?string
{
return $this->currentPlace;
}
public function setCurrentPlace(?string $currentPlace): self
{
$this->currentPlace = $currentPlace;
return $this;
}
public function isHasFlag(): ?bool
{
return $this->hasFlag;
}
public function setHasFlag(?bool $hasFlag): self
{
$this->hasFlag = $hasFlag;
return $this;
}
public function getPromoCodeUsage(): ?PromoCodeUsage
{
return $this->promoCodeUsage;
}
public function setPromoCodeUsage(?PromoCodeUsage $promoCodeUsage): self
{
// unset the owning side of the relation if necessary
if ($promoCodeUsage === null && $this->promoCodeUsage !== null) {
$this->promoCodeUsage->setSubscription(null);
}
// set the owning side of the relation if necessary
if ($promoCodeUsage !== null && $promoCodeUsage->getSubscription() !== $this) {
$promoCodeUsage->setSubscription($this);
}
$this->promoCodeUsage = $promoCodeUsage;
return $this;
}
public function getStripeId(): ?string
{
return $this->stripeId;
}
public function setStripeId(?string $stripeId): self
{
$this->stripeId = $stripeId;
return $this;
}
public function getOrdenItem(): ?OrdenItem
{
return $this->ordenItem;
}
public function setOrdenItem(?OrdenItem $ordenItem): self
{
// unset the owning side of the relation if necessary
if ($ordenItem === null && $this->ordenItem !== null) {
$this->ordenItem->setSubscription(null);
}
// set the owning side of the relation if necessary
if ($ordenItem !== null && $ordenItem->getSubscription() !== $this) {
$ordenItem->setSubscription($this);
}
$this->ordenItem = $ordenItem;
return $this;
}
public function getClienteId(): ?int
{
return $this->clienteId;
}
public function setClienteId(?int $clienteId): self
{
$this->clienteId = $clienteId;
return $this;
}
public function getUserSubStatus()
{
return $this->getUser()->getSubscriptionStatus();
}
public function getUserTel()
{
return $this->getUser()->getTel1();
}
public function getSubscriptionStatus(): ?SubscriptionStatus
{
return $this->subscriptionStatus;
}
public function setSubscriptionStatus(?SubscriptionStatus $subscriptionStatus): self
{
$this->subscriptionStatus = $subscriptionStatus;
return $this;
}
}