src/Entity/Location.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\LocationRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. #[ORM\Entity(repositoryClassLocationRepository::class)]
  11. #[ApiResource()]
  12. class Location
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     #[Groups(['pitch:read','reservation:read','favoris:read'])]
  18.     private $id;
  19.     #[ORM\Column(type'string'length120)]
  20.     #[Assert\NotBlank]
  21.     #[Assert\NotNull]
  22.     #[Groups(['pitch:read','reservation:read','favoris:read'])]
  23.     private $label;
  24.     #[ORM\OneToMany(mappedBy'location'targetEntityPitch::class)]
  25.     private $pitches;
  26.     public function __construct()
  27.     {
  28.         $this->pitches = new ArrayCollection();
  29.     }
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     public function getLabel(): ?string
  35.     {
  36.         return $this->label;
  37.     }
  38.     public function setLabel(string $label): self
  39.     {
  40.         $this->label $label;
  41.         return $this;
  42.     }
  43.     /**
  44.      * @return Collection<int, Pitch>
  45.      */
  46.     public function getPitches(): Collection
  47.     {
  48.         return $this->pitches;
  49.     }
  50.     public function addPitch(Pitch $pitch): self
  51.     {
  52.         if (!$this->pitches->contains($pitch)) {
  53.             $this->pitches[] = $pitch;
  54.             $pitch->setLocation($this);
  55.         }
  56.         return $this;
  57.     }
  58.     public function removePitch(Pitch $pitch): self
  59.     {
  60.         if ($this->pitches->removeElement($pitch)) {
  61.             // set the owning side to null (unless already changed)
  62.             if ($pitch->getLocation() === $this) {
  63.                 $pitch->setLocation(null);
  64.             }
  65.         }
  66.         return $this;
  67.     }
  68. }