src/Entity/Details/Operation/DetailsCoupon.php line 55

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Details\Operation;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\MediaObject\MediaCoupon;
  6. use App\Repository\Details\DetailsCouponRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. use Ramsey\Uuid\Doctrine\UuidGenerator;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Serializer\Annotation\SerializedName;
  14. /**
  15.  * @ApiResource(
  16.  *     attributes={
  17.  *          "normalization_context"={
  18.  *              "groups"={
  19.  *                  "DetailsCoupon:output",
  20.  *                  "DetailsCoupon:io"
  21.  *              }
  22.  *          },
  23.  *          "denormalization_context"={
  24.  *              "groups"={
  25.  *                  "DetailsCoupon:input",
  26.  *                  "DetailsCoupon:io"
  27.  *              }
  28.  *          },
  29.  *      },
  30.  *     collectionOperations={
  31.  *          "post"={
  32.  *              "method"="POST",
  33.  *              "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
  34.  *          },
  35.  *          "get"={
  36.  *              "method"="GET",
  37.  *              "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
  38.  *          },
  39.  *     },
  40.  *     itemOperations={
  41.  *          "put"={
  42.  *              "method"="PUT",
  43.  *              "access_control"="is_granted('ROLE_ADMIN_SOGEC')",
  44.  *          },
  45.  *          "get"={
  46.  *              "method"="GET"
  47.  *          },
  48.  *      }
  49.  * )
  50.  * @ORM\Entity(repositoryClass=DetailsCouponRepository::class)
  51.  */
  52. class DetailsCoupon
  53. {
  54.     /**
  55.      * Hook timestampable behavior
  56.      * updates createdAt, updatedAt fields
  57.      */
  58.     use TimestampableEntity;
  59.     /**
  60.      * @ORM\Id
  61.      * @ORM\Column(type="uuid", unique=true)
  62.      * @ORM\GeneratedValue(strategy="CUSTOM")
  63.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  64.      * @SerializedName("id")
  65.      * @ApiProperty(identifier=true)
  66.      * @Groups({
  67.      *     "DetailsCoupon:output",
  68.      *     "get_all_public_coupons",
  69.      *     "get_coupons_by_user_department",
  70.      * })
  71.      */
  72.     private string $id;
  73.     /**
  74.      * @ORM\Column(type="float")
  75.      * @SerializedName("amount")
  76.      * @Groups({
  77.      *     "DetailsCoupon:io",
  78.      *     "OperationCoupon:io",
  79.      *     "get_all_public_coupons",
  80.      *     "get_coupons_by_user_department",
  81.      * })
  82.      */
  83.     private ?float $amount;
  84.     /**
  85.      * @ORM\OneToOne(targetEntity="App\Entity\Operation\Coupon")
  86.      * @ORM\JoinColumn(name="coupon_id", referencedColumnName="id")
  87.      * @Groups({
  88.      *     "get_all_public_coupons",
  89.      *     "get_coupons_by_user_department",
  90.      * })
  91.      */
  92.     private $coupon;
  93.     /**
  94.      * @var Collection
  95.      * @ORM\OneToMany(targetEntity=MediaCoupon::class, mappedBy="detailsCoupon")
  96.      * @Groups({
  97.      *     "DetailsCoupon:io",
  98.      *     "OperationCoupon:io"
  99.      * })
  100.      */
  101.     private Collection $images;
  102.     /**
  103.      * @SerializedName("image")
  104.      * @Groups({
  105.      *     "DetailsCoupon:output",
  106.      *     "OperationCoupon:output",
  107.      *     "get_all_public_coupons",
  108.      *     "get_coupons_by_user_department",
  109.      * })
  110.      */
  111.     private $image;
  112.     /**
  113.      * @ORM\Column(type="string", length=255)
  114.      * @SerializedName("name")
  115.      *
  116.      * @Groups({
  117.      *     "DetailsCoupon:io",
  118.      *     "OperationCoupon:io",
  119.      *     "get_all_public_coupons",
  120.      *     "get_coupons_by_user_department",
  121.      * })
  122.      */
  123.     private $name;
  124.     /**
  125.      * @ORM\Column(type="text", nullable=true)
  126.      * @SerializedName("description")
  127.      *
  128.      * @Groups({
  129.      *     "DetailsCoupon:io",
  130.      *     "OperationCoupon:io",
  131.      *     "get_all_public_coupons",
  132.      *     "get_coupons_by_user_department",
  133.      * })
  134.      */
  135.     private $description;
  136.     /**
  137.      * @ORM\Column(type="text", nullable=true)
  138.      * @SerializedName("link_extern")
  139.      *
  140.      * @Groups({
  141.      *     "DetailsCoupon:io",
  142.      *     "OperationCoupon:io",
  143.      *     "get_all_public_coupons",
  144.      *     "get_coupons_by_user_department",
  145.      * })
  146.      */
  147.     private $linkExtern;
  148.     public function __construct()
  149.     {
  150.         $this->images = new ArrayCollection();
  151.     }
  152.     public function getId(): ?string
  153.     {
  154.         return $this->id;
  155.     }
  156.     public function getAmount(): ?float
  157.     {
  158.         return $this->amount;
  159.     }
  160.     public function setAmount(?float $amount): self
  161.     {
  162.         $this->amount $amount;
  163.         return $this;
  164.     }
  165.     public function getCoupon()
  166.     {
  167.         return $this->coupon;
  168.     }
  169.     public function setCoupon($coupon)
  170.     {
  171.         $this->coupon $coupon;
  172.         return $this;
  173.     }
  174.     /**
  175.      * @return mixed
  176.      */
  177.     public function getName()
  178.     {
  179.         return $this->name;
  180.     }
  181.     /**
  182.      * @param mixed $name
  183.      */
  184.     public function setName($name): DetailsCoupon
  185.     {
  186.         $this->name $name;
  187.         return $this;
  188.     }
  189.     /**
  190.      * @return mixed
  191.      */
  192.     public function getDescription()
  193.     {
  194.         return $this->description;
  195.     }
  196.     /**
  197.      * @param mixed $description
  198.      */
  199.     public function setDescription($description): DetailsCoupon
  200.     {
  201.         $this->description $description;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return mixed
  206.      */
  207.     public function getLinkExtern()
  208.     {
  209.         return $this->linkExtern;
  210.     }
  211.     /**
  212.      * @param mixed $linkExtern
  213.      */
  214.     public function setLinkExtern($linkExtern): DetailsCoupon
  215.     {
  216.         $this->linkExtern $linkExtern;
  217.         return $this;
  218.     }
  219.     /**
  220.      * @param mixed $image
  221.      */
  222.     public function addImage($image)
  223.     {
  224.         $this->images->add($image);
  225.         // uncomment if you want to update other side
  226.         $image->setDetailsCoupon($this);
  227.     }
  228.     /**
  229.      * @param mixed $image
  230.      */
  231.     public function removeImage($image)
  232.     {
  233.         $this->images->removeElement($image);
  234.         // uncomment if you want to update other side
  235.         //$image->setDetailsCoupon(null);
  236.     }
  237.     /**
  238.      * @return Collection
  239.      */
  240.     public function getImages(): Collection
  241.     {
  242.         return $this->images;
  243.     }
  244.     /**
  245.      * @param Collection $images
  246.      * @return DetailsCoupon
  247.      */
  248.     public function setImages(Collection $images): DetailsCoupon
  249.     {
  250.         $this->images $images;
  251.         return $this;
  252.     }
  253.     /**
  254.      * @return mixed
  255.      */
  256.     public function getImage()
  257.     {
  258.         return $this->images->first();
  259.     }
  260. }