suivi/src/Entity/Tool.php
2022-12-19 18:35:10 +01:00

79 lines
1.7 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\ToolRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use App\Core\Entity\EntityInterface;
#[ORM\Entity(repositoryClass: ToolRepository::class)]
class Tool implements EntityInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
protected $id;
#[ORM\Column(type: 'string', length: 255)]
protected $label;
#[ORM\ManyToMany(targetEntity: Intervention::class, mappedBy: 'tools', cascade: ['persist', 'remove'])]
protected $interventions;
public function __construct()
{
$this->interventions = new ArrayCollection();
}
public function __toString()
{
return $this->getLabel();
}
public function getId(): ?int
{
return $this->id;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
/**
* @return Collection<int, Intervention>
*/
public function getInterventions(): Collection
{
return $this->interventions;
}
public function addIntervention(Intervention $intervention): self
{
if (!$this->interventions->contains($intervention)) {
$this->interventions[] = $intervention;
$intervention->addTool($this);
}
return $this;
}
public function removeIntervention(Intervention $intervention): self
{
if ($this->interventions->removeElement($intervention)) {
$intervention->removeTool($this);
}
return $this;
}
}