<?phpnamespace Roothirsch\DeliveryTimeEstimatorBundle\Entity;use ApiPlatform\Core\Annotation\ApiResource;use ApiPlatform\Core\Annotation\ApiSubresource;use Roothirsch\DeliveryTimeEstimatorBundle\Repository\ProductGroupRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Gedmo\Mapping\Annotation as Gedmo;use Symfony\Component\Serializer\Annotation\Groups;/** * @ApiResource( * shortName="DeliveryTimeEstimator/ProductGroup", * attributes={ * "normalization_context"={"groups"={"read"}} * } * ) * @ORM\Entity * @ORM\Table(name="delivery_time_estimator_product_group") */class ProductGroup{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") * @Groups({"read"}) */ private $id; /** * @ORM\Column(type="string", length=255) * @Groups({"read"}) * @Gedmo\Translatable */ private $title; /** * @Gedmo\SortablePosition * @ORM\Column(name="position", type="integer") * @Groups({"read"}) */ private $position; /** * @ORM\OneToMany(targetEntity=Product::class, mappedBy="productGroup") * @Groups({"read"}) * @ApiSubresource */ private $products; public function __construct() { $this->products = new ArrayCollection(); } public function __toString() { return $this->title; } public function getId(): ?int { return $this->id; } public function getTitle(): ?string { return $this->title; } public function setTitle(string $title): self { $this->title = $title; return $this; } /** * @return Collection|Product[] */ public function getProducts(): Collection { return $this->products; } public function addProduct(Product $product): self { if (!$this->products->contains($product)) { $this->products[] = $product; $product->setproductGroup($this); } return $this; } public function removeProduct(Product $product): self { if ($this->products->removeElement($product)) { // set the owning side to null (unless already changed) if ($product->getproductGroup() === $this) { $product->setproductGroup(null); } } return $this; } /** * Get the value of position */ public function getPosition() { return $this->position; } /** * Set the value of position * * @return self */ public function setPosition($position) { $this->position = $position; return $this; }}