<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Repository\LocationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: LocationRepository::class)]
#[ApiResource()]
class Location
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups(['pitch:read','reservation:read','favoris:read'])]
private $id;
#[ORM\Column(type: 'string', length: 120)]
#[Assert\NotBlank]
#[Assert\NotNull]
#[Groups(['pitch:read','reservation:read','favoris:read'])]
private $label;
#[ORM\OneToMany(mappedBy: 'location', targetEntity: Pitch::class)]
private $pitches;
public function __construct()
{
$this->pitches = new ArrayCollection();
}
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, Pitch>
*/
public function getPitches(): Collection
{
return $this->pitches;
}
public function addPitch(Pitch $pitch): self
{
if (!$this->pitches->contains($pitch)) {
$this->pitches[] = $pitch;
$pitch->setLocation($this);
}
return $this;
}
public function removePitch(Pitch $pitch): self
{
if ($this->pitches->removeElement($pitch)) {
// set the owning side to null (unless already changed)
if ($pitch->getLocation() === $this) {
$pitch->setLocation(null);
}
}
return $this;
}
}