src/Entity/Tenant/Plan.php line 19
<?php
namespace App\Entity\Tenant;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\Tenant\PlanRepository;
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: PlanRepository::class)]
#[ApiResource(
normalizationContext: ["groups" => ["read"]],
denormalizationContext: ["groups"=> ["write"]]
)]
class Plan
{
/**
* visible :list;order:1;
*/
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read'])]
private ?int $id = null;
/**
* order:1;
*/
#[ORM\Column]
#[ApiProperty]
#[Groups(['read'])]
private ?\DateTimeImmutable $createdAt;
/**
* visible :list;order:1;
*/
#[ORM\Column]
#[Groups(['read'])]
private ?\DateTimeImmutable $updatedAt;
/**
* visible :list, form;order:2;
*/
#[ORM\Column(length: 255)]
#[Groups(['read', 'write'])]
private ?string $name = null;
/**
* visible :list, form;order:4;
*/
#[ORM\Column]
#[Groups(['read', 'write'])]
private ?int $frequencyValue = null;
/**
* visible :list, form;order:5;
*/
#[ORM\Column(length: 255)]
#[Groups(['read', 'write'])]
private ?string $frequencyUnit = null;
/**
* visible :form;order:6;
*/
#[ORM\Column]
#[Groups(['read', 'write'])]
private ?bool $enabled = null;
/**
* visible :form;order:7;
*/
#[ORM\Column(nullable: true)]
#[Groups(['read', 'write'])]
private ?int $deadlineAfterExpiry = null;
/**
* visible :form;order:10;oneToMany:true
*/
#[ORM\OneToMany(mappedBy: 'plan', targetEntity: Subscription::class)]
#[Groups(['read', 'write'])]
private Collection $subscriptions;
/**
* visible :list, form;order:3;
*/
#[ORM\Column]
#[Groups(['read', 'write'])]
private ?float $price = null;
/**
* visible :form;order:8;
*/
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['read', 'write'])]
private ?string $description = null;
/**
* visible :form;order:9;
*/
#[ORM\Column(type: Types::SIMPLE_ARRAY, nullable: true)]
private array $permissions = [];
public function __construct()
{
$this->updatedAt = new \DateTimeImmutable();
$this->createdAt = new \DateTimeImmutable();
$this->subscriptions = new ArrayCollection();
}
public function __toString(): string
{
return $this->name;
}
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 getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getFrequencyValue(): ?int
{
return $this->frequencyValue;
}
public function setFrequencyValue(int $frequencyValue): self
{
$this->frequencyValue = $frequencyValue;
return $this;
}
public function getFrequencyUnit(): ?string
{
return $this->frequencyUnit;
}
public function setFrequencyUnit(string $frequencyUnit): self
{
$this->frequencyUnit = $frequencyUnit;
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getDeadlineAfterExpiry(): ?int
{
return $this->deadlineAfterExpiry;
}
public function setDeadlineAfterExpiry(?int $deadlineAfterExpiry): self
{
$this->deadlineAfterExpiry = $deadlineAfterExpiry;
return $this;
}
/**
* @return Collection<int, Subscription>
*/
public function getSubscriptions(): Collection
{
return $this->subscriptions;
}
public function addSubscription(Subscription $subscription): self
{
if (!$this->subscriptions->contains($subscription)) {
$this->subscriptions->add($subscription);
$subscription->setPlan($this);
}
return $this;
}
public function removeSubscription(Subscription $subscription): self
{
if ($this->subscriptions->removeElement($subscription)) {
// set the owning side to null (unless already changed)
if ($subscription->getPlan() === $this) {
$subscription->setPlan(null);
}
}
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(float $price): self
{
$this->price = $price;
return $this;
}
public function getFrequencyStr(): string
{
return $this->frequencyValue . " " . $this->frequencyUnit;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getPermissions(): array
{
return $this->permissions;
}
public function setPermissions(?array $permissions): self
{
$this->permissions = $permissions;
return $this;
}
}