src/Entity/AttributeItems.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\AttributeItemsRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use ApiPlatform\Metadata\ApiFilter;
  9. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[ORM\Entity(repositoryClassAttributeItemsRepository::class)]
  12. #[ApiResource(
  13.     normalizationContext: ['groups' => ['attributes_items:read']],
  14.     denormalizationContext: ['groups' => ['attributes_items:write']],
  15.     order: ['id' => 'DESC'],    
  16. )]
  17. #[ApiFilter(SearchFilter::class, properties: ['name' => 'ipartial''categories.id' => 'exact''product.id' => 'exact'])]
  18. class AttributeItems
  19. {
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column]
  23.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read'])]
  24.     private ?int $id null;
  25.     #[ORM\Column(length255)]
  26.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read'])]
  27.     private ?string $name null;
  28.     #[ORM\Column(length255)]
  29.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read'])]
  30.     private ?string $slug null;
  31.     #[Groups(['attributes_items:read''attributes:read''attributes:write''cat:read''attributes_items:write'])]
  32.     #[ORM\ManyToMany(targetEntityProducts::class, inversedBy'attributeItems')]
  33.     private Collection $product;
  34.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read'])]
  35.     #[ORM\ManyToOne(inversedBy'attributeItems')]
  36.     private ?Attributes $attribute null;
  37.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read'])]
  38.     #[ORM\ManyToMany(targetEntityCategory::class, inversedBy'attributeItems')]
  39.     private Collection $categories;
  40.     public function __construct()
  41.     {
  42.         $this->product = new ArrayCollection();
  43.         $this->categories = new ArrayCollection();
  44.     }
  45.     public function getId(): ?int
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getName(): ?string
  50.     {
  51.         return $this->name;
  52.     }
  53.     public function setName(string $name): self
  54.     {
  55.         $this->name $name;
  56.         return $this;
  57.     }
  58.     public function getSlug(): ?string
  59.     {
  60.         return $this->slug;
  61.     }
  62.     public function setSlug(string $slug): self
  63.     {
  64.         $this->slug $slug;
  65.         return $this;
  66.     }
  67.     /**
  68.      * @return Collection<int, Products>
  69.      */
  70.     public function getProduct(): Collection
  71.     {
  72.         return $this->product;
  73.     }
  74.     public function addProduct(Products $product): self
  75.     {
  76.         if (!$this->product->contains($product)) {
  77.             $this->product->add($product);
  78.         }
  79.         return $this;
  80.     }
  81.     public function removeProduct(Products $product): self
  82.     {
  83.         $this->product->removeElement($product);
  84.         return $this;
  85.     }
  86.     public function getAttribute(): ?Attributes
  87.     {
  88.         return $this->attribute;
  89.     }
  90.     public function setAttribute(?Attributes $attribute): self
  91.     {
  92.         $this->attribute $attribute;
  93.         return $this;
  94.     }
  95.     /**
  96.      * @return Collection<int, Category>
  97.      */
  98.     public function getCategories(): Collection
  99.     {
  100.         return $this->categories;
  101.     }
  102.     public function addCategory(Category $category): self
  103.     {
  104.         if (!$this->categories->contains($category)) {
  105.             $this->categories->add($category);
  106.         }
  107.         return $this;
  108.     }
  109.     public function removeCategory(Category $category): self
  110.     {
  111.         $this->categories->removeElement($category);
  112.         return $this;
  113.     }
  114. }