src/Entity/Subscription.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubscriptionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassSubscriptionRepository::class)]
  9. class Subscription
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255nullabletrue)]
  16.     private ?string $stripeId null;
  17.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  18.     private ?\DateTimeInterface $currentPeriodStart null;
  19.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  20.     private ?\DateTimeInterface $currentPeriodEnd  null;
  21.     #[ORM\Column]
  22.     private ?bool $isActive null;
  23.     #[ORM\ManyToOne(inversedBy'subscriptions')]
  24.     private ?Plan $plan null;
  25.     #[ORM\ManyToOne(inversedBy'subscriptions')]
  26.     private ?Users $user null;
  27.     #[ORM\OneToMany(mappedBy'subscription'targetEntityInvoice::class)]
  28.     private Collection $invoices;
  29.     public function __construct()
  30.     {
  31.         $this->invoices = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getStripeId(): ?string
  38.     {
  39.         return $this->stripeId;
  40.     }
  41.     public function setStripeId(?string $stripeId): self
  42.     {
  43.         $this->stripeId $stripeId;
  44.         return $this;
  45.     }
  46.     public function getCurrentPeriodStart(): ?\DateTimeInterface
  47.     {
  48.         return $this->currentPeriodStart;
  49.     }
  50.     public function setCurrentPeriodStart(?\DateTimeInterface $currentPeriodStart): self
  51.     {
  52.         $this->currentPeriodStart  $currentPeriodStart;
  53.         return $this;
  54.     }
  55.     public function getCurrentPeriodEnd(): ?\DateTimeInterface
  56.     {
  57.         return $this->currentPeriodEnd;
  58.     }
  59.     public function setCurrentPeriodEnd(?\DateTimeInterface $currentPeriodEnd): self
  60.     {
  61.         $this->currentPeriodEnd  $currentPeriodEnd;
  62.         return $this;
  63.     }
  64.     public function isIsActive(): ?bool
  65.     {
  66.         return $this->isActive;
  67.     }
  68.     public function setIsActive(?bool $isActive): self
  69.     {
  70.         // Obtenez la date actuelle
  71.         $currentDate = new \DateTime();
  72.         // Comparez la date actuelle avec la date de début et de fin de l'abonnement
  73.         if ($this->currentPeriodStart <= $currentDate && $currentDate <= $this->currentPeriodEnd) {
  74.             $this->isActive true;
  75.         } else {
  76.             $this->isActive false;
  77.         }
  78.         return $this;
  79.     }
  80.     public function getPlan(): ?Plan
  81.     {
  82.         return $this->plan;
  83.     }
  84.     public function setPlan(?Plan $plan): self
  85.     {
  86.         $this->plan $plan;
  87.         return $this;
  88.     }
  89.     public function getUser(): ?Users
  90.     {
  91.         return $this->user;
  92.     }
  93.     public function setUser(?Users $user): self
  94.     {
  95.         $this->user $user;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return Collection<int, Invoice>
  100.      */
  101.     public function getInvoices(): Collection
  102.     {
  103.         return $this->invoices;
  104.     }
  105.     public function addInvoice(Invoice $invoice): self
  106.     {
  107.         if (!$this->invoices->contains($invoice)) {
  108.             $this->invoices->add($invoice);
  109.             $invoice->setSubscription($this);
  110.         }
  111.         return $this;
  112.     }
  113.     public function removeInvoice(Invoice $invoice): self
  114.     {
  115.         if ($this->invoices->removeElement($invoice)) {
  116.             // set the owning side to null (unless already changed)
  117.             if ($invoice->getSubscription() === $this) {
  118.                 $invoice->setSubscription(null);
  119.             }
  120.         }
  121.         return $this;
  122.     }
  123.         public function __toString(): string
  124.     {
  125.         return $this->id ? (string) $this->id '';
  126.     }
  127. }