<?php
// src/Entity/Categorie.php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass="App\Repository\CategorieRepository")
* @ORM\Table(name="categories")
*/
class Categorie
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=50)
*/
private $nom;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $icone;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $topVente = false;
/**
* @ORM\OneToMany(targetEntity="Produit", mappedBy="categorie")
*/
private $produits;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User")
* @ORM\JoinColumn(nullable=true) // Changez à nullable=true
*/
private $user;
public function __construct()
{
$this->produits = new ArrayCollection();
}
// Getters et Setters
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?string
{
return $this->nom;
}
public function setNom(string $nom): self
{
$this->nom = $nom;
return $this;
}
public function getIcone(): ?string
{
return $this->icone;
}
public function setIcone(?string $icone): self
{
$this->icone = $icone;
return $this;
}
public function isTopVente(): bool
{
return $this->topVente;
}
public function setTopVente(bool $topVente): self
{
$this->topVente = $topVente;
return $this;
}
/**
* @return Collection|Produit[]
*/
public function getProduits(): Collection
{
return $this->produits;
}
public function addProduit(Produit $produit): self
{
if (!$this->produits->contains($produit)) {
$this->produits[] = $produit;
$produit->setCategorie($this);
}
return $this;
}
public function removeProduit(Produit $produit): self
{
if ($this->produits->contains($produit)) {
$this->produits->removeElement($produit);
if ($produit->getCategorie() === $this) {
$produit->setCategorie(null);
}
}
return $this;
}
public function __toString()
{
return $this->nom;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getTopVente(): ?bool
{
return $this->topVente;
}
}