src/Entity/Tenant/FreeTrial.php line 50
<?php
namespace App\Entity\Tenant;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use App\Controller\Api\StartFreeTrialController;
use App\DTO\FreeTrialInputDTO;
use App\DTO\FreeTrialOutputDTO;
use App\Repository\Tenant\FreeTrialRepository;
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;
use ApiPlatform\Metadata\Post;
#[ORM\Entity(repositoryClass: FreeTrialRepository::class)]
#[ApiResource(
operations: [
new Post(
uriTemplate: '/ext/free-trials',
controller: StartFreeTrialController::class,
input: FreeTrialInputDTO::class,
output: FreeTrialOutputDTO::class
),
new Post(
uriTemplate: '/free-trials',
controller: StartFreeTrialController::class,
input: FreeTrialInputDTO::class,
output: FreeTrialOutputDTO::class
),
new Post(
uriTemplate: '/free_trials',
controller: StartFreeTrialController::class,
input: FreeTrialInputDTO::class,
output: FreeTrialOutputDTO::class
),
new GetCollection(),
new Get(),
new Patch(),
new Delete(),
new Put()
])
]
class FreeTrial
{
/**
* visible :list;order:1;
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read'])]
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;order:1;
*/
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
#[Groups(['read', 'write'])]
private ?\DateTimeImmutable $finalDate = null;
/**
* visible :list, form;order:2;oneToOne:true
*/
#[ORM\OneToOne(inversedBy: 'freeTrial', cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?Subscriber $subscriber = null;
/**
* visible :form;order:3;oneToMany:true
*/
#[ORM\OneToMany(mappedBy: 'freeTrial', targetEntity: Event::class)]
#[Groups(['read', 'write'])]
private Collection $events;
public function __construct()
{
$this->events = 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 getFinalDate(): ?\DateTimeImmutable
{
return $this->finalDate;
}
public function setFinalDate(\DateTimeImmutable $finalDate): self
{
$this->finalDate = $finalDate;
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->setFreeTrial($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->getFreeTrial() === $this) {
$event->setFreeTrial(null);
}
}
return $this;
}
public function isEnabled(): bool
{
return $this->finalDate > new \DateTimeImmutable();
}
public function __toString(): string
{
return "[#" . $this->id . "] VĂ¡lido hasta " . $this->finalDate->format("d/m/o");
}
}