<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\AttributeItemsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: AttributeItemsRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['attributes_items:read']],
denormalizationContext: ['groups' => ['attributes_items:write']],
order: ['id' => 'DESC'],
)]
#[ApiFilter(SearchFilter::class, properties: ['name' => 'ipartial', 'categories.id' => 'exact', 'product.id' => 'exact'])]
class AttributeItems
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['attributes_items:read', 'attributes:read', 'attributes:write', 'attributes_items:write', 'product:read'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['attributes_items:read', 'attributes:read', 'attributes:write', 'attributes_items:write', 'product:read'])]
private ?string $name = null;
#[ORM\Column(length: 255)]
#[Groups(['attributes_items:read', 'attributes:read', 'attributes:write', 'attributes_items:write', 'product:read'])]
private ?string $slug = null;
#[Groups(['attributes_items:read', 'attributes:read', 'attributes:write', 'cat:read', 'attributes_items:write'])]
#[ORM\ManyToMany(targetEntity: Products::class, inversedBy: 'attributeItems')]
private Collection $product;
#[Groups(['attributes_items:read', 'attributes:read', 'attributes:write', 'attributes_items:write', 'product:read'])]
#[ORM\ManyToOne(inversedBy: 'attributeItems')]
private ?Attributes $attribute = null;
#[Groups(['attributes_items:read', 'attributes:read', 'attributes:write', 'attributes_items:write', 'product:read'])]
#[ORM\ManyToMany(targetEntity: Category::class, inversedBy: 'attributeItems')]
private Collection $categories;
public function __construct()
{
$this->product = new ArrayCollection();
$this->categories = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection<int, Products>
*/
public function getProduct(): Collection
{
return $this->product;
}
public function addProduct(Products $product): self
{
if (!$this->product->contains($product)) {
$this->product->add($product);
}
return $this;
}
public function removeProduct(Products $product): self
{
$this->product->removeElement($product);
return $this;
}
public function getAttribute(): ?Attributes
{
return $this->attribute;
}
public function setAttribute(?Attributes $attribute): self
{
$this->attribute = $attribute;
return $this;
}
/**
* @return Collection<int, Category>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): self
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
}
return $this;
}
public function removeCategory(Category $category): self
{
$this->categories->removeElement($category);
return $this;
}
}