src/Entity/Range.php line 13

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