src/Entity/Category.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Subcategory;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Doctrine\ORM\Mapping\UniqueConstraint as UniqueConstraint;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ORM\Table(name:"category")]
  10. #[ORM\Entity(repositoryClass:"App\Repository\CategoryRepository")]
  11. class Category
  12. {
  13.     public function __construct()
  14.     {
  15.         $this->subcategories = new ArrayCollection();
  16.         $this->companies = new ArrayCollection();
  17.     }
  18.     #[ORM\Id]
  19.     #[ORM\GeneratedValue(strategy:'AUTO')]
  20.     #[ORM\Column(name:'id'type:'integer'unique:true )]
  21.     #[Groups(['category''company'])]
  22.     private $id;
  23.     #[ORM\Column(name:'name'type:'string'length:255)]
  24.     #[Groups(['category''company'])]
  25.     protected $name;
  26.     #[ORM\Column(name:'description'type:'text'nullable:true)]
  27.     #[Groups(['category''company'])]
  28.     protected $description;
  29.     #[ORM\Column(name:'image'type:'string')]
  30.     #[Groups(['category''company'])]
  31.     protected $image;
  32.     #[ORM\Column(name:'slug'type:'string'length:255nullable:true)]
  33.     #[Groups(['category''company'])]
  34.     protected $slug;
  35.     #[ORM\ManyToMany(targetEntity:'App\Entity\Company',mappedBy:'categories'cascade:['persist'])]
  36.     protected $companies;
  37.     /**
  38.      * @return mixed
  39.      */
  40.     public function getCompanies()
  41.     {
  42.         return $this->companies;
  43.     }
  44.     public function addCompany(Company $company)
  45.     {
  46.         $this->companies->add($company);
  47.     }
  48.     public function removeCompany(Company $company)
  49.     {
  50.         $this->companies->removeElement($company);
  51.     }
  52.     #[Groups(['category''company'])]
  53.     #[ORM\ManyToMany(targetEntity:'App\Entity\Subcategory',inversedBy:'categories'cascade:['persist'], fetch'EAGER')]
  54.     protected $subcategories;
  55.     #[ORM\OneToOne(targetEntity:AdapterContent::class,mappedBy:'category'cascade:['persist''remove'])]
  56.     private $adapterContent;
  57.     #[ORM\Columntype:'integer'nullable:true)]
  58.     #[Groups(['category''company'])]
  59.     private $unicity;
  60.     /**
  61.      * @return mixed
  62.      */
  63.     public function getSubcategories()
  64.     {
  65.         return $this->subcategories;
  66.     }
  67.     public function addSubcategory(Subcategory $subcategory)
  68.     {
  69.         $this->subcategories->add($subcategory);
  70.     }
  71.     public function removeSubcategory(Subcategory $subcategory)
  72.     {
  73.         $this->subcategories->removeElement($subcategory);
  74.     }
  75.     /**
  76.      * @param ArrayCollection $subcategories
  77.      */
  78.     public function setSubcategories($subcategories)
  79.     {
  80.         $this->subcategories $subcategories;
  81.     }
  82.     /**
  83.      * @return int
  84.      */
  85.     public function getId()
  86.     {
  87.         return $this->id;
  88.     }
  89.     /**
  90.      * @param int $id
  91.      */
  92.     public function setId($id)
  93.     {
  94.         $this->id $id;
  95.     }
  96.     /**
  97.      * @return string
  98.      */
  99.     public function getName()
  100.     {
  101.         return $this->name;
  102.     }
  103.     /**
  104.      * @param string $name
  105.      */
  106.     public function setName($name)
  107.     {
  108.         $this->name $name;
  109.     }
  110.     /**
  111.      * @return text
  112.      */
  113.     public function getDescription()
  114.     {
  115.         return $this->description;
  116.     }
  117.     /**
  118.      * @param text $description
  119.      */
  120.     public function setDescription($description)
  121.     {
  122.         $this->description $description;
  123.     }
  124.     /**
  125.      * @return string
  126.      */
  127.     public function getSlug()
  128.     {
  129.         return $this->slug;
  130.     }
  131.     /**
  132.      * @param string $slug
  133.      */
  134.     public function setSlug($slug)
  135.     {
  136.         $this->slug $slug;
  137.     }
  138.     /**
  139.      * @return string
  140.      */
  141.     public function getImage()
  142.     {
  143.         return $this->image;
  144.     }
  145.     /**
  146.      * @param string $image
  147.      * @return mixed
  148.      */
  149.     public function setImage($image)
  150.     {
  151.         $this->image $image;
  152.         return $this;
  153.     }
  154.     public function getAdapterContent(): ?AdapterContent
  155.     {
  156.         return $this->adapterContent;
  157.     }
  158.     public function setAdapterContent(?AdapterContent $adapterContent): self
  159.     {
  160.         // unset the owning side of the relation if necessary
  161.         if ($adapterContent === null && $this->adapterContent !== null) {
  162.             $this->adapterContent->setCategory(null);
  163.         }
  164.         // set the owning side of the relation if necessary
  165.         if ($adapterContent !== null && $adapterContent->getCategory() !== $this) {
  166.             $adapterContent->setCategory($this);
  167.         }
  168.         $this->adapterContent $adapterContent;
  169.         return $this;
  170.     }
  171.     public function getUnicity(): ?int
  172.     {
  173.         return $this->unicity;
  174.     }
  175.     public function setUnicity(?int $unicity): self
  176.     {
  177.         $this->unicity $unicity;
  178.         return $this;
  179.     }
  180. }