src/Entity/Attributes.php line 24

  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''language' => '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''objects: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''objects: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''objects:read''attributes_items: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.     #[Groups(['attributes:read''attributes:write''cat:read',  'product:read''attributes_items:read''site_product:read'])]
  42.     #[ORM\Column(nullabletrue)]
  43.     private ?int $sort 0;
  44.     #[Groups(['cat:read''attributes:read''attributes:write'])]
  45.     #[ORM\Column(nullabletrue)]
  46.     private ?bool $show null;
  47.     #[Groups(['cat:read''attributes:read''attributes:write'])]
  48.     #[ORM\Column(nullabletrue)]
  49.     private ?bool $filter null;
  50.     #[Groups(['attributes:read''attributes:write''product:read'])]
  51.     #[ORM\ManyToOne(inversedBy'attributes')]
  52.     private ?Languages $language null;
  53.     #[Groups(['attributes:read''attributes:write''product:read'])]
  54.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'translations')]
  55.     private ?self $translation null;
  56.     #[Groups(['attributes:read''attributes:write''product:read'])]
  57.     #[ORM\OneToMany(mappedBy'translation'targetEntityself::class)]
  58.     private Collection $translations;
  59.     public function __construct()
  60.     {
  61.         $this->category = new ArrayCollection();
  62.         $this->attributeItems = new ArrayCollection();
  63.         $this->translations = new ArrayCollection();
  64.         
  65.     }
  66.     public function getId(): ?int
  67.     {
  68.         return $this->id;
  69.     }
  70.     public function getName(): ?string
  71.     {
  72.         return $this->name;
  73.     }
  74.     public function setName(string $name): self
  75.     {
  76.         $this->name $name;
  77.         return $this;
  78.     }
  79.     public function getDateEntered(): ?\DateTimeInterface
  80.     {
  81.         return $this->date_entered;
  82.     }
  83.     public function setDateEntered(?\DateTimeInterface $date_entered): self
  84.     {
  85.         $this->date_entered $date_entered;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, Category>
  90.      */
  91.     public function getCategory(): Collection
  92.     {
  93.         return $this->category;
  94.     }
  95.     public function addCategory(Category $category): self
  96.     {
  97.         if (!$this->category->contains($category)) {
  98.             $this->category->add($category);
  99.         }
  100.         return $this;
  101.     }
  102.     public function removeCategory(Category $category): self
  103.     {
  104.         $this->category->removeElement($category);
  105.         return $this;
  106.     }
  107.     public function getSlug(): ?string
  108.     {
  109.         return $this->slug;
  110.     }
  111.     public function setSlug(string $slug): self
  112.     {
  113.         $this->slug $slug;
  114.         return $this;
  115.     }
  116.     /**
  117.      * @return Collection<int, AttributeItems>
  118.      */
  119.     public function getAttributeItems(): Collection
  120.     {
  121.         return $this->attributeItems;
  122.     }
  123.     public function addAttributeItem(AttributeItems $attributeItem): self
  124.     {
  125.         if (!$this->attributeItems->contains($attributeItem)) {
  126.             $this->attributeItems->add($attributeItem);
  127.             $attributeItem->setAttribute($this);
  128.         }
  129.         return $this;
  130.     }
  131.     public function removeAttributeItem(AttributeItems $attributeItem): self
  132.     {
  133.         if ($this->attributeItems->removeElement($attributeItem)) {
  134.             // set the owning side to null (unless already changed)
  135.             if ($attributeItem->getAttribute() === $this) {
  136.                 $attributeItem->setAttribute(null);
  137.             }
  138.         }
  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.     public function getLanguage(): ?Languages
  152.     {
  153.         return $this->language;
  154.     }
  155.     public function setLanguage(?Languages $language): static
  156.     {
  157.         $this->language $language;
  158.         return $this;
  159.     }
  160.     public function isShow(): ?bool
  161.     {
  162.         return $this->show;
  163.     }
  164.     public function setShow(?bool $show): static
  165.     {
  166.         $this->show $show;
  167.         return $this;
  168.     }
  169.     public function getTranslation(): ?self
  170.     {
  171.         return $this->translation;
  172.     }
  173.     public function setTranslation(?self $translation): static
  174.     {
  175.         $this->translation $translation;
  176.         return $this;
  177.     }
  178.     public function isFilter(): ?bool
  179.     {
  180.         return $this->filter;
  181.     }
  182.     public function setFilter(?bool $filter): static
  183.     {
  184.         $this->filter $filter;
  185.         
  186.         return $this;
  187.     }
  188.     
  189.     /**
  190.      * @return Collection<int, self>
  191.      */
  192.     public function getTranslations(): Collection
  193.     {
  194.         return $this->translations;
  195.     }
  196.     public function addTranslation(self $translation): static
  197.     {
  198.         if (!$this->translations->contains($translation)) {
  199.             $this->translations->add($translation);
  200.             $translation->setTranslation($this);
  201.         }
  202.         return $this;
  203.     }
  204.     public function removeTranslation(self $translation): static
  205.     {
  206.         if ($this->translations->removeElement($translation)) {
  207.             // set the owning side to null (unless already changed)
  208.             if ($translation->getTranslation() === $this) {
  209.                 $translation->setTranslation(null);
  210.             }
  211.         }
  212.         return $this;
  213.     }
  214. }