src/Entity/Provider.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Model\Entity;
  4. use App\Repository\ProviderRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassProviderRepository::class)]
  9. class Provider extends Entity
  10. {
  11.     #[ORM\Column(length255)]
  12.     private ?string $name null;
  13.     #[ORM\ManyToMany(targetEntityFamily::class, inversedBy'providers')]
  14.     private Collection $families;
  15.     #[ORM\OneToMany(mappedBy'provider'targetEntityProduct::class)]
  16.     private Collection $products;
  17.     public function __construct(string $name null)
  18.     {
  19.         $this->name $name;
  20.         $this->families = new ArrayCollection();
  21.         $this->products = new ArrayCollection();
  22.     }
  23.     public function getName(): ?string
  24.     {
  25.         return $this->name;
  26.     }
  27.     public function setName(string $name): self
  28.     {
  29.         $this->name $name;
  30.         return $this;
  31.     }
  32.     /**
  33.      * @return Collection<int, Family>
  34.      */
  35.     public function getFamilies(): Collection
  36.     {
  37.         return $this->families;
  38.     }
  39.     public function addFamily(Family $family): self
  40.     {
  41.         if (!$this->families->contains($family)) {
  42.             $this->families->add($family);
  43.         }
  44.         return $this;
  45.     }
  46.     public function removeFamily(Family $family): self
  47.     {
  48.         $this->families->removeElement($family);
  49.         return $this;
  50.     }
  51.     /**
  52.      * @return Collection<int, Product>
  53.      */
  54.     public function getProducts(): Collection
  55.     {
  56.         return $this->products;
  57.     }
  58.     public function addProduct(Product $product): self
  59.     {
  60.         if (!$this->products->contains($product)) {
  61.             $this->products->add($product);
  62.             $product->setProvider($this);
  63.         }
  64.         return $this;
  65.     }
  66.     public function removeProduct(Product $product): self
  67.     {
  68.         if ($this->products->removeElement($product)) {
  69.             // set the owning side to null (unless already changed)
  70.             if ($product->getProvider() === $this) {
  71.                 $product->setProvider(null);
  72.             }
  73.         }
  74.         return $this;
  75.     }
  76.     public function __toString(): string
  77.     {
  78.         return $this->name;
  79.     }
  80. }