<?phpnamespace App\Entity;use App\Repository\SubscriptionRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: SubscriptionRepository::class)]class Subscription{ #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] private ?int $id = null; #[ORM\Column(length: 255, nullable: true)] private ?string $stripeId = null; #[ORM\Column(type: Types::DATETIME_MUTABLE)] private ?\DateTimeInterface $currentPeriodStart = null; #[ORM\Column(type: Types::DATETIME_MUTABLE)] private ?\DateTimeInterface $currentPeriodEnd = null; #[ORM\Column] private ?bool $isActive = null; #[ORM\ManyToOne(inversedBy: 'subscriptions')] private ?Plan $plan = null; #[ORM\ManyToOne(inversedBy: 'subscriptions')] private ?Users $user = null; #[ORM\OneToMany(mappedBy: 'subscription', targetEntity: Invoice::class)] private Collection $invoices; public function __construct() { $this->invoices = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getStripeId(): ?string { return $this->stripeId; } public function setStripeId(?string $stripeId): self { $this->stripeId = $stripeId; return $this; } public function getCurrentPeriodStart(): ?\DateTimeInterface { return $this->currentPeriodStart; } public function setCurrentPeriodStart(?\DateTimeInterface $currentPeriodStart): self { $this->currentPeriodStart = $currentPeriodStart; return $this; } public function getCurrentPeriodEnd(): ?\DateTimeInterface { return $this->currentPeriodEnd; } public function setCurrentPeriodEnd(?\DateTimeInterface $currentPeriodEnd): self { $this->currentPeriodEnd = $currentPeriodEnd; return $this; } public function isIsActive(): ?bool { return $this->isActive; } public function setIsActive(?bool $isActive): self { // Obtenez la date actuelle $currentDate = new \DateTime(); // Comparez la date actuelle avec la date de début et de fin de l'abonnement if ($this->currentPeriodStart <= $currentDate && $currentDate <= $this->currentPeriodEnd) { $this->isActive = true; } else { $this->isActive = false; } return $this; } public function getPlan(): ?Plan { return $this->plan; } public function setPlan(?Plan $plan): self { $this->plan = $plan; return $this; } public function getUser(): ?Users { return $this->user; } public function setUser(?Users $user): self { $this->user = $user; return $this; } /** * @return Collection<int, Invoice> */ public function getInvoices(): Collection { return $this->invoices; } public function addInvoice(Invoice $invoice): self { if (!$this->invoices->contains($invoice)) { $this->invoices->add($invoice); $invoice->setSubscription($this); } return $this; } public function removeInvoice(Invoice $invoice): self { if ($this->invoices->removeElement($invoice)) { // set the owning side to null (unless already changed) if ($invoice->getSubscription() === $this) { $invoice->setSubscription(null); } } return $this; } public function __toString(): string { return $this->id ? (string) $this->id : ''; }}