src/Entity/Categorie.php line 13

Open in your IDE?
  1. <?php
  2. // src/Entity/Categorie.php
  3. namespace App\Entity;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\CategorieRepository")
  9.  * @ORM\Table(name="categories")
  10.  */
  11. class Categorie
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=50)
  21.      */
  22.     private $nom;
  23.     /**
  24.      * @ORM\Column(type="string", length=255, nullable=true)
  25.      */
  26.     private $icone;
  27.     /**
  28.      * @ORM\Column(type="boolean", options={"default": false})
  29.      */
  30.     private $topVente = false;
  31.     /**
  32.      * @ORM\OneToMany(targetEntity="Produit", mappedBy="categorie")
  33.      */
  34.     private $produits;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity="App\Entity\User")
  37.      * @ORM\JoinColumn(nullable=true) // Changez à nullable=true
  38.      */
  39.     private $user;
  40.     public function __construct()
  41.     {
  42.         $this->produits = new ArrayCollection();
  43.     }
  44.     // Getters et Setters
  45.     public function getId(): ?int
  46.     {
  47.         return $this->id;
  48.     }
  49.     public function getNom(): ?string
  50.     {
  51.         return $this->nom;
  52.     }
  53.     public function setNom(string $nom): self
  54.     {
  55.         $this->nom = $nom;
  56.         return $this;
  57.     }
  58.     public function getIcone(): ?string
  59.     {
  60.         return $this->icone;
  61.     }
  62.     public function setIcone(?string $icone): self
  63.     {
  64.         $this->icone = $icone;
  65.         return $this;
  66.     }
  67.     public function isTopVente(): bool
  68.     {
  69.         return $this->topVente;
  70.     }
  71.     public function setTopVente(bool $topVente): self
  72.     {
  73.         $this->topVente = $topVente;
  74.         return $this;
  75.     }
  76.     /**
  77.      * @return Collection|Produit[]
  78.      */
  79.     public function getProduits(): Collection
  80.     {
  81.         return $this->produits;
  82.     }
  83.     public function addProduit(Produit $produit): self
  84.     {
  85.         if (!$this->produits->contains($produit)) {
  86.             $this->produits[] = $produit;
  87.             $produit->setCategorie($this);
  88.         }
  89.         return $this;
  90.     }
  91.     public function removeProduit(Produit $produit): self
  92.     {
  93.         if ($this->produits->contains($produit)) {
  94.             $this->produits->removeElement($produit);
  95.             if ($produit->getCategorie() === $this) {
  96.                 $produit->setCategorie(null);
  97.             }
  98.         }
  99.         return $this;
  100.     }
  101.     public function __toString()
  102.     {
  103.         return $this->nom;
  104.     }
  105.     public function getUser(): ?User
  106.     {
  107.         return $this->user;
  108.     }
  109.     public function setUser(?User $user): self
  110.     {
  111.         $this->user = $user;
  112.         return $this;
  113.     }
  114.     public function getTopVente(): ?bool
  115.     {
  116.         return $this->topVente;
  117.     }
  118. }