src/Entity/Tenant/Subscription.php line 48
<?php
namespace App\Entity\Tenant;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Controller\Api\CreateSubscriptionController;
use App\Controller\Api\UpdateSubscriptionController;
use App\DTO\SubscriptionInputDTO;
use App\DTO\UpdateSubscriptionInputDTO;
use App\DTO\SubscriptionOutputDTO;
use App\Repository\Tenant\SubscriptionRepository;
use App\Service\ApiPlatform\GeneralSearchFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: SubscriptionRepository::class)]
#[ApiFilter(GeneralSearchFilter::class)]
#[ApiResource(
operations: [
new Post(
controller: CreateSubscriptionController::class,
input: SubscriptionInputDTO::class,
output: SubscriptionOutputDTO::class
),
new Patch(
inputFormats: ['json' => 'application/json'],
controller: UpdateSubscriptionController::class,
input: UpdateSubscriptionInputDTO::class,
output: SubscriptionOutputDTO::class
),
new Get(),
new GetCollection(),
new Delete(),
new Put()
]
)]
class Subscription
{
/**
* visible :list;order:1;
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read'])]
#[ApiProperty(identifier: true)]
private ?int $id = null;
/**
* visible :list;order:1;
*/
#[ORM\Column]
#[Groups(['read'])]
private ?\DateTimeImmutable $createdAt = null;
/**
* visible :list;order:1;
*/
#[ORM\Column]
#[Groups(['read'])]
private ?\DateTimeImmutable $updatedAt = null;
/**
* visible :list, form;order:2;
*/
#[ORM\Column(length: 255)]
#[Groups(['read', 'write'])]
private ?string $status = null;
/**
* visible :list, form;order:3;
*/
#[ORM\Column]
#[Groups(['read', 'write'])]
private ?bool $serviceEnabled = null;
/**
* visible :form;order:6;
*/
#[ORM\Column]
#[Groups(['read', 'write'])]
private ?bool $cancelled = null;
/**
* visible :list, form;order:4;
*/
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
#[Groups(['read', 'write'])]
private ?\DateTimeImmutable $nextRenewalDate = null;
/**
* visible :list, form;order:5;
*/
#[ORM\Column(type: Types::DATE_IMMUTABLE, nullable: true)]
#[Groups(['read', 'write'])]
private ?\DateTimeImmutable $lastRenewalDate = null;
/**
* visible :form;order:7;oneToOne:true
*/
#[ORM\OneToOne(inversedBy: 'subscription', cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?Subscriber $subscriber = null;
/**
* visible :form;order:9;oneToMany:true
*/
#[ORM\OneToMany(mappedBy: 'subscription', targetEntity: Event::class)]
private Collection $events;
/**
* visible :form;order:8;manyToOne:true
*/
#[ORM\ManyToOne(inversedBy: 'subscriptions')]
#[ORM\JoinColumn(nullable: false)]
private ?Plan $plan = null;
/**
* visible :form;order:10;oneToMany:true
*/
#[ORM\OneToMany(mappedBy: 'subscription', targetEntity: Renewal::class)]
private Collection $renewals;
#[ORM\ManyToMany(targetEntity: Module::class, mappedBy: 'subscriptions')]
private Collection $modules;
public function __construct()
{
$this->updatedAt = new \DateTimeImmutable();
$this->createdAt = new \DateTimeImmutable();
$this->events = new ArrayCollection();
$this->renewals = new ArrayCollection();
$this->modules = new ArrayCollection();
}
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 getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function isServiceEnabled(): ?bool
{
return $this->serviceEnabled;
}
public function setServiceEnabled(bool $serviceEnabled): self
{
$this->serviceEnabled = $serviceEnabled;
return $this;
}
public function isCancelled(): ?bool
{
return $this->cancelled;
}
public function setCancelled(bool $cancelled): self
{
$this->cancelled = $cancelled;
return $this;
}
public function getNextRenewalDate(): ?\DateTimeImmutable
{
return $this->nextRenewalDate;
}
public function setNextRenewalDate(?\DateTimeImmutable $nextRenewalDate): self
{
$this->nextRenewalDate = $nextRenewalDate;
return $this;
}
public function getLastRenewalDate(): ?\DateTimeImmutable
{
return $this->lastRenewalDate;
}
public function setLastRenewalDate(?\DateTimeImmutable $lastRenewalDate): self
{
$this->lastRenewalDate = $lastRenewalDate;
return $this;
}
public function getSubscriber(): ?Subscriber
{
return $this->subscriber;
}
public function setSubscriber(Subscriber $subscriber): self
{
$this->subscriber = $subscriber;
return $this;
}
/**
* @return Collection<int, Event>
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events->add($event);
$event->setSubscription($this);
}
return $this;
}
public function removeEvent(Event $event): self
{
if ($this->events->removeElement($event)) {
// set the owning side to null (unless already changed)
if ($event->getSubscription() === $this) {
$event->setSubscription(null);
}
}
return $this;
}
public function getPlan(): ?Plan
{
return $this->plan;
}
public function setPlan(?Plan $plan): self
{
$this->plan = $plan;
return $this;
}
/**
* @return Collection<int, Renewal>
*/
public function getRenewals(): Collection
{
return $this->renewals;
}
public function addRenewal(Renewal $renewal): self
{
if (!$this->renewals->contains($renewal)) {
$this->renewals->add($renewal);
$renewal->setSubscription($this);
}
return $this;
}
public function removeRenewal(Renewal $renewal): self
{
if ($this->renewals->removeElement($renewal)) {
// set the owning side to null (unless already changed)
if ($renewal->getSubscription() === $this) {
$renewal->setSubscription(null);
}
}
return $this;
}
/**
* @return Collection<int, Module>
*/
public function getModules(): Collection
{
return $this->modules;
}
public function addModule(Module $module): static
{
if (!$this->modules->contains($module)) {
$this->modules->add($module);
$module->addSubscription($this);
}
return $this;
}
public function removeModule(Module $module): static
{
if ($this->modules->removeElement($module)) {
$module->removeSubscription($this);
}
return $this;
}
}