<?php
namespace App\Entity\Catalog;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\Api\Gift\GetGifts;
use App\Entity\Cart\GiftCart;
use App\Entity\MediaObject\MediaCodeGift;
use App\Entity\MediaObject\MediaGift;
use App\Entity\MediaObject\MediaThumbnailGift;
use App\Repository\Catalog\GiftRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* attributes={
* "normalization_context"={
* "groups"={
* "Gift:output",
* "Gift:io",
* },
* },
* "denormalization_context"={
* "groups"={
* "Gift:input",
* "Gift:io",
* },
* }
* },
* collectionOperations={
* "get-public"={
* "method"="GET",
* "path"="/public/gifts",
* "access_control"="is_granted('ROLE_PUBLIC')",
* "controller"=GetGifts::class,
* "defaults"={"_api_receive"=false},
* },
* },
* itemOperations={
* "get"={
* "method"="GET",
* "access_control"="is_granted('ROLE_USER')",
* },
* "get-gift-public"={
* "method"="GET",
* "path"="/public/gift/{id}",
* },
* }
* )
*
* @ORM\Entity(repositoryClass=GiftRepository::class)
*/
class Gift
{
public const GIFT_TYPE_DEMAT = 'demat';
public const GIFT_TYPE_PHYSIC = 'physic';
public const ARRAY_GIFT_TYPE = [
self::GIFT_TYPE_PHYSIC,
self::GIFT_TYPE_DEMAT,
];
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @SerializedName("id")
* @ApiProperty(identifier=true)
* @Groups({
* "Gift:output",
* "Order:output",
* "get_user_gift_carts",
* "get_order_by_user",
* })
*/
private string $id;
/**
* @ORM\Column(type="integer")
* @SerializedName("nb_puntos")
* @Groups({
* "Order:output",
* "Gift:output",
* "get_user_gift_carts",
* })
*/
private $nbPuntos;
/**
* @ORM\Column(type="integer")
* @SerializedName("single_buyer_limit")
* @Groups({
* "Gift:output",
* "Order:output",
* })
*/
private $singleBuyerLimit;
/**
* @ORM\Column(type="string", length=255)
* @SerializedName("label")
* @Groups({
* "Order:output",
* "Gift:output",
* "get_user_gift_carts",
* })
*/
private ?string $label;
/**
* @ORM\Column(type="text")
* @SerializedName("description")
* @Groups({
* "Gift:output",
* "Order:output",
* })
*/
private ?string $description;
/**
* @ORM\Column(type="integer")
* @SerializedName("stock")
* @Groups({
* "Gift:output",
* "Order:output",
* })
*/
private $stock;
/**
* @ORM\ManyToOne(targetEntity=GiftLevel::class, inversedBy="gifts")
* @ORM\JoinColumn(nullable=false)
* @SerializedName("gift_level")
* @Groups({
* "Gift:output",
* "GiftLevel:io"
* })
*/
private $level;
/**
* @var string|null
* @ORM\Column(name="gift_type", type="string")
* @SerializedName("gift_type")
* @Groups({
* "Gift:output",
* "get_user_gift_carts",
* })
*/
private ?string $giftType;
/**
* @ORM\Column(type="text", nullable=true)
* @SerializedName("mail_content")
* @Groups({
* "Gift:output",
* })
*/
private $mailContent;
/**
* @ORM\OneToMany(targetEntity=MediaGift::class, mappedBy="gift", cascade={"persist"})
* @SerializedName("media_gifts")
* @Groups({
* "Gift:output",
* "MediaGift:io",
* "get_user_gift_carts",
* "get_order_by_user",
* "Order:output",
* })
*/
private $mediaGifts;
/**
* @ORM\OneToMany(targetEntity=MediaThumbnailGift::class, mappedBy="gift", cascade={"persist"})
* @SerializedName("media_thumbnail_gifts")
* @Groups({
* "Gift:output",
* "MediaThumbnailGift:io",
* "get_user_gift_carts",
* "get_order_by_user",
* "Order:output",
* })
*/
private $mediaThumbnailGifts;
/**
* @var MediaCodeGift|null
* @ORM\OneToMany(targetEntity=MediaCodeGift::class, mappedBy="gift", cascade={"persist"})
* @SerializedName("media_code_gifts")
* @Groups({
* "Blog:output",
* "MediaBlog:io"
* })
*/
private $mediaCodeGifts;
/**
* @ORM\OneToMany(targetEntity=GiftCart::class, mappedBy="gift")
*/
private Collection $carts;
/**
* @ORM\Column(type="text", nullable=true)
* @SerializedName("transport_reference")
* @Groups({
* "Gift:output",
* })
*/
private $transportReference;
/**
* @ORM\Column(type="text", nullable=true, length=8)
* @Assert\Length(
* min="8",
* max="8",
* )
* @SerializedName("bext_reference")
* @Groups({
* "Gift:output",
* })
*/
private $bextReference;
public function __construct()
{
$this->mediaGifts = new ArrayCollection();
$this->mediaThumbnailGifts = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getMediaGifts()
{
return $this->mediaGifts;
}
public function setMediaGifts(MediaGift $mediaGift): Gift
{
$this->mediaGifts = $mediaGift;
return $this;
}
public function addMediaGift(MediaGift $mediaGift)
{
if ($this->mediaGifts->contains($mediaGift)) {
return;
}
$this->mediaGifts[] = $mediaGift;
$mediaGift->setGift($this);
}
public function getMediaThumbnailGifts()
{
return $this->mediaThumbnailGifts;
}
public function setMediaThumbnailGifts(MediaThumbnailGift $mediaThumbnailGift): Gift
{
$this->mediaThumbnailGifts = $mediaThumbnailGift;
return $this;
}
public function addMediaThumbnailGift(MediaThumbnailGift $mediaThumbnailGift)
{
if ($this->mediaThumbnailGifts->contains($mediaThumbnailGift)) {
return;
}
$this->mediaThumbnailGifts[] = $mediaThumbnailGift;
$mediaThumbnailGift->setGift($this);
}
public function getNbPuntos(): ?int
{
return $this->nbPuntos;
}
public function setNbPuntos(int $nbPuntos): self
{
$this->nbPuntos = $nbPuntos;
return $this;
}
public function getSingleBuyerLimit(): ?int
{
return $this->singleBuyerLimit;
}
public function setSingleBuyerLimit(int $singleBuyerLimit): self
{
$this->singleBuyerLimit = $singleBuyerLimit;
return $this;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getStock(): ?int
{
return $this->stock;
}
public function setStock(int $stock): self
{
$this->stock = $stock;
return $this;
}
public function getLevel(): ?GiftLevel
{
return $this->level;
}
public function setLevel(?GiftLevel $level): self
{
$this->level = $level;
return $this;
}
public function getGiftType(): ?string
{
return $this->giftType;
}
public function setGiftType(?string $giftType): self
{
$this->giftType = $giftType;
return $this;
}
public function getMailContent(): ?string
{
return $this->mailContent;
}
public function setMailContent(?string $mailContent): self
{
$this->mailContent = $mailContent;
return $this;
}
/**
* @return \DateTime
* @SerializedName("created_at")
* @Groups({
* "Gift:output",
* })
*/
public function getSerializedCreatedAt()
{
return $this->createdAt;
}
public function hasStock(): bool
{
return (bool) $this->stock;
}
/**
* @return ?string
*/
public function getTransportReference(): ?string
{
return $this->transportReference;
}
/**
* @param ?string $transportReference
* @return Gift
*/
public function setTransportReference(?string $transportReference): self
{
$this->transportReference = $transportReference;
return $this;
}
/**
* @return ?string
*/
public function getBextReference()
{
return $this->bextReference;
}
/**
* @param ?string $bextReference
* @return Gift
*/
public function setBextReference(?string $bextReference): self
{
$this->bextReference = $bextReference;
return $this;
}
}