src/Entity/Tenant/FreeTrial.php line 50

  1. <?php
  2. namespace App\Entity\Tenant;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Delete;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\GetCollection;
  7. use ApiPlatform\Metadata\Patch;
  8. use ApiPlatform\Metadata\Put;
  9. use App\Controller\Api\StartFreeTrialController;
  10. use App\DTO\FreeTrialInputDTO;
  11. use App\DTO\FreeTrialOutputDTO;
  12. use App\Repository\Tenant\FreeTrialRepository;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\DBAL\Types\Types;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use ApiPlatform\Metadata\Post;
  19. #[ORM\Entity(repositoryClassFreeTrialRepository::class)]
  20. #[ApiResource(
  21.     operations: [
  22.         new Post(
  23.             uriTemplate'/ext/free-trials',
  24.             controllerStartFreeTrialController::class,
  25.             inputFreeTrialInputDTO::class,
  26.             outputFreeTrialOutputDTO::class
  27.         ),
  28.         new Post(
  29.             uriTemplate'/free-trials',
  30.             controllerStartFreeTrialController::class,
  31.             inputFreeTrialInputDTO::class,
  32.             outputFreeTrialOutputDTO::class
  33.         ),
  34.         new Post(
  35.             uriTemplate'/free_trials',
  36.             controllerStartFreeTrialController::class,
  37.             inputFreeTrialInputDTO::class,
  38.             outputFreeTrialOutputDTO::class
  39.         ),
  40.         new GetCollection(),
  41.         new Get(),
  42.         new Patch(),
  43.         new Delete(),
  44.         new Put()
  45.     ])
  46. ]
  47. class FreeTrial
  48. {
  49.     /**
  50.      * visible :list;order:1;
  51.      */
  52.     #[ORM\Id]
  53.     #[ORM\GeneratedValue]
  54.     #[ORM\Column]
  55.     #[Groups(['read'])]
  56.     private ?int $id null;
  57.     /**
  58.      * visible :list;order:1;
  59.      */
  60.     #[ORM\Column]
  61.     #[Groups(['read'])]
  62.     private ?\DateTimeImmutable $createdAt null;
  63.     /**
  64.      * visible :list;order:1;
  65.      */
  66.     #[ORM\Column]
  67.     #[Groups(['read'])]
  68.     private ?\DateTimeImmutable $updatedAt null;
  69.     /**
  70.      * visible :list;order:1;
  71.      */
  72.     #[ORM\Column(typeTypes::DATE_IMMUTABLE)]
  73.     #[Groups(['read''write'])]
  74.     private ?\DateTimeImmutable $finalDate null;
  75.     /**
  76.      * visible :list, form;order:2;oneToOne:true
  77.      */
  78.     #[ORM\OneToOne(inversedBy'freeTrial'cascade: ['persist''remove'])]
  79.     #[ORM\JoinColumn(nullablefalse)]
  80.     private ?Subscriber $subscriber null;
  81.     /**
  82.      * visible :form;order:3;oneToMany:true
  83.      */
  84.     #[ORM\OneToMany(mappedBy'freeTrial'targetEntityEvent::class)]
  85.     #[Groups(['read''write'])]
  86.     private Collection $events;
  87.     public function __construct()
  88.     {
  89.         $this->events = new ArrayCollection();
  90.     }
  91.     public function getId(): ?int
  92.     {
  93.         return $this->id;
  94.     }
  95.     public function getCreatedAt(): ?\DateTimeImmutable
  96.     {
  97.         return $this->createdAt;
  98.     }
  99.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  100.     {
  101.         $this->createdAt $createdAt;
  102.         return $this;
  103.     }
  104.     public function getUpdatedAt(): ?\DateTimeImmutable
  105.     {
  106.         return $this->updatedAt;
  107.     }
  108.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  109.     {
  110.         $this->updatedAt $updatedAt;
  111.         return $this;
  112.     }
  113.     public function getFinalDate(): ?\DateTimeImmutable
  114.     {
  115.         return $this->finalDate;
  116.     }
  117.     public function setFinalDate(\DateTimeImmutable $finalDate): self
  118.     {
  119.         $this->finalDate $finalDate;
  120.         return $this;
  121.     }
  122.     public function getSubscriber(): ?Subscriber
  123.     {
  124.         return $this->subscriber;
  125.     }
  126.     public function setSubscriber(Subscriber $subscriber): self
  127.     {
  128.         $this->subscriber $subscriber;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @return Collection<int, Event>
  133.      */
  134.     public function getEvents(): Collection
  135.     {
  136.         return $this->events;
  137.     }
  138.     public function addEvent(Event $event): self
  139.     {
  140.         if (!$this->events->contains($event)) {
  141.             $this->events->add($event);
  142.             $event->setFreeTrial($this);
  143.         }
  144.         return $this;
  145.     }
  146.     public function removeEvent(Event $event): self
  147.     {
  148.         if ($this->events->removeElement($event)) {
  149.             // set the owning side to null (unless already changed)
  150.             if ($event->getFreeTrial() === $this) {
  151.                 $event->setFreeTrial(null);
  152.             }
  153.         }
  154.         return $this;
  155.     }
  156.     public function isEnabled(): bool
  157.     {
  158.         return $this->finalDate > new \DateTimeImmutable();
  159.     }
  160.     public function __toString(): string
  161.     {
  162.         return "[#" $this->id "] VĂ¡lido hasta " $this->finalDate->format("d/m/o");
  163.     }
  164. }