src/Flexy/ShopBundle/Entity/Product/ProductSubscription.php line 20
<?php
namespace App\Flexy\ShopBundle\Entity\Product;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Flexy\ShopBundle\Entity\Customer\Customer;
use App\Flexy\ShopBundle\Entity\Order\Order;
use App\Flexy\ShopBundle\Entity\Payment\Payment;
use App\Repository\Flexy\ShopBundle\Entity\Product\ProductSubscriptionRepository;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: ProductSubscriptionRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['read']],
denormalizationContext: ['groups' => ['write']],
)]
class ProductSubscription
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['read','write'])]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'productSubscriptions')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['read','write'])]
private ?Product $product = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Groups(['read','write'])]
private ?\DateTimeInterface $startAt = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
#[Groups(['read','write'])]
private ?\DateTimeInterface $endAt = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
#[Groups(['read','write'])]
private ?string $description = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['read','write'])]
private ?string $status = null;
#[ORM\ManyToOne(inversedBy: 'productSubscriptions')]
private ?Customer $customer = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(['read','write'])]
private ?\DateTimeInterface $createdAt = null;
#[ORM\OneToOne(inversedBy: 'productSubscription', cascade: ['persist', 'remove'])]
private ?Order $relatedOrder = null;
public function __construct()
{
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getProduct(): ?Product
{
return $this->product;
}
public function setProduct(?Product $product): self
{
$this->product = $product;
return $this;
}
public function getStartAt(): ?\DateTimeInterface
{
return $this->startAt;
}
public function setStartAt(\DateTimeInterface $startAt): self
{
$this->startAt = $startAt;
return $this;
}
public function getEndAt(): ?\DateTimeInterface
{
return $this->endAt;
}
public function setEndAt(\DateTimeInterface $endAt): self
{
$this->endAt = $endAt;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function getCustomer(): ?Customer
{
return $this->customer;
}
public function setCustomer(?Customer $customer): self
{
$this->customer = $customer;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getRelatedOrder(): ?Order
{
return $this->relatedOrder;
}
public function setRelatedOrder(?Order $relatedOrder): self
{
$this->relatedOrder = $relatedOrder;
return $this;
}
#[Groups(['read'])]
public function getOrderNumber(){
if(!$this->getRelatedOrder()){
return null;
}
return $this->getRelatedOrder()->getOrderNumber();
}
#[Groups(['read'])]
public function getOrderId(){
if(!$this->getRelatedOrder()){
return null;
}
return $this->getRelatedOrder()->getId();
}
#[Groups(['read'])]
public function getStartAtFormatted(){
return $this->startAt->format("d/m/Y H:i");
}
#[Groups(['read'])]
public function getEndAtFormatted(){
return $this->endAt->format("d/m/Y H:i");
}
}