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. * @ORM\OrderBy({"position" = "ASC"})
  45. * @Groups({"read"})
  46. * @ApiSubresource
  47. */
  48. private $products;
  49. public function __construct()
  50. {
  51. $this->products = new ArrayCollection();
  52. }
  53. public function __toString() {
  54. return $this->title;
  55. }
  56. public function getId(): ?int
  57. {
  58. return $this->id;
  59. }
  60. public function getTitle(): ?string
  61. {
  62. return $this->title;
  63. }
  64. public function setTitle(string $title): self
  65. {
  66. $this->title = $title;
  67. return $this;
  68. }
  69. /**
  70. * @return Collection|Product[]
  71. */
  72. public function getProducts(): Collection
  73. {
  74. return $this->products;
  75. }
  76. public function addProduct(Product $product): self
  77. {
  78. if (!$this->products->contains($product)) {
  79. $this->products[] = $product;
  80. $product->setproductGroup($this);
  81. }
  82. return $this;
  83. }
  84. public function removeProduct(Product $product): self
  85. {
  86. if ($this->products->removeElement($product)) {
  87. // set the owning side to null (unless already changed)
  88. if ($product->getproductGroup() === $this) {
  89. $product->setproductGroup(null);
  90. }
  91. }
  92. return $this;
  93. }
  94. /**
  95. * Get the value of position
  96. */
  97. public function getPosition()
  98. {
  99. return $this->position;
  100. }
  101. /**
  102. * Set the value of position
  103. *
  104. * @return self
  105. */
  106. public function setPosition($position)
  107. {
  108. $this->position = $position;
  109. return $this;
  110. }
  111. }