src/Entity/Tag.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TagRepository;
  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(repositoryClass:TagRepository ::class)]
  9. class Tag
  10. {
  11.     //Déclarations des variables
  12.     #[ORM\Id]
  13.     #[ORM\Column(name'id_tag',type'integer'nullablefalse)]
  14.     #[ORM\GeneratedValue(strategy:'IDENTITY')]
  15.     private ?int $id;
  16.     #[ORM\Column(length255nullablefalse)]
  17.     private ?string $nom null;
  18.     //Association bidirectionnelle
  19.     #[ORM\ManyToMany(targetEntityModel::class, mappedBy:'tags'orphanRemoval:true)]
  20.     private ?Collection $models;
  21.     //Constructeur
  22.     public function __construct()
  23.     {
  24.         $this->models = new ArrayCollection();
  25.     }
  26.     //Getters et Setters
  27.     /**
  28.      * @return int|null
  29.      */
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     /**
  35.      * @return string|null
  36.      */
  37.     public function getNom(): ?string
  38.     {
  39.         return $this->nom;
  40.     }
  41.     /**
  42.      * @param string|null $nom
  43.      */
  44.     public function setNom(?string $nom): void
  45.     {
  46.         $this->nom $nom;
  47.     }
  48.     //Fonctions des collections
  49.     /**
  50.      * @return Collection<int, Model>
  51.      */
  52.     public function getModels(): Collection
  53.     {
  54.         return $this->models;
  55.     }
  56.     public function addModel(Model $model): self
  57.     {
  58.         if (!$this->models->contains($model)) {
  59.             $this->models->add($model);
  60.             $model->addTag($this);
  61.         }
  62.         return $this;
  63.     }
  64.     public function removeModel(Model $model): self
  65.     {
  66.         if ($this->models->removeElement($model)) {
  67.             // set the owning side to null (unless already changed)
  68.             if ($model->getTags() === $this) {
  69.                 $model->addTag(null);
  70.             }
  71.         }
  72.         return $this;
  73.     }
  74.     public function __toString(): string
  75.     {
  76.         return $this->nom ?? '';
  77.     }
  78. }