<?phpnamespace Roothirsch\PimBundle\Entity;use ApiPlatform\Core\Annotation\ApiResource;use Roothirsch\PimBundle\Repository\AttributeGroupRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;/** * @ApiResource( shortName="Pim/AttributeGroup") * @ORM\Entity(repositoryClass=AttributeGroupRepository::class) * @ORM\Table(name="pim_attribute_group") */class AttributeGroup{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $title; /** * @ORM\OneToMany(targetEntity=Attribute::class, mappedBy="attributeGroup", orphanRemoval=true) */ private $attributes; /** * @ORM\ManyToMany(targetEntity=Category::class, mappedBy="attributeGroups") */ private $categories; public function __construct($title = null) { $this->attributes = new ArrayCollection(); $this->categories = new ArrayCollection(); $this->title = $title; } 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|Attribute[] */ public function getAttributes(): Collection { return $this->attributes; } public function addAttribute(Attribute $attribute): self { if (!$this->attributes->contains($attribute)) { $this->attributes[] = $attribute; $attribute->setAttributeGroup($this); } return $this; } public function removeAttribute(Attribute $attribute): self { if ($this->attributes->removeElement($attribute)) { // set the owning side to null (unless already changed) if ($attribute->getAttributeGroup() === $this) { $attribute->setAttributeGroup(null); } } return $this; } /** * @return Collection|Category[] */ public function getCategories(): Collection { return $this->categories; } public function addCategory(Category $category): self { if (!$this->categories->contains($category)) { $this->categories[] = $category; $category->addAttributeGroup($this); } return $this; } public function removeCategory(Category $category): self { if ($this->categories->removeElement($category)) { $category->removeAttributeGroup($this); } return $this; } public function getAttributeByName($name) { foreach($this->attributes as $attribute) { if ($attribute->getName() == $name){ return $attribute; } } return null; }}