src/Flexy/ShopBundle/Entity/Product/ProductSubscription.php line 20

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Entity\Customer\Customer;
  5. use App\Flexy\ShopBundle\Entity\Order\Order;
  6. use App\Flexy\ShopBundle\Entity\Payment\Payment;
  7. use App\Repository\Flexy\ShopBundle\Entity\Product\ProductSubscriptionRepository;
  8. use DateTime;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. #[ORM\Entity(repositoryClassProductSubscriptionRepository::class)]
  13. #[ApiResource(
  14.     normalizationContext: ['groups' => ['read']],
  15.     denormalizationContext: ['groups' => ['write']],
  16. )]
  17. class ProductSubscription
  18. {
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column]
  22.     #[Groups(['read','write'])]
  23.     private ?int $id null;
  24.     #[ORM\ManyToOne(inversedBy'productSubscriptions')]
  25.     #[ORM\JoinColumn(nullablefalse)]
  26.     #[Groups(['read','write'])]
  27.     private ?Product $product null;
  28.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  29.     #[Groups(['read','write'])]
  30.     private ?\DateTimeInterface $startAt null;
  31.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  32.     #[Groups(['read','write'])]
  33.     private ?\DateTimeInterface $endAt null;
  34.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  35.     #[Groups(['read','write'])]
  36.     private ?string $description null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     #[Groups(['read','write'])]
  39.     private ?string $status null;
  40.   
  41.     #[ORM\ManyToOne(inversedBy'productSubscriptions')]
  42.     private ?Customer $customer null;
  43.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  44.     #[Groups(['read','write'])]
  45.     private ?\DateTimeInterface $createdAt null;
  46.     #[ORM\OneToOne(inversedBy'productSubscription'cascade: ['persist''remove'])]
  47.    
  48.     private ?Order $relatedOrder null;
  49.     public function __construct()
  50.     {
  51.         $this->createdAt = new \DateTime();
  52.     }
  53.     public function getId(): ?int
  54.     {
  55.         return $this->id;
  56.     }
  57.     public function getProduct(): ?Product
  58.     {
  59.         return $this->product;
  60.     }
  61.     public function setProduct(?Product $product): self
  62.     {
  63.         $this->product $product;
  64.         return $this;
  65.     }
  66.     public function getStartAt(): ?\DateTimeInterface
  67.     {
  68.         return $this->startAt;
  69.     }
  70.     public function setStartAt(\DateTimeInterface $startAt): self
  71.     {
  72.         $this->startAt $startAt;
  73.         return $this;
  74.     }
  75.     public function getEndAt(): ?\DateTimeInterface
  76.     {
  77.         return $this->endAt;
  78.     }
  79.     public function setEndAt(\DateTimeInterface $endAt): self
  80.     {
  81.         $this->endAt $endAt;
  82.         return $this;
  83.     }
  84.     public function getDescription(): ?string
  85.     {
  86.         return $this->description;
  87.     }
  88.     public function setDescription(?string $description): self
  89.     {
  90.         $this->description $description;
  91.         return $this;
  92.     }
  93.     public function getStatus(): ?string
  94.     {
  95.         return $this->status;
  96.     }
  97.     public function setStatus(?string $status): self
  98.     {
  99.         $this->status $status;
  100.         return $this;
  101.     }
  102.     public function getCustomer(): ?Customer
  103.     {
  104.         return $this->customer;
  105.     }
  106.     public function setCustomer(?Customer $customer): self
  107.     {
  108.         $this->customer $customer;
  109.         return $this;
  110.     }
  111.     public function getCreatedAt(): ?\DateTimeInterface
  112.     {
  113.         return $this->createdAt;
  114.     }
  115.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  116.     {
  117.         $this->createdAt $createdAt;
  118.         return $this;
  119.     }
  120.     public function getRelatedOrder(): ?Order
  121.     {
  122.         return $this->relatedOrder;
  123.     }
  124.     public function setRelatedOrder(?Order $relatedOrder): self
  125.     {
  126.         $this->relatedOrder $relatedOrder;
  127.         return $this;
  128.     }
  129.     #[Groups(['read'])]
  130.     public function getOrderNumber(){
  131.         if(!$this->getRelatedOrder()){
  132.             return  null;
  133.         }
  134.         return $this->getRelatedOrder()->getOrderNumber();
  135.     }
  136.     
  137.     #[Groups(['read'])]
  138.     public function getOrderId(){
  139.         if(!$this->getRelatedOrder()){
  140.             return  null;
  141.         }
  142.         return $this->getRelatedOrder()->getId();
  143.     }
  144.     #[Groups(['read'])]
  145.     public function getStartAtFormatted(){
  146.         return $this->startAt->format("d/m/Y H:i");
  147.     }
  148.     #[Groups(['read'])]
  149.     public function getEndAtFormatted(){
  150.         return $this->endAt->format("d/m/Y H:i");
  151.     }
  152. }