vendor/roothirsch/delivery-time-estimator-bundle/Entity/ProductGroup.php line 23

Open in your IDE?
  1. <?php
  2. namespace Roothirsch\DeliveryTimeEstimatorBundle\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiSubresource;
  5. use Roothirsch\DeliveryTimeEstimatorBundle\Repository\ProductGroupRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. /**
  12. * @ApiResource(
  13. * shortName="DeliveryTimeEstimator/ProductGroup",
  14. * attributes={
  15. * "normalization_context"={"groups"={"read"}}
  16. * }
  17. * )
  18. * @ORM\Entity
  19. * @ORM\Table(name="delivery_time_estimator_product_group")
  20. */
  21. class ProductGroup
  22. {
  23. /**
  24. * @ORM\Id
  25. * @ORM\GeneratedValue
  26. * @ORM\Column(type="integer")
  27. * @Groups({"read"})
  28. */
  29. private $id;
  30. /**
  31. * @ORM\Column(type="string", length=255)
  32. * @Groups({"read"})
  33. * @Gedmo\Translatable
  34. */
  35. private $title;
  36. /**
  37. * @Gedmo\SortablePosition
  38. * @ORM\Column(name="position", type="integer")
  39. * @Groups({"read"})
  40. */
  41. private $position;
  42. /**
  43. * @ORM\OneToMany(targetEntity=Product::class, mappedBy="productGroup")
  44. * @Groups({"read"})
  45. * @ApiSubresource
  46. */
  47. private $products;
  48. public function __construct()
  49. {
  50. $this->products = new ArrayCollection();
  51. }
  52. public function __toString() {
  53. return $this->title;
  54. }
  55. public function getId(): ?int
  56. {
  57. return $this->id;
  58. }
  59. public function getTitle(): ?string
  60. {
  61. return $this->title;
  62. }
  63. public function setTitle(string $title): self
  64. {
  65. $this->title = $title;
  66. return $this;
  67. }
  68. /**
  69. * @return Collection|Product[]
  70. */
  71. public function getProducts(): Collection
  72. {
  73. return $this->products;
  74. }
  75. public function addProduct(Product $product): self
  76. {
  77. if (!$this->products->contains($product)) {
  78. $this->products[] = $product;
  79. $product->setproductGroup($this);
  80. }
  81. return $this;
  82. }
  83. public function removeProduct(Product $product): self
  84. {
  85. if ($this->products->removeElement($product)) {
  86. // set the owning side to null (unless already changed)
  87. if ($product->getproductGroup() === $this) {
  88. $product->setproductGroup(null);
  89. }
  90. }
  91. return $this;
  92. }
  93. /**
  94. * Get the value of position
  95. */
  96. public function getPosition()
  97. {
  98. return $this->position;
  99. }
  100. /**
  101. * Set the value of position
  102. *
  103. * @return self
  104. */
  105. public function setPosition($position)
  106. {
  107. $this->position = $position;
  108. return $this;
  109. }
  110. }