src/Entity/Categorie.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategorieRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Entity\User;
  8. #[ORM\Entity(repositoryClassCategorieRepository::class)]
  9. class Categorie
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length50)]
  16.     private ?string $name null;
  17.     #[ORM\OneToMany(targetEntityArticle::class, mappedBy'categorie'cascade: ["persist"], orphanRemovaltrue)]
  18.     private Collection $haves;
  19.     public function __construct()
  20.     {
  21.         #permet de gérer les articles qui sont associé
  22.         $this->haves = new ArrayCollection();
  23.     }
  24.     public function getId(): ?int
  25.     {
  26.         return $this->id;
  27.     }
  28.     public function getName(): ?string
  29.     {
  30.         return $this->name;
  31.     }
  32.     public function setName(string $name): static
  33.     {
  34.         $this->name $name;
  35.         return $this;
  36.     }
  37.     
  38.     public function getHaves(): Collection
  39.     {
  40.         return $this->haves;
  41.     }
  42.     public function addHave(Have $have): self
  43.     {
  44.         if (!$this->haves->contains($have)) {
  45.             $this->haves[] = $have;
  46.             $have->setCategorie($this);
  47.         }
  48.         return $this;
  49.     }
  50.     public function removeHave(Article $article): self
  51.     {
  52.         if ($this->haves->removeElement($article)) {
  53.             if ($article->getCategorie() === $this) {
  54.                 $article->setCategorie(null);
  55.             }
  56.         }
  57.     
  58.         return $this;
  59.     }
  60.     
  61.      
  62.     public function __toString(): string
  63.     {
  64.         return $this->name;
  65.     }
  66.     
  67.     
  68. }