src/Entity/SousCategorie.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SousCategorieRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use phpDocumentor\Reflection\Types\Integer;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassSousCategorieRepository::class)]
  9. class SousCategorie
  10. {
  11.     //Déclarations des variables
  12.     #[ORM\Id]
  13.     #[ORM\Column(name'id_sous_categorie',type'integer'nullablefalse)]
  14.     //Spécifie que la valeur générée est un ID auto-incrémenté
  15.     #[ORM\GeneratedValue(strategy:'IDENTITY')]
  16.     private ?int $id;
  17.     #[ORM\Column(length255nullablefalse)]
  18.     private ?string $nom null;
  19.     //Associations
  20.     #[ORM\ManyToOne(targetEntityCategorie::class, inversedBy'sousCategories')]
  21.     #[ORM\JoinColumn(referencedColumnName'id_categorie'nullablefalse)]
  22.     private ?Categorie $categorie null;
  23.     //Association bidirectionnelle
  24.     #[ORM\ManyToMany(targetEntityModel::class, mappedBy:'sousCategories')]
  25.     private ?Collection $models;
  26.     //Constructeur
  27.     public function __construct()
  28.     {
  29.         $this->models = new ArrayCollection();
  30.     }
  31.     //Getters et Setters
  32.     /**
  33.      * @return int|null
  34.      */
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     /**
  40.      * @return string|null
  41.      */
  42.     public function getNom(): ?string
  43.     {
  44.         return $this->nom;
  45.     }
  46.     /**
  47.      * @param string|null $nom
  48.      */
  49.     public function setNom(?string $nom): void
  50.     {
  51.         $this->nom $nom;
  52.     }
  53.     /**
  54.      * @return Categorie|null
  55.      */
  56.     public function getCategorie(): ?Categorie
  57.     {
  58.         return $this->categorie;
  59.     }
  60.     /**
  61.      * @param Categorie|null $categorie
  62.      */
  63.     public function setCategorie(?Categorie $categorie): void
  64.     {
  65.         $this->categorie $categorie;
  66.     }
  67.     //Fonctions des collections
  68.     /**
  69.      * @return Collection<int, Model>
  70.      */
  71.     public function getModels(): Collection
  72.     {
  73.         return $this->models;
  74.     }
  75.     public function addModel(Model $model): self
  76.     {
  77.         if (!$this->models->contains($model)) {
  78.             $this->models->add($model);
  79.             $model->addSousCategorie($this);
  80.         }
  81.         return $this;
  82.     }
  83.     public function removeModel(Model $model): self
  84.     {
  85.         if ($this->models->removeElement($model)) {
  86.             // set the owning side to null (unless already changed)
  87.             if ($model->getSousCategories() === $this) {
  88.                 $model->addSousCategorie(null);
  89.             }
  90.         }
  91.         return $this;
  92.     }
  93. //    public function __toString(): string
  94. //    {
  95. //        return $this->nom ?? '';
  96. //    }
  97. }