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: ['sort' => 'ASC''name' => 'ASC'],    
  16. )]
  17. #[ApiFilter(SearchFilter::class, properties: ['name' => 'ipartial''categories.id' => 'exact''product.id' => 'exact',  'attribute.id' => 'exact',  'product.site_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''site_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''site_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''site_product:read'])]
  30.     private ?string $slug null;
  31.     #[Groups(['attributes_items:read''attributes:write''attributes_items:write'])]
  32.     #[ORM\ManyToMany(targetEntityProducts::class, inversedBy'attributeItems'cascade:['persist''remove'])]
  33.     private Collection $product;
  34.     #[Groups(['attributes_items:read''attributes:write''attributes_items:write''product:read''site_product:read'])]
  35.     #[ORM\ManyToOne(inversedBy'attributeItems')]
  36.     private ?Attributes $attribute null;
  37.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write'])]
  38.     #[ORM\ManyToMany(targetEntityCategory::class, inversedBy'attributeItems')]
  39.     private Collection $categories;
  40.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read''site_product:read'])]
  41.     #[ORM\Column(nullabletrue)]
  42.     private ?int $sort 0;
  43.     public function __construct()
  44.     {
  45.         $this->product = new ArrayCollection();
  46.         $this->categories = new ArrayCollection();
  47.     }
  48.     public function getId(): ?int
  49.     {
  50.         return $this->id;
  51.     }
  52.     public function getName(): ?string
  53.     {
  54.         return $this->name;
  55.     }
  56.     public function setName(string $name): self
  57.     {
  58.         $this->name $name;
  59.         return $this;
  60.     }
  61.     public function getSlug(): ?string
  62.     {
  63.         return $this->slug;
  64.     }
  65.     public function setSlug(string $slug): self
  66.     {
  67.         $this->slug $slug;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @return Collection<int, Products>
  72.      */
  73.     public function getProduct(): Collection
  74.     {
  75.         return $this->product;
  76.     }
  77.     public function addProduct(Products $product): self
  78.     {
  79.         if (!$this->product->contains($product)) {
  80.             $this->product->add($product);
  81.         }
  82.         return $this;
  83.     }
  84.     public function removeProduct(Products $product): self
  85.     {
  86.         $this->product->removeElement($product);
  87.         return $this;
  88.     }
  89.     public function getAttribute(): ?Attributes
  90.     {
  91.         return $this->attribute;
  92.     }
  93.     public function setAttribute(?Attributes $attribute): self
  94.     {
  95.         $this->attribute $attribute;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return Collection<int, Category>
  100.      */
  101.     public function getCategories(): Collection
  102.     {
  103.         return $this->categories;
  104.     }
  105.     public function addCategory(Category $category): self
  106.     {
  107.         if (!$this->categories->contains($category)) {
  108.             $this->categories->add($category);
  109.         }
  110.         return $this;
  111.     }
  112.     public function removeCategory(Category $category): self
  113.     {
  114.         $this->categories->removeElement($category);
  115.         return $this;
  116.     }
  117.     public function getSort(): ?int
  118.     {
  119.         return $this->sort;
  120.     }
  121.     public function setSort(?int $sort): self
  122.     {
  123.         $this->sort $sort;
  124.         return $this;
  125.     }
  126. }