<?php
namespace App\Entity;
use App\Repository\TagRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use phpDocumentor\Reflection\Types\Integer;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass:TagRepository ::class)]
class Tag
{
//Déclarations des variables
#[ORM\Id]
#[ORM\Column(name: 'id_tag',type: 'integer', nullable: false)]
#[ORM\GeneratedValue(strategy:'IDENTITY')]
private ?int $id;
#[ORM\Column(length: 255, nullable: false)]
private ?string $nom = null;
//Association bidirectionnelle
#[ORM\ManyToMany(targetEntity: Model::class, mappedBy:'tags', orphanRemoval:true)]
private ?Collection $models;
//Constructeur
public function __construct()
{
$this->models = new ArrayCollection();
}
//Getters et Setters
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getNom(): ?string
{
return $this->nom;
}
/**
* @param string|null $nom
*/
public function setNom(?string $nom): void
{
$this->nom = $nom;
}
//Fonctions des collections
/**
* @return Collection<int, Model>
*/
public function getModels(): Collection
{
return $this->models;
}
public function addModel(Model $model): self
{
if (!$this->models->contains($model)) {
$this->models->add($model);
$model->addTag($this);
}
return $this;
}
public function removeModel(Model $model): self
{
if ($this->models->removeElement($model)) {
// set the owning side to null (unless already changed)
if ($model->getTags() === $this) {
$model->addTag(null);
}
}
return $this;
}
public function __toString(): string
{
return $this->nom ?? '';
}
}