src/Entity/AttributeItems.php line 22

  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. use ApiPlatform\Serializer\Filter\GroupFilter;
  12. #[ORM\Entity(repositoryClassAttributeItemsRepository::class)]
  13. #[ApiResource(
  14.     normalizationContext: ['groups' => ['attributes_items:read']],
  15.     denormalizationContext: ['groups' => ['attributes_items:write']],
  16.     order: ['sort' => 'ASC''name' => 'ASC'],    
  17. )]
  18. #[ApiFilter(SearchFilter::class, properties: [
  19.     'name' => 'ipartial'
  20.     'categories.id' => 'exact'
  21.     'product.id' => 'exact',  
  22.     'attribute.id' => 'exact',  
  23.     'product.site_product.id' => 'exact'
  24.     'objects.attributeItems.id' => 'exact'
  25. ])]
  26. #[ApiFilter(GroupFilter::class, arguments: ['parameterName' => 'g''overrideDefaultGroups' => true])]
  27. class AttributeItems
  28. {
  29.     #[ORM\Id]
  30.     #[ORM\GeneratedValue]
  31.     #[ORM\Column]
  32.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read''site_product:read''objects:read''cat:read''scanning:read'])]
  33.     private ?int $id null;
  34.     #[ORM\Column(length255)]
  35.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read''site_product:read''objects:read''cat:read''scanning:read'])]
  36.     private ?string $name null;
  37.     #[ORM\Column(length255)]
  38.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read''site_product:read''objects:read''cat:read''scanning:read'])]
  39.     private ?string $slug null;
  40.     #[Groups(['attributes_items:product''attributes_items:write' ])]
  41.     #[ORM\ManyToMany(targetEntityProducts::class, inversedBy'attributeItems'cascade:['persist''remove'])]
  42.     private Collection $product;
  43.     #[Groups(['attributes_items:read''attributes:write''attributes_items:write''product:read''site_product:read''objects:read''cat:read''scanning:read'])]
  44.     #[ORM\ManyToOne(inversedBy'attributeItems')]
  45.     private ?Attributes $attribute null;
  46.     #[Groups(['attributes_items:categories''attributes:read''attributes:write''attributes_items:write''objects:read'])]
  47.     #[ORM\ManyToMany(targetEntityCategory::class, inversedBy'attributeItems')]
  48.     private Collection $categories;
  49.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read''site_product:read''objects:read''scanning:read'])]
  50.     #[ORM\Column(nullabletrue)]
  51.     private ?int $sort 0;
  52.     #[ORM\ManyToMany(targetEntityProjects::class, mappedBy'attribute_items')]
  53.     private Collection $projects;
  54.     #[ORM\ManyToMany(targetEntityObjects::class, mappedBy'attributeItems')]
  55.     private Collection $objects;
  56.     /**
  57.      * @var Collection<int, Scannings>
  58.      */
  59.     #[ORM\ManyToMany(targetEntityScannings::class, mappedBy'attributeItems')]
  60.     private Collection $scannings;
  61.     #[Groups(['attributes_items:read''attributes:read''attributes:write''attributes_items:write''product:read''site_product:read''objects:read''cat:read''scanning:read'])]
  62.     #[ORM\Column(nullabletrue)]
  63.     private ?bool $main null;
  64.     public function __construct()
  65.     {
  66.         $this->product = new ArrayCollection();
  67.         $this->categories = new ArrayCollection();
  68.         $this->projects = new ArrayCollection();
  69.         $this->objects = new ArrayCollection();
  70.         $this->scannings = new ArrayCollection();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getName(): ?string
  77.     {
  78.         return $this->name;
  79.     }
  80.     public function setName(string $name): self
  81.     {
  82.         $this->name $name;
  83.         return $this;
  84.     }
  85.     public function getSlug(): ?string
  86.     {
  87.         return $this->slug;
  88.     }
  89.     public function setSlug(string $slug): self
  90.     {
  91.         $this->slug $slug;
  92.         return $this;
  93.     }
  94.     /**
  95.      * @return Collection<int, Products>
  96.      */
  97.     public function getProduct(): Collection
  98.     {
  99.         return $this->product;
  100.     }
  101.     public function addProduct(Products $product): self
  102.     {
  103.         if (!$this->product->contains($product)) {
  104.             $this->product->add($product);
  105.         }
  106.         return $this;
  107.     }
  108.     public function removeProduct(Products $product): self
  109.     {
  110.         $this->product->removeElement($product);
  111.         return $this;
  112.     }
  113.     public function getAttribute(): ?Attributes
  114.     {
  115.         return $this->attribute;
  116.     }
  117.     public function setAttribute(?Attributes $attribute): self
  118.     {
  119.         $this->attribute $attribute;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return Collection<int, Category>
  124.      */
  125.     public function getCategories(): Collection
  126.     {
  127.         return $this->categories;
  128.     }
  129.     public function addCategory(Category $category): self
  130.     {
  131.         if (!$this->categories->contains($category)) {
  132.             $this->categories->add($category);
  133.         }
  134.         return $this;
  135.     }
  136.     public function removeCategory(Category $category): self
  137.     {
  138.         $this->categories->removeElement($category);
  139.         return $this;
  140.     }
  141.     public function getSort(): ?int
  142.     {
  143.         return $this->sort;
  144.     }
  145.     public function setSort(?int $sort): self
  146.     {
  147.         $this->sort $sort;
  148.         return $this;
  149.     }
  150.     /**
  151.      * @return Collection<int, Projects>
  152.      */
  153.     public function getProjects(): Collection
  154.     {
  155.         return $this->projects;
  156.     }
  157.     public function addProject(Projects $project): static
  158.     {
  159.         if (!$this->projects->contains($project)) {
  160.             $this->projects->add($project);
  161.             $project->addAttributeItem($this);
  162.         }
  163.         return $this;
  164.     }
  165.     public function removeProject(Projects $project): static
  166.     {
  167.         if ($this->projects->removeElement($project)) {
  168.             $project->removeAttributeItem($this);
  169.         }
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return Collection<int, Objects>
  174.      */
  175.     public function getObjects(): Collection
  176.     {
  177.         return $this->objects;
  178.     }
  179.     public function addObject(Objects $object): static
  180.     {
  181.         if (!$this->objects->contains($object)) {
  182.             $this->objects->add($object);
  183.             $object->addAttributeItem($this);
  184.         }
  185.         return $this;
  186.     }
  187.     public function removeObject(Objects $object): static
  188.     {
  189.         if ($this->objects->removeElement($object)) {
  190.             $object->removeAttributeItem($this);
  191.         }
  192.         return $this;
  193.     }
  194.     /**
  195.      * @return Collection<int, Scannings>
  196.      */
  197.     public function getScannings(): Collection
  198.     {
  199.         return $this->scannings;
  200.     }
  201.     public function addScanning(Scannings $scanning): static
  202.     {
  203.         if (!$this->scannings->contains($scanning)) {
  204.             $this->scannings->add($scanning);
  205.             $scanning->addAttributeItem($this);
  206.         }
  207.         return $this;
  208.     }
  209.     public function removeScanning(Scannings $scanning): static
  210.     {
  211.         if ($this->scannings->removeElement($scanning)) {
  212.             $scanning->removeAttributeItem($this);
  213.         }
  214.         return $this;
  215.     }
  216.     public function isMain(): ?bool
  217.     {
  218.         return $this->main;
  219.     }
  220.     public function setMain(?bool $main): static
  221.     {
  222.         $this->main $main;
  223.         return $this;
  224.     }
  225. }