src/Entity/Subscription.php line 16
<?phpnamespace App\Entity;use App\Kimia;use App\Repository\SubscriptionRepository;use App\Trait\ArrayableTrait;use DateTime;use DateTimeInterface;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{use ArrayableTrait;#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(type: Types::SMALLINT)]private ?int $state = Kimia::ACTIVE;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private ?DateTimeInterface $nextPaymentAt = null;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]private ?Plan $plan = null;#[ORM\ManyToMany(targetEntity: Option::class)]private Collection $extraOptions;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]private ?User $user = null;#[ORM\Column(type: Types::DATETIME_MUTABLE)]private ?DateTimeInterface $createdAt;#[ORM\Column]private ?float $amount = null;#[ORM\ManyToOne]#[ORM\JoinColumn(nullable: false)]private ?Currency $currency = null;#[ORM\ManyToOne(inversedBy: 'subscriptions')]#[ORM\JoinColumn(nullable: false)]private ?Establishment $establishment = null;public function __construct(){$this->createdAt = new DateTime();$this->extraOptions = new ArrayCollection();}public function getId(): ?int{return $this->id;}public function getState(): ?int{return $this->state;}public function setState(int $state): self{$this->state = $state;return $this;}public function getNextPaymentAt(): ?DateTimeInterface{return $this->nextPaymentAt;}public function getExpirationDays(): bool|int{$dateTime = new DateTime();return $this->nextPaymentAt > $dateTime ? $dateTime->diff($this->nextPaymentAt, true)->days : 0;}public function setNextPaymentAt(DateTimeInterface $nextPaymentAt): self{$this->nextPaymentAt = $nextPaymentAt;return $this;}/*** @throws \Exception*/public function addDuration(int $duration): self{$date = $this->nextPaymentAt ?? new \DateTime();$this->nextPaymentAt = $date->modify("+$duration days");return $this;}public function getPlan(): ?Plan{return $this->plan;}public function setPlan(?Plan $plan): self{$this->plan = $plan;return $this;}public function getOptions(): ArrayCollection|Collection{$options = $this->extraOptions;foreach ($this->plan->getOptions() as $option) {$options->add($option);}return $options;}/*** @return Collection<int, Option>*/public function getExtraOptions(): Collection{return $this->extraOptions;}public function addExtraOption(Option $extraOption): self{if (!$this->extraOptions->contains($extraOption)) {$this->extraOptions->add($extraOption);}return $this;}public function removeExtraOption(Option $extraOption): self{$this->extraOptions->removeElement($extraOption);return $this;}public function getUser(): ?User{return $this->user;}public function setUser(?User $user): self{$this->user = $user;return $this;}public function getCreatedAt(): ?DateTimeInterface{return $this->createdAt;}public function setCreatedAt(DateTimeInterface $createdAt): self{$this->createdAt = $createdAt;return $this;}public function isActive(): bool{return $this->getState() === Kimia::ACTIVE;}public function isPremium(): bool{return $this->getPlan()?->getName() === Kimia::PLAN_PREMIUM;}public function getAmount(): ?float{return $this->amount;}public function setAmount(float $amount): self{$this->amount = $amount;return $this;}public function getCurrency(): ?Currency{return $this->currency;}public function setCurrency(?Currency $currency): self{$this->currency = $currency;return $this;}public function getEstablishment(): ?Establishment{return $this->establishment;}public function setEstablishment(?Establishment $establishment): self{$this->establishment = $establishment;return $this;}}