src/Entity/Catalog/GiftLevel.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Catalog;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Catalog\GiftLevelRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Serializer\Annotation\SerializedName;
  10. /**
  11.  * @ORM\Entity(repositoryClass=GiftLevelRepository::class)
  12.  * @ApiResource(
  13.  *     collectionOperations={"get"},
  14.  *     itemOperations={"get"},
  15.  * )
  16.  */
  17. class GiftLevel
  18. {
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      * @Groups({
  24.      *     "Gift:output",
  25.      * })
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\Column(type="string", length=255)
  30.      * @SerializedName("label")
  31.      * @Groups({
  32.      *     "Gift:output",
  33.      * })
  34.      */
  35.     private $label;
  36.     /**
  37.      * @ORM\Column(type="text", nullable=true)
  38.      * @SerializedName("description")
  39.      * @Groups({
  40.      *     "Gift:output",
  41.      * })
  42.      */
  43.     private $description;
  44.     /**
  45.      * @ORM\OneToMany(targetEntity=Gift::class, mappedBy="level")
  46.      */
  47.     private $gifts;
  48.     public function __construct()
  49.     {
  50.         $this->gifts = new ArrayCollection();
  51.     }
  52.     /**
  53.      * @return mixed
  54.      */
  55.     public function getId()
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getLabel(): ?string
  60.     {
  61.         return $this->label;
  62.     }
  63.     public function setLabel(string $label): self
  64.     {
  65.         $this->label $label;
  66.         return $this;
  67.     }
  68.     public function getDescription(): ?string
  69.     {
  70.         return $this->description;
  71.     }
  72.     public function setDescription(?string $description): self
  73.     {
  74.         $this->description $description;
  75.         return $this;
  76.     }
  77.     /**
  78.      * @return Collection|Gift[]
  79.      */
  80.     public function getGifts(): Collection
  81.     {
  82.         return $this->gifts;
  83.     }
  84.     public function addGift(Gift $gift): self
  85.     {
  86.         if (!$this->gifts->contains($gift)) {
  87.             $this->gifts[] = $gift;
  88.             $gift->setLevel($this);
  89.         }
  90.         return $this;
  91.     }
  92.     public function removeGift(Gift $gift): self
  93.     {
  94.         if ($this->gifts->removeElement($gift)) {
  95.             // set the owning side to null (unless already changed)
  96.             if ($gift->getLevel() === $this) {
  97.                 $gift->setLevel(null);
  98.             }
  99.         }
  100.         return $this;
  101.     }
  102.     public function __toString()
  103.     {
  104.         return $this->label;
  105.     }
  106. }