src/Entity/Tenant/Plan.php line 19

  1. <?php
  2. namespace App\Entity\Tenant;
  3. use ApiPlatform\Metadata\ApiProperty;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use App\Repository\Tenant\PlanRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ORM\Entity(repositoryClassPlanRepository::class)]
  12. #[ApiResource(
  13.     normalizationContext: ["groups" => ["read"]],
  14.     denormalizationContext: ["groups"=> ["write"]]
  15. )]
  16. class Plan
  17. {
  18.     /**
  19.      * visible :list;order:1;
  20.      */
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column]
  24.     #[Groups(['read'])]
  25.     private ?int $id null;
  26.     /**
  27.      * order:1;
  28.      */
  29.     #[ORM\Column]
  30.     #[ApiProperty]
  31.     #[Groups(['read'])]
  32.     private ?\DateTimeImmutable $createdAt;
  33.     /**
  34.      * visible :list;order:1;
  35.      */
  36.     #[ORM\Column]
  37.     #[Groups(['read'])]
  38.     private ?\DateTimeImmutable $updatedAt;
  39.     /**
  40.      * visible :list, form;order:2;
  41.      */
  42.     #[ORM\Column(length255)]
  43.     #[Groups(['read''write'])]
  44.     private ?string $name null;
  45.     /**
  46.      * visible :list, form;order:4;
  47.      */
  48.     #[ORM\Column]
  49.     #[Groups(['read''write'])]
  50.     private ?int $frequencyValue null;
  51.     /**
  52.      * visible :list, form;order:5;
  53.      */
  54.     #[ORM\Column(length255)]
  55.     #[Groups(['read''write'])]
  56.     private ?string $frequencyUnit null;
  57.     /**
  58.      * visible :form;order:6;
  59.      */
  60.     #[ORM\Column]
  61.     #[Groups(['read''write'])]
  62.     private ?bool $enabled null;
  63.     /**
  64.      * visible :form;order:7;
  65.      */
  66.     #[ORM\Column(nullabletrue)]
  67.     #[Groups(['read''write'])]
  68.     private ?int $deadlineAfterExpiry null;
  69.     /**
  70.      * visible :form;order:10;oneToMany:true
  71.      */
  72.     #[ORM\OneToMany(mappedBy'plan'targetEntitySubscription::class)]
  73.     #[Groups(['read''write'])]
  74.     private Collection $subscriptions;
  75.     /**
  76.      * visible :list, form;order:3;
  77.      */
  78.     #[ORM\Column]
  79.     #[Groups(['read''write'])]
  80.     private ?float $price null;
  81.     /**
  82.      * visible :form;order:8;
  83.      */
  84.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  85.     #[Groups(['read''write'])]
  86.     private ?string $description null;
  87.     /**
  88.      * visible :form;order:9;
  89.      */
  90.     #[ORM\Column(typeTypes::SIMPLE_ARRAYnullabletrue)]
  91.     private array $permissions = [];
  92.     public function __construct()
  93.     {
  94.         $this->updatedAt = new \DateTimeImmutable();
  95.         $this->createdAt = new \DateTimeImmutable();
  96.         $this->subscriptions = new ArrayCollection();
  97.     }
  98.     public function __toString(): string
  99.     {
  100.         return $this->name;
  101.     }
  102.     public function getId(): ?int
  103.     {
  104.         return $this->id;
  105.     }
  106.     public function getCreatedAt(): ?\DateTimeImmutable
  107.     {
  108.         return $this->createdAt;
  109.     }
  110.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  111.     {
  112.         $this->createdAt $createdAt;
  113.         return $this;
  114.     }
  115.     public function getUpdatedAt(): ?\DateTimeImmutable
  116.     {
  117.         return $this->updatedAt;
  118.     }
  119.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  120.     {
  121.         $this->updatedAt $updatedAt;
  122.         return $this;
  123.     }
  124.     public function getName(): ?string
  125.     {
  126.         return $this->name;
  127.     }
  128.     public function setName(string $name): self
  129.     {
  130.         $this->name $name;
  131.         return $this;
  132.     }
  133.     public function getFrequencyValue(): ?int
  134.     {
  135.         return $this->frequencyValue;
  136.     }
  137.     public function setFrequencyValue(int $frequencyValue): self
  138.     {
  139.         $this->frequencyValue $frequencyValue;
  140.         return $this;
  141.     }
  142.     public function getFrequencyUnit(): ?string
  143.     {
  144.         return $this->frequencyUnit;
  145.     }
  146.     public function setFrequencyUnit(string $frequencyUnit): self
  147.     {
  148.         $this->frequencyUnit $frequencyUnit;
  149.         return $this;
  150.     }
  151.     public function isEnabled(): ?bool
  152.     {
  153.         return $this->enabled;
  154.     }
  155.     public function setEnabled(bool $enabled): self
  156.     {
  157.         $this->enabled $enabled;
  158.         return $this;
  159.     }
  160.     public function getDeadlineAfterExpiry(): ?int
  161.     {
  162.         return $this->deadlineAfterExpiry;
  163.     }
  164.     public function setDeadlineAfterExpiry(?int $deadlineAfterExpiry): self
  165.     {
  166.         $this->deadlineAfterExpiry $deadlineAfterExpiry;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @return Collection<int, Subscription>
  171.      */
  172.     public function getSubscriptions(): Collection
  173.     {
  174.         return $this->subscriptions;
  175.     }
  176.     public function addSubscription(Subscription $subscription): self
  177.     {
  178.         if (!$this->subscriptions->contains($subscription)) {
  179.             $this->subscriptions->add($subscription);
  180.             $subscription->setPlan($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function removeSubscription(Subscription $subscription): self
  185.     {
  186.         if ($this->subscriptions->removeElement($subscription)) {
  187.             // set the owning side to null (unless already changed)
  188.             if ($subscription->getPlan() === $this) {
  189.                 $subscription->setPlan(null);
  190.             }
  191.         }
  192.         return $this;
  193.     }
  194.     public function getPrice(): ?float
  195.     {
  196.         return $this->price;
  197.     }
  198.     public function setPrice(float $price): self
  199.     {
  200.         $this->price $price;
  201.         return $this;
  202.     }
  203.     public function getFrequencyStr(): string
  204.     {
  205.         return $this->frequencyValue " " $this->frequencyUnit;
  206.     }
  207.     public function getDescription(): ?string
  208.     {
  209.         return $this->description;
  210.     }
  211.     public function setDescription(?string $description): self
  212.     {
  213.         $this->description $description;
  214.         return $this;
  215.     }
  216.     public function getPermissions(): array
  217.     {
  218.         return $this->permissions;
  219.     }
  220.     public function setPermissions(?array $permissions): self
  221.     {
  222.         $this->permissions $permissions;
  223.         return $this;
  224.     }
  225. }