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: ['sort' => 'ASC''name' => 'ASC''attributeItems.sort' => 'ASC''attributeItems.name' => 'ASC'],    
  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''site_product:read'])]
  25.     private ?int $id null;
  26.     #[ORM\Column(length255)]
  27.     #[Groups(['attributes:read''attributes:write''cat:read',  'product:read''attributes_items:read''site_product: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''site_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.     #[ORM\Column(nullabletrue)]
  42.     private ?int $sort null;
  43.     public function __construct()
  44.     {
  45.         $this->category = new ArrayCollection();
  46.         $this->attributeItems = 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 getDateEntered(): ?\DateTimeInterface
  62.     {
  63.         return $this->date_entered;
  64.     }
  65.     public function setDateEntered(?\DateTimeInterface $date_entered): self
  66.     {
  67.         $this->date_entered $date_entered;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @return Collection<int, Category>
  72.      */
  73.     public function getCategory(): Collection
  74.     {
  75.         return $this->category;
  76.     }
  77.     public function addCategory(Category $category): self
  78.     {
  79.         if (!$this->category->contains($category)) {
  80.             $this->category->add($category);
  81.         }
  82.         return $this;
  83.     }
  84.     public function removeCategory(Category $category): self
  85.     {
  86.         $this->category->removeElement($category);
  87.         return $this;
  88.     }
  89.     public function getSlug(): ?string
  90.     {
  91.         return $this->slug;
  92.     }
  93.     public function setSlug(string $slug): self
  94.     {
  95.         $this->slug $slug;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @return Collection<int, AttributeItems>
  100.      */
  101.     public function getAttributeItems(): Collection
  102.     {
  103.         return $this->attributeItems;
  104.     }
  105.     public function addAttributeItem(AttributeItems $attributeItem): self
  106.     {
  107.         if (!$this->attributeItems->contains($attributeItem)) {
  108.             $this->attributeItems->add($attributeItem);
  109.             $attributeItem->setAttribute($this);
  110.         }
  111.         return $this;
  112.     }
  113.     public function removeAttributeItem(AttributeItems $attributeItem): self
  114.     {
  115.         if ($this->attributeItems->removeElement($attributeItem)) {
  116.             // set the owning side to null (unless already changed)
  117.             if ($attributeItem->getAttribute() === $this) {
  118.                 $attributeItem->setAttribute(null);
  119.             }
  120.         }
  121.         return $this;
  122.     }
  123.     public function getSort(): ?int
  124.     {
  125.         return $this->sort;
  126.     }
  127.     public function setSort(int $sort): self
  128.     {
  129.         $this->sort $sort;
  130.         return $this;
  131.     }
  132. }