src/Flexy/ShopBundle/Entity/Product/Attribut.php line 14

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Product;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Repository\Product\AttributRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ApiResource]
  9. #[ORM\Entity(repositoryClassAttributRepository::class)]
  10. #[ORM\Cache(usage:"NONSTRICT_READ_WRITE",region:"append_depend")]
  11. class Attribut implements \Stringable
  12. {
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column(type'integer')]
  16.     private $id;
  17.     #[ORM\Column(type'text'nullabletrue)]
  18.     private ?string $description null;
  19.     #[ORM\Column(type'datetime_immutable'nullabletrue)]
  20.     private ?\DateTimeImmutable $createdAt null;
  21.     #[ORM\Column(type'string'length255)]
  22.     private ?string $name null;
  23.     #[ORM\Column(type'string'length255nullabletrue)]
  24.     private ?string $type "text";
  25.     #[ORM\OneToMany(targetEntityAttributValue::class, mappedBy'attribut',cascade:["remove","persist"])]
  26.     private \Doctrine\Common\Collections\Collection|array $attributValues;
  27.     #[ORM\ManyToMany(targetEntityCategoryProduct::class, mappedBy'attributes')]
  28.     private \Doctrine\Common\Collections\Collection|array $categoriesProduct;
  29.     public function __construct()
  30.     {
  31.         $this->attributValues = new ArrayCollection();
  32.         $this->categoriesProduct = new ArrayCollection();
  33.     }
  34.     public function __toString(): string
  35.     {
  36.         return (string) $this->name;
  37.     }
  38.     public function getId(): ?int
  39.     {
  40.         return $this->id;
  41.     }
  42.     public function getDescription(): ?string
  43.     {
  44.         return $this->description;
  45.     }
  46.     public function setDescription(?string $description): self
  47.     {
  48.         $this->description $description;
  49.         return $this;
  50.     }
  51.     public function getCreatedAt(): ?\DateTimeImmutable
  52.     {
  53.         return $this->createdAt;
  54.     }
  55.     public function setCreatedAt(?\DateTimeImmutable $createdAt): self
  56.     {
  57.         $this->createdAt $createdAt;
  58.         return $this;
  59.     }
  60.     public function getName(): ?string
  61.     {
  62.         return $this->name;
  63.     }
  64.     public function setName(string $name): self
  65.     {
  66.         $this->name $name;
  67.         return $this;
  68.     }
  69.     public function getType(): ?string
  70.     {
  71.         return $this->type;
  72.     }
  73.     public function setType(?string $type): self
  74.     {
  75.         $this->type $type;
  76.         return $this;
  77.     }
  78.     /**
  79.      * @return Collection|AttributValue[]
  80.      */
  81.     public function getAttributValues(): Collection
  82.     {
  83.         return $this->attributValues;
  84.     }
  85.     public function addAttributValue(AttributValue $attributValue): self
  86.     {
  87.         if (!$this->attributValues->contains($attributValue)) {
  88.             $this->attributValues[] = $attributValue;
  89.             $attributValue->setAttribut($this);
  90.         }
  91.         return $this;
  92.     }
  93.     public function removeAttributValue(AttributValue $attributValue): self
  94.     {
  95.         if ($this->attributValues->removeElement($attributValue)) {
  96.             // set the owning side to null (unless already changed)
  97.             if ($attributValue->getAttribut() === $this) {
  98.                 $attributValue->setAttribut(null);
  99.             }
  100.         }
  101.         return $this;
  102.     }
  103.     /**
  104.      * @return Collection|CategoryProduct[]
  105.      */
  106.     public function getCategoriesProduct(): Collection
  107.     {
  108.         return $this->categoriesProduct;
  109.     }
  110.     public function addCategoriesProduct(CategoryProduct $categoriesProduct): self
  111.     {
  112.         if (!$this->categoriesProduct->contains($categoriesProduct)) {
  113.             $this->categoriesProduct[] = $categoriesProduct;
  114.             $categoriesProduct->addAttribute($this);
  115.         }
  116.         return $this;
  117.     }
  118.     public function removeCategoriesProduct(CategoryProduct $categoriesProduct): self
  119.     {
  120.         if ($this->categoriesProduct->removeElement($categoriesProduct)) {
  121.             $categoriesProduct->removeAttribute($this);
  122.         }
  123.         return $this;
  124.     }
  125. }