src/Entity/Tenant/Subscription.php line 48

  1. <?php
  2. namespace App\Entity\Tenant;
  3. use ApiPlatform\Metadata\ApiFilter;
  4. use ApiPlatform\Metadata\ApiProperty;
  5. use ApiPlatform\Metadata\ApiResource;
  6. use ApiPlatform\Metadata\Delete;
  7. use ApiPlatform\Metadata\Get;
  8. use ApiPlatform\Metadata\GetCollection;
  9. use ApiPlatform\Metadata\Patch;
  10. use ApiPlatform\Metadata\Post;
  11. use ApiPlatform\Metadata\Put;
  12. use App\Controller\Api\CreateSubscriptionController;
  13. use App\Controller\Api\UpdateSubscriptionController;
  14. use App\DTO\SubscriptionInputDTO;
  15. use App\DTO\UpdateSubscriptionInputDTO;
  16. use App\DTO\SubscriptionOutputDTO;
  17. use App\Repository\Tenant\SubscriptionRepository;
  18. use App\Service\ApiPlatform\GeneralSearchFilter;
  19. use Doctrine\Common\Collections\ArrayCollection;
  20. use Doctrine\Common\Collections\Collection;
  21. use Doctrine\DBAL\Types\Types;
  22. use Doctrine\ORM\Mapping as ORM;
  23. use Symfony\Component\Serializer\Annotation\Groups;
  24. #[ORM\Entity(repositoryClassSubscriptionRepository::class)]
  25. #[ApiFilter(GeneralSearchFilter::class)]
  26. #[ApiResource(
  27.     operations: [
  28.         new Post(
  29.             controllerCreateSubscriptionController::class,
  30.             inputSubscriptionInputDTO::class,
  31.             outputSubscriptionOutputDTO::class
  32.         ),
  33.         new Patch(
  34.             inputFormats: ['json' => 'application/json'],
  35.             controllerUpdateSubscriptionController::class,
  36.             inputUpdateSubscriptionInputDTO::class,
  37.             outputSubscriptionOutputDTO::class
  38.         ),
  39.         new Get(),
  40.         new GetCollection(),
  41.         new Delete(),
  42.         new Put()
  43.     ]
  44. )]
  45. class Subscription
  46. {
  47.     /**
  48.      * visible :list;order:1;
  49.      */
  50.     #[ORM\Id]
  51.     #[ORM\GeneratedValue]
  52.     #[ORM\Column]
  53.     #[Groups(['read'])]
  54.     #[ApiProperty(identifiertrue)]
  55.     private ?int $id null;
  56.     /**
  57.      * visible :list;order:1;
  58.      */
  59.     #[ORM\Column]
  60.     #[Groups(['read'])]
  61.     private ?\DateTimeImmutable $createdAt null;
  62.     /**
  63.      * visible :list;order:1;
  64.      */
  65.     #[ORM\Column]
  66.     #[Groups(['read'])]
  67.     private ?\DateTimeImmutable $updatedAt null;
  68.     /**
  69.      * visible :list, form;order:2;
  70.      */
  71.     #[ORM\Column(length255)]
  72.     #[Groups(['read''write'])]
  73.     private ?string $status null;
  74.     /**
  75.      * visible :list, form;order:3;
  76.      */
  77.     #[ORM\Column]
  78.     #[Groups(['read''write'])]
  79.     private ?bool $serviceEnabled null;
  80.     /**
  81.      * visible :form;order:6;
  82.      */
  83.     #[ORM\Column]
  84.     #[Groups(['read''write'])]
  85.     private ?bool $cancelled null;
  86.     /**
  87.      * visible :list, form;order:4;
  88.      */
  89.     #[ORM\Column(typeTypes::DATE_IMMUTABLEnullabletrue)]
  90.     #[Groups(['read''write'])]
  91.     private ?\DateTimeImmutable $nextRenewalDate null;
  92.     /**
  93.      * visible :list, form;order:5;
  94.      */
  95.     #[ORM\Column(typeTypes::DATE_IMMUTABLEnullabletrue)]
  96.     #[Groups(['read''write'])]
  97.     private ?\DateTimeImmutable $lastRenewalDate null;
  98.     /**
  99.      * visible :form;order:7;oneToOne:true
  100.      */
  101.     #[ORM\OneToOne(inversedBy'subscription'cascade: ['persist''remove'])]
  102.     #[ORM\JoinColumn(nullablefalse)]
  103.     private ?Subscriber $subscriber null;
  104.     /**
  105.      * visible :form;order:9;oneToMany:true
  106.      */
  107.     #[ORM\OneToMany(mappedBy'subscription'targetEntityEvent::class)]
  108.     private Collection $events;
  109.     /**
  110.      * visible :form;order:8;manyToOne:true
  111.      */
  112.     #[ORM\ManyToOne(inversedBy'subscriptions')]
  113.     #[ORM\JoinColumn(nullablefalse)]
  114.     private ?Plan $plan null;
  115.     /**
  116.      * visible :form;order:10;oneToMany:true
  117.      */
  118.     #[ORM\OneToMany(mappedBy'subscription'targetEntityRenewal::class)]
  119.     private Collection $renewals;
  120.     #[ORM\ManyToMany(targetEntityModule::class, mappedBy'subscriptions')]
  121.     private Collection $modules;
  122.     public function __construct()
  123.     {
  124.         $this->updatedAt = new \DateTimeImmutable();
  125.         $this->createdAt = new \DateTimeImmutable();
  126.         $this->events = new ArrayCollection();
  127.         $this->renewals = new ArrayCollection();
  128.         $this->modules = new ArrayCollection();
  129.     }
  130.     public function getId(): ?int
  131.     {
  132.         return $this->id;
  133.     }
  134.     public function getCreatedAt(): ?\DateTimeImmutable
  135.     {
  136.         return $this->createdAt;
  137.     }
  138.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  139.     {
  140.         $this->createdAt $createdAt;
  141.         return $this;
  142.     }
  143.     public function getUpdatedAt(): ?\DateTimeImmutable
  144.     {
  145.         return $this->updatedAt;
  146.     }
  147.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  148.     {
  149.         $this->updatedAt $updatedAt;
  150.         return $this;
  151.     }
  152.     public function getStatus(): ?string
  153.     {
  154.         return $this->status;
  155.     }
  156.     public function setStatus(string $status): self
  157.     {
  158.         $this->status $status;
  159.         return $this;
  160.     }
  161.     public function isServiceEnabled(): ?bool
  162.     {
  163.         return $this->serviceEnabled;
  164.     }
  165.     public function setServiceEnabled(bool $serviceEnabled): self
  166.     {
  167.         $this->serviceEnabled $serviceEnabled;
  168.         return $this;
  169.     }
  170.     public function isCancelled(): ?bool
  171.     {
  172.         return $this->cancelled;
  173.     }
  174.     public function setCancelled(bool $cancelled): self
  175.     {
  176.         $this->cancelled $cancelled;
  177.         return $this;
  178.     }
  179.     public function getNextRenewalDate(): ?\DateTimeImmutable
  180.     {
  181.         return $this->nextRenewalDate;
  182.     }
  183.     public function setNextRenewalDate(?\DateTimeImmutable $nextRenewalDate): self
  184.     {
  185.         $this->nextRenewalDate $nextRenewalDate;
  186.         return $this;
  187.     }
  188.     public function getLastRenewalDate(): ?\DateTimeImmutable
  189.     {
  190.         return $this->lastRenewalDate;
  191.     }
  192.     public function setLastRenewalDate(?\DateTimeImmutable $lastRenewalDate): self
  193.     {
  194.         $this->lastRenewalDate $lastRenewalDate;
  195.         return $this;
  196.     }
  197.     public function getSubscriber(): ?Subscriber
  198.     {
  199.         return $this->subscriber;
  200.     }
  201.     public function setSubscriber(Subscriber $subscriber): self
  202.     {
  203.         $this->subscriber $subscriber;
  204.         return $this;
  205.     }
  206.     /**
  207.      * @return Collection<int, Event>
  208.      */
  209.     public function getEvents(): Collection
  210.     {
  211.         return $this->events;
  212.     }
  213.     public function addEvent(Event $event): self
  214.     {
  215.         if (!$this->events->contains($event)) {
  216.             $this->events->add($event);
  217.             $event->setSubscription($this);
  218.         }
  219.         return $this;
  220.     }
  221.     public function removeEvent(Event $event): self
  222.     {
  223.         if ($this->events->removeElement($event)) {
  224.             // set the owning side to null (unless already changed)
  225.             if ($event->getSubscription() === $this) {
  226.                 $event->setSubscription(null);
  227.             }
  228.         }
  229.         return $this;
  230.     }
  231.     public function getPlan(): ?Plan
  232.     {
  233.         return $this->plan;
  234.     }
  235.     public function setPlan(?Plan $plan): self
  236.     {
  237.         $this->plan $plan;
  238.         return $this;
  239.     }
  240.     /**
  241.      * @return Collection<int, Renewal>
  242.      */
  243.     public function getRenewals(): Collection
  244.     {
  245.         return $this->renewals;
  246.     }
  247.     public function addRenewal(Renewal $renewal): self
  248.     {
  249.         if (!$this->renewals->contains($renewal)) {
  250.             $this->renewals->add($renewal);
  251.             $renewal->setSubscription($this);
  252.         }
  253.         return $this;
  254.     }
  255.     public function removeRenewal(Renewal $renewal): self
  256.     {
  257.         if ($this->renewals->removeElement($renewal)) {
  258.             // set the owning side to null (unless already changed)
  259.             if ($renewal->getSubscription() === $this) {
  260.                 $renewal->setSubscription(null);
  261.             }
  262.         }
  263.         return $this;
  264.     }
  265.     /**
  266.      * @return Collection<int, Module>
  267.      */
  268.     public function getModules(): Collection
  269.     {
  270.         return $this->modules;
  271.     }
  272.     public function addModule(Module $module): static
  273.     {
  274.         if (!$this->modules->contains($module)) {
  275.             $this->modules->add($module);
  276.             $module->addSubscription($this);
  277.         }
  278.         return $this;
  279.     }
  280.     public function removeModule(Module $module): static
  281.     {
  282.         if ($this->modules->removeElement($module)) {
  283.             $module->removeSubscription($this);
  284.         }
  285.         return $this;
  286.     }
  287. }