src/Entity/Attributes.php line 24

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