src/Entity/Attribute.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AttributeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassAttributeRepository::class)]
  8. class Attribute
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column(type'integer')]
  13.     private ?int $id null;
  14.     #[ORM\Column(type'string'length255)]
  15.     private ?string $name null;
  16.     #[ORM\ManyToMany(targetEntityProduct::class, inversedBy'attributes')]
  17.     private Collection $products;
  18.     #[ORM\OneToMany(mappedBy'attribute'targetEntityProductExtra::class)]
  19.     private Collection $productExtras;
  20.     #[ORM\ManyToMany(targetEntityOrderProduct::class, mappedBy'removeAttribute')]
  21.     private Collection $orderProducts;
  22.     public function __construct()
  23.     {
  24.         $this->products = new ArrayCollection();
  25.         $this->productExtras = new ArrayCollection();
  26.         $this->orderProducts = new ArrayCollection();
  27.     }
  28.     public function __toString(): string
  29.     {
  30.         return $this->getId() . " - " $this->getName();
  31.     }
  32.     public function getId(): ?int
  33.     {
  34.         return $this->id;
  35.     }
  36.     public function getName(): ?string
  37.     {
  38.         return $this->name;
  39.     }
  40.     public function setName(string $name): self
  41.     {
  42.         $this->name $name;
  43.         return $this;
  44.     }
  45.     /**
  46.      * @return Collection<int, Product>
  47.      */
  48.     public function getProducts(): Collection
  49.     {
  50.         return $this->products;
  51.     }
  52.     public function addProduct(Product $product): self
  53.     {
  54.         if (!$this->products->contains($product)) {
  55.             $this->products[] = $product;
  56.         }
  57.         return $this;
  58.     }
  59.     public function removeProduct(Product $product): self
  60.     {
  61.         $this->products->removeElement($product);
  62.         return $this;
  63.     }
  64.     /**
  65.      * @return Collection<int, ProductExtra>
  66.      */
  67.     public function getProductExtras(): Collection
  68.     {
  69.         return $this->productExtras;
  70.     }
  71.     public function addProductExtra(ProductExtra $productExtra): self
  72.     {
  73.         if (!$this->productExtras->contains($productExtra)) {
  74.             $this->productExtras[] = $productExtra;
  75.             $productExtra->setAttribute($this);
  76.         }
  77.         return $this;
  78.     }
  79.     public function removeProductExtra(ProductExtra $productExtra): self
  80.     {
  81.         if ($this->productExtras->removeElement($productExtra)) {
  82.             if ($productExtra->getAttribute() === $this) {
  83.                 $productExtra->setAttribute(null);
  84.             }
  85.         }
  86.         return $this;
  87.     }
  88.     /**
  89.      * @return Collection<int, OrderProduct>
  90.      */
  91.     public function getOrderProducts(): Collection
  92.     {
  93.         return $this->orderProducts;
  94.     }
  95.     public function addOrderProduct(OrderProduct $orderProduct): self
  96.     {
  97.         if (!$this->orderProducts->contains($orderProduct)) {
  98.             $this->orderProducts[] = $orderProduct;
  99.             $orderProduct->addRemoveAttribute($this);
  100.         }
  101.         return $this;
  102.     }
  103.     public function removeOrderProduct(OrderProduct $orderProduct): self
  104.     {
  105.         if ($this->orderProducts->removeElement($orderProduct)) {
  106.             $orderProduct->removeRemoveAttribute($this);
  107.         }
  108.         return $this;
  109.     }
  110. }