src/Entity/Category.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  9.  */
  10. class Category
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="category")
  24.      */
  25.     private $products;
  26.     public function __construct()
  27.     {
  28.         $this->products = new ArrayCollection();
  29.     }
  30.     public function __toString(){
  31.         return $this->getName();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getName(): ?string
  38.     {
  39.         return $this->name;
  40.     }
  41.     public function setName(string $name): self
  42.     {
  43.         $this->name $name;
  44.         return $this;
  45.     }
  46.     /**
  47.      * @ORM\Column(type="string", length=255, nullable=true)
  48.      */
  49.     private $image;   
  50.     public function getImage(): ?string
  51.     {
  52.         return $this->image;
  53.     }
  54.     public function setImage(?string $image): self
  55.     {
  56.         $this->image $image;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @ORM\Column(type="text", nullable=true)
  61.      */
  62.     private $description;
  63.     public function getDescription(): ?string
  64.     {
  65.         return $this->description;
  66.     }
  67.     public function setDescription(?string $description): self
  68.     {
  69.         $this->description $description;
  70.         return $this;
  71.     }
  72.     
  73.     /**
  74.      * @return Collection<int, Product>
  75.      */
  76.     public function getProducts(): Collection
  77.     {
  78.         return $this->products;
  79.     }
  80.     public function addProduct(Product $product): self
  81.     {
  82.         if (!$this->products->contains($product)) {
  83.             $this->products[] = $product;
  84.             $product->setCategory($this);
  85.         }
  86.         return $this;
  87.     }
  88.     public function removeProduct(Product $product): self
  89.     {
  90.         if ($this->products->removeElement($product)) {
  91.             // set the owning side to null (unless already changed)
  92.             if ($product->getCategory() === $this) {
  93.                 $product->setCategory(null);
  94.             }
  95.         }
  96.         return $this;
  97.     }
  98. }