src/Entity/Subcategory.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\ORM\Mapping\JoinColumn;
  6. use Doctrine\ORM\Mapping\InverseJoinColumn;
  7. use Doctrine\ORM\Mapping\JoinTable;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Table(name'subcategory')]
  11. #[ORM\Entity(repositoryClass'App\Repository\SubcategoryRepository')]
  12. #[UniqueEntity('name')]
  13. class Subcategory
  14. {
  15.     public function __construct()
  16.     {
  17.         $this->products = new ArrayCollection();
  18.         $this->categories = new ArrayCollection();
  19.     }
  20.     #[Groups(['category''company'])]
  21.     #[ORM\Column(name'id'type'integer')]
  22.     #[ORM\Id]
  23.     #[ORM\GeneratedValue(strategy'AUTO')]
  24.     private $id;
  25.     #[Groups(['category''company'])]
  26.     #[ORM\Column(name'name'type'string'length255)]
  27.     protected $name;
  28.     #[Groups(['category''company'])]
  29.     #[ORM\Column(name'description'type'text'nullabletrue)]
  30.     protected $description;
  31.     #[Groups(['category''company'])]
  32.     #[ORM\Column(name'slug'type'string'length255nullabletrue)]
  33.     protected $slug;
  34.     #[Groups(['category''company'])]
  35.     #[ORM\Column(name'image'type'string'length255)]
  36.     protected $image;
  37.     #[ORM\ManyToMany(targetEntity'App\Entity\Category'mappedBy'subcategories'cascade: ['persist'], fetch'EAGER')]
  38.     protected $categories;
  39.     public function getCategories()
  40.     {
  41.         return $this->categories;
  42.     }
  43.     public function addCategory(Category $Category)
  44.     {
  45.         $this->categories->add($Category);
  46.     }
  47.     public function removeCategory(Category $Category)
  48.     {
  49.         $this->categories->removeElement($Category);
  50.     }
  51.     // /**
  52.     //  *
  53.     //  * @ORM\ManyToMany(targetEntity="App\Entity\Product", inversedBy="subcategories", cascade={"persist"})
  54.     //  * @JoinTable(name="product_subcategory",
  55.     //  *      joinColumns={@JoinColumn(name="subcategory_id", referencedColumnName="id")},
  56.     //  *      inverseJoinColumns={@JoinColumn(name="product_id", referencedColumnName="id",nullable=false,onDelete="CASCADE")}
  57.     //  *      )
  58.     //  */
  59.     #[ORM\ManyToMany(targetEntity'App\Entity\Product'inversedBy'subcategories'cascade: ['persist'])]
  60.     #[ORM\JoinTable(name'product_subcategory')]
  61.     #[ORM\JoinColumn(name'subcategory_id'referencedColumnName'id')]
  62.     #[ORM\InverseJoinColumn(name'product_id'referencedColumnName'id'nullablefalseonDelete'CASCADE')]
  63.     // #[Groups(["category"])]
  64.     private $products;
  65.     #[Groups(["category"])]
  66.     #[ORM\Column(type'integer'nullabletrue)]
  67.     private $unicity;
  68.     /**
  69.      * @return Collection|Product[]
  70.      */
  71.     public function getProducts()
  72.     {
  73.         return $this->products;
  74.     }
  75.     public function addProduct(Product $product)
  76.     {
  77.         $this->products[] = $product;
  78.         return $this;
  79.     }
  80.     public function removeProduct(Product $product)
  81.     {
  82.         return $this->products->removeElement($product);
  83.     }
  84.     /**
  85.      * @return int
  86.      */
  87.     public function getId()
  88.     {
  89.         return $this->id;
  90.     }
  91.     /**
  92.      * @param int $id
  93.      */
  94.     public function setId($id)
  95.     {
  96.         $this->id $id;
  97.     }
  98.     /**
  99.      * @return string
  100.      */
  101.     public function getName()
  102.     {
  103.         return $this->name;
  104.     }
  105.     /**
  106.      * @param string $name
  107.      */
  108.     public function setName($name)
  109.     {
  110.         $this->name $name;
  111.     }
  112.     /**
  113.      * @return text
  114.      */
  115.     public function getDescription()
  116.     {
  117.         return $this->description;
  118.     }
  119.     /**
  120.      * @param text $description
  121.      */
  122.     public function setDescription($description)
  123.     {
  124.         $this->description $description;
  125.     }
  126.     /**
  127.      * @return string
  128.      */
  129.     public function getSlug()
  130.     {
  131.         return $this->slug;
  132.     }
  133.     /**
  134.      * @param string $slug
  135.      */
  136.     public function setSlug($slug)
  137.     {
  138.         $this->slug $slug;
  139.     }
  140.     /**
  141.      * @return string
  142.      */
  143.     public function getImage()
  144.     {
  145.         return $this->image;
  146.     }
  147.     /**
  148.      * @param string $image
  149.      * @return mixed
  150.      */
  151.     public function setImage($image)
  152.     {
  153.         $this->image $image;
  154.         return $this;
  155.     }
  156.     public function getUnicity(): ?int
  157.     {
  158.         return $this->unicity;
  159.     }
  160.     public function setUnicity(?int $unicity): self
  161.     {
  162.         $this->unicity $unicity;
  163.         return $this;
  164.     }
  165. }