src/Entity/Catalog/Gift.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Catalog;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Controller\Api\Gift\GetGifts;
  6. use App\Entity\Cart\GiftCart;
  7. use App\Entity\MediaObject\MediaCodeGift;
  8. use App\Entity\MediaObject\MediaGift;
  9. use App\Entity\MediaObject\MediaThumbnailGift;
  10. use App\Repository\Catalog\GiftRepository;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\ORM\Mapping as ORM;
  14. use Gedmo\Timestampable\Traits\TimestampableEntity;
  15. use Ramsey\Uuid\Doctrine\UuidGenerator;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Serializer\Annotation\SerializedName;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. /**
  20.  * @ApiResource(
  21.  *     attributes={
  22.  *          "normalization_context"={
  23.  *              "groups"={
  24.  *                  "Gift:output",
  25.  *                  "Gift:io",
  26.  *              },
  27.  *          },
  28.  *          "denormalization_context"={
  29.  *              "groups"={
  30.  *                  "Gift:input",
  31.  *                  "Gift:io",
  32.  *              },
  33.  *          }
  34.  *      },
  35.  *     collectionOperations={
  36.  *          "get-public"={
  37.  *              "method"="GET",
  38.  *              "path"="/public/gifts",
  39.  *              "access_control"="is_granted('ROLE_PUBLIC')",
  40.  *              "controller"=GetGifts::class,
  41.  *              "defaults"={"_api_receive"=false},
  42.  *          },
  43.  *     },
  44.  *     itemOperations={
  45.  *          "get"={
  46.  *              "method"="GET",
  47.  *              "access_control"="is_granted('ROLE_USER')",
  48.  *          },
  49.  *           "get-gift-public"={
  50.  *              "method"="GET",
  51.  *              "path"="/public/gift/{id}",
  52.  *          },
  53.  *     }
  54.  * )
  55.  *
  56.  * @ORM\Entity(repositoryClass=GiftRepository::class)
  57.  */
  58. class Gift
  59. {
  60.     public const GIFT_TYPE_DEMAT 'demat';
  61.     public const GIFT_TYPE_PHYSIC 'physic';
  62.     public const ARRAY_GIFT_TYPE = [
  63.         self::GIFT_TYPE_PHYSIC,
  64.         self::GIFT_TYPE_DEMAT,
  65.     ];
  66.     /**
  67.      * Hook timestampable behavior
  68.      * updates createdAt, updatedAt fields
  69.      */
  70.     use TimestampableEntity;
  71.     /**
  72.      * @ORM\Id
  73.      * @ORM\Column(type="uuid", unique=true)
  74.      * @ORM\GeneratedValue(strategy="CUSTOM")
  75.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  76.      * @SerializedName("id")
  77.      * @ApiProperty(identifier=true)
  78.      * @Groups({
  79.      *     "Gift:output",
  80.      *     "Order:output",
  81.      *     "get_user_gift_carts",
  82.      *     "get_order_by_user",
  83.      * })
  84.      */
  85.     private string $id;
  86.     /**
  87.      * @ORM\Column(type="integer")
  88.      * @SerializedName("nb_puntos")
  89.      * @Groups({
  90.      *     "Order:output",
  91.      *     "Gift:output",
  92.      *     "get_user_gift_carts",
  93.      * })
  94.      */
  95.     private $nbPuntos;
  96.     /**
  97.      * @ORM\Column(type="integer")
  98.      * @SerializedName("single_buyer_limit")
  99.      * @Groups({
  100.      *     "Gift:output",
  101.      *     "Order:output",
  102.      * })
  103.      */
  104.     private $singleBuyerLimit;
  105.     /**
  106.      * @ORM\Column(type="string", length=255)
  107.      * @SerializedName("label")
  108.      * @Groups({
  109.      *     "Order:output",
  110.      *     "Gift:output",
  111.      *     "get_user_gift_carts",
  112.      * })
  113.      */
  114.     private ?string $label;
  115.     /**
  116.      * @ORM\Column(type="text")
  117.      * @SerializedName("description")
  118.      * @Groups({
  119.      *     "Gift:output",
  120.      *     "Order:output",
  121.      * })
  122.      */
  123.     private ?string $description;
  124.     /**
  125.      * @ORM\Column(type="integer")
  126.      * @SerializedName("stock")
  127.      * @Groups({
  128.      *     "Gift:output",
  129.      *     "Order:output",
  130.      * })
  131.      */
  132.     private $stock;
  133.     /**
  134.      * @ORM\ManyToOne(targetEntity=GiftLevel::class, inversedBy="gifts")
  135.      * @ORM\JoinColumn(nullable=false)
  136.      * @SerializedName("gift_level")
  137.      * @Groups({
  138.      *     "Gift:output",
  139.      *     "GiftLevel:io"
  140.      * })
  141.      */
  142.     private $level;
  143.     /**
  144.      * @var string|null
  145.      * @ORM\Column(name="gift_type", type="string")
  146.      * @SerializedName("gift_type")
  147.      * @Groups({
  148.      *     "Gift:output",
  149.      *     "get_user_gift_carts",
  150.      * })
  151.      */
  152.     private ?string $giftType;
  153.     /**
  154.      * @ORM\Column(type="text", nullable=true)
  155.      * @SerializedName("mail_content")
  156.      * @Groups({
  157.      *     "Gift:output",
  158.      * })
  159.      */
  160.     private $mailContent;
  161.     /**
  162.      * @ORM\OneToMany(targetEntity=MediaGift::class, mappedBy="gift", cascade={"persist"})
  163.      * @SerializedName("media_gifts")
  164.      * @Groups({
  165.      *     "Gift:output",
  166.      *     "MediaGift:io",
  167.      *     "get_user_gift_carts",
  168.      *     "get_order_by_user",
  169.      *     "Order:output",
  170.      * })
  171.      */
  172.     private $mediaGifts;
  173.     /**
  174.      * @ORM\OneToMany(targetEntity=MediaThumbnailGift::class, mappedBy="gift", cascade={"persist"})
  175.      * @SerializedName("media_thumbnail_gifts")
  176.      * @Groups({
  177.      *     "Gift:output",
  178.      *     "MediaThumbnailGift:io",
  179.      *     "get_user_gift_carts",
  180.      *     "get_order_by_user",
  181.      *     "Order:output",
  182.      * })
  183.      */
  184.     private $mediaThumbnailGifts;
  185.     /**
  186.      * @var MediaCodeGift|null
  187.      * @ORM\OneToMany(targetEntity=MediaCodeGift::class, mappedBy="gift", cascade={"persist"})
  188.      * @SerializedName("media_code_gifts")
  189.      * @Groups({
  190.      *     "Blog:output",
  191.      *     "MediaBlog:io"
  192.      * })
  193.      */
  194.     private $mediaCodeGifts;
  195.     /**
  196.      * @ORM\OneToMany(targetEntity=GiftCart::class, mappedBy="gift")
  197.      */
  198.     private Collection $carts;
  199.     /**
  200.      * @ORM\Column(type="text", nullable=true)
  201.      * @SerializedName("transport_reference")
  202.      * @Groups({
  203.      *     "Gift:output",
  204.      * })
  205.      */
  206.     private $transportReference;
  207.     /**
  208.      * @ORM\Column(type="text", nullable=true, length=8)
  209.      * @Assert\Length(
  210.      *     min="8",
  211.      *     max="8",
  212.      * )
  213.      * @SerializedName("bext_reference")
  214.      * @Groups({
  215.      *     "Gift:output",
  216.      * })
  217.      */
  218.     private $bextReference;
  219.     public function __construct()
  220.     {
  221.         $this->mediaGifts = new ArrayCollection();
  222.         $this->mediaThumbnailGifts = new ArrayCollection();
  223.     }
  224.     public function getId(): ?string
  225.     {
  226.         return $this->id;
  227.     }
  228.     public function getMediaGifts()
  229.     {
  230.         return $this->mediaGifts;
  231.     }
  232.     public function setMediaGifts(MediaGift $mediaGift): Gift
  233.     {
  234.         $this->mediaGifts $mediaGift;
  235.         return $this;
  236.     }
  237.     public function addMediaGift(MediaGift $mediaGift)
  238.     {
  239.         if ($this->mediaGifts->contains($mediaGift)) {
  240.             return;
  241.         }
  242.         $this->mediaGifts[] = $mediaGift;
  243.         $mediaGift->setGift($this);
  244.     }
  245.     public function getMediaThumbnailGifts()
  246.     {
  247.         return $this->mediaThumbnailGifts;
  248.     }
  249.     public function setMediaThumbnailGifts(MediaThumbnailGift $mediaThumbnailGift): Gift
  250.     {
  251.         $this->mediaThumbnailGifts $mediaThumbnailGift;
  252.         return $this;
  253.     }
  254.     public function addMediaThumbnailGift(MediaThumbnailGift $mediaThumbnailGift)
  255.     {
  256.         if ($this->mediaThumbnailGifts->contains($mediaThumbnailGift)) {
  257.             return;
  258.         }
  259.         $this->mediaThumbnailGifts[] = $mediaThumbnailGift;
  260.         $mediaThumbnailGift->setGift($this);
  261.     }
  262.     public function getNbPuntos(): ?int
  263.     {
  264.         return $this->nbPuntos;
  265.     }
  266.     public function setNbPuntos(int $nbPuntos): self
  267.     {
  268.         $this->nbPuntos $nbPuntos;
  269.         return $this;
  270.     }
  271.     public function getSingleBuyerLimit(): ?int
  272.     {
  273.         return $this->singleBuyerLimit;
  274.     }
  275.     public function setSingleBuyerLimit(int $singleBuyerLimit): self
  276.     {
  277.         $this->singleBuyerLimit $singleBuyerLimit;
  278.         return $this;
  279.     }
  280.     public function getLabel(): ?string
  281.     {
  282.         return $this->label;
  283.     }
  284.     public function setLabel(string $label): self
  285.     {
  286.         $this->label $label;
  287.         return $this;
  288.     }
  289.     public function getDescription(): ?string
  290.     {
  291.         return $this->description;
  292.     }
  293.     public function setDescription(string $description): self
  294.     {
  295.         $this->description $description;
  296.         return $this;
  297.     }
  298.     public function getStock(): ?int
  299.     {
  300.         return $this->stock;
  301.     }
  302.     public function setStock(int $stock): self
  303.     {
  304.         $this->stock $stock;
  305.         return $this;
  306.     }
  307.     public function getLevel(): ?GiftLevel
  308.     {
  309.         return $this->level;
  310.     }
  311.     public function setLevel(?GiftLevel $level): self
  312.     {
  313.         $this->level $level;
  314.         return $this;
  315.     }
  316.     public function getGiftType(): ?string
  317.     {
  318.         return $this->giftType;
  319.     }
  320.     public function setGiftType(?string $giftType): self
  321.     {
  322.         $this->giftType $giftType;
  323.         return $this;
  324.     }
  325.     public function getMailContent(): ?string
  326.     {
  327.         return $this->mailContent;
  328.     }
  329.     public function setMailContent(?string $mailContent): self
  330.     {
  331.         $this->mailContent $mailContent;
  332.         return $this;
  333.     }
  334.     /**
  335.      * @return \DateTime
  336.      * @SerializedName("created_at")
  337.      * @Groups({
  338.      *     "Gift:output",
  339.      * })
  340.      */
  341.     public function getSerializedCreatedAt()
  342.     {
  343.         return $this->createdAt;
  344.     }
  345.     public function hasStock(): bool
  346.     {
  347.         return (bool) $this->stock;
  348.     }
  349.     /**
  350.      * @return ?string
  351.      */
  352.     public function getTransportReference(): ?string
  353.     {
  354.         return $this->transportReference;
  355.     }
  356.     /**
  357.      * @param ?string $transportReference
  358.      * @return Gift
  359.      */
  360.     public function setTransportReference(?string $transportReference): self
  361.     {
  362.         $this->transportReference $transportReference;
  363.         return $this;
  364.     }
  365.     /**
  366.      * @return ?string
  367.      */
  368.     public function getBextReference()
  369.     {
  370.         return $this->bextReference;
  371.     }
  372.     /**
  373.      * @param ?string $bextReference
  374.      * @return Gift
  375.      */
  376.     public function setBextReference(?string $bextReference): self
  377.     {
  378.         $this->bextReference $bextReference;
  379.         return $this;
  380.     }
  381. }