src/Entity/Categorie.php line 12

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. #[ORM\Entity(repositoryClass:CategorieRepository ::class)]
  8. class Categorie
  9. {
  10.     //Déclarations des variables
  11.     #[ORM\Id]
  12.     #[ORM\Column(name'id_categorie',type'integer',nullablefalse)]
  13.     #[ORM\GeneratedValue(strategy:'IDENTITY')]
  14.     private ?int $id;
  15.     #[ORM\Column(length255nullablefalse)]
  16.     private ?string $nom null;
  17.     //Associations
  18.     #[ORM\OneToMany(mappedBy:'categorie'targetEntitySousCategorie::class)]
  19.     private Collection $sousCategories;
  20.     //Association bidirectionnelle
  21.     #[ORM\ManyToMany(targetEntityModel::class, mappedBy:'categories')]
  22.     private ?Collection $models;
  23.     #[ORM\ManyToMany(targetEntityTypeCollection::class, mappedBy'categories')]
  24.     private Collection $typeCollections;
  25.     //Constructeur
  26.     public function __construct()
  27.     {
  28.         $this->sousCategories = new ArrayCollection();
  29.         $this->models = new ArrayCollection();
  30.         $this->typeCollections = new ArrayCollection();
  31.     }
  32.     //Getters et Setters
  33.     /**
  34.      * @return int|null
  35.      */
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     /**
  41.      * @return string|null
  42.      */
  43.     public function getNom(): ?string
  44.     {
  45.         return $this->nom;
  46.     }
  47.     /**
  48.      * @param string|null $nom
  49.      */
  50.     public function setNom(?string $nom): void
  51.     {
  52.         $this->nom $nom;
  53.     }
  54.     /**
  55.      * @return Collection<int, SousCategorie>
  56.      */
  57.     public function getSousCategories(): Collection
  58.     {
  59.         return $this->sousCategories;
  60.     }
  61.     public function addSousCategorie(SousCategorie $sousCategorie): self
  62.     {
  63.         if (!$this->sousCategories->contains($sousCategorie)) {
  64.             $this->sousCategories->add($sousCategorie);
  65.             $sousCategorie->addCategorie($this);
  66.         }
  67.         return $this;
  68.     }
  69.     public function removeSousCategorie(SousCategorie $sousCategorie): self
  70.     {
  71.         if ($this->sousCategories->removeElement($sousCategorie)) {
  72.             // set the owning side to null (unless already changed)
  73.             if ($sousCategorie->getCategorie() === $this) {
  74.                 $sousCategorie->removeCategorie(null);
  75.             }
  76.         }
  77.         return $this;
  78.     }
  79.     /**
  80.      * @return Collection<int, Model>
  81.      */
  82.     public function getModels(): Collection
  83.     {
  84.         return $this->models;
  85.     }
  86.     public function addModel(Model $model): self
  87.     {
  88.         if (!$this->models->contains($model)) {
  89.             $this->models->add($model);
  90.             $model->addCategorie($this);
  91.         }
  92.         return $this;
  93.     }
  94.     public function removeModel(Model $model): self
  95.     {
  96.         if ($this->models->removeElement($model)) {
  97.             // set the owning side to null (unless already changed)
  98.             if ($model->getCategories() === $this) {
  99.                 $model->addCategorie(null);
  100.             }
  101.         }
  102.         return $this;
  103.     }
  104.     public function __toString(): string
  105.     {
  106.         return $this->nom ?? '';
  107.     }
  108.     /**
  109.      * @return Collection<int, TypeCollection>
  110.      */
  111.     public function getTypeCollections(): Collection
  112.     {
  113.         return $this->typeCollections;
  114.     }
  115.     public function addTypeCollection(TypeCollection $typeCollection): self
  116.     {
  117.         if (!$this->typeCollections->contains($typeCollection)) {
  118.             $this->typeCollections->add($typeCollection);
  119.             $typeCollection->addCategory($this);
  120.         }
  121.         return $this;
  122.     }
  123.     public function removeTypeCollection(TypeCollection $typeCollection): self
  124.     {
  125.         if ($this->typeCollections->removeElement($typeCollection)) {
  126.             $typeCollection->removeCategory($this);
  127.         }
  128.         return $this;
  129.     }
  130. }