src/Entity/Zone.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\ZoneRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassZoneRepository::class)]
  9. #[ApiResource]
  10. class Zone
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length100)]
  17.     private ?string $name null;
  18.     #[ORM\ManyToOne(inversedBy'zones')]
  19.     #[ORM\JoinColumn(nullablefalse)]
  20.     private ?Country $country null;
  21.     #[ORM\OneToMany(mappedBy'zone'targetEntityUsers::class, orphanRemovaltrue)]
  22.     private Collection $users;
  23.     #[ORM\OneToMany(mappedBy'zone'targetEntityStation::class, orphanRemovaltrue)]
  24.     private Collection $stations;
  25.     public function __construct()
  26.     {
  27.         $this->users = new ArrayCollection();
  28.         $this->stations = new ArrayCollection();
  29.     }
  30.     public function getId(): ?int
  31.     {
  32.         return $this->id;
  33.     }
  34.     public function getName(): ?string
  35.     {
  36.         return $this->name;
  37.     }
  38.     public function setName(string $name): self
  39.     {
  40.         $this->name $name;
  41.         return $this;
  42.     }
  43.     public function getCountry(): ?Country
  44.     {
  45.         return $this->country;
  46.     }
  47.     public function setCountry(?Country $country): self
  48.     {
  49.         $this->country $country;
  50.         return $this;
  51.     }
  52.     /**
  53.      * @return Collection<int, Users>
  54.      */
  55.     public function getUsers(): Collection
  56.     {
  57.         return $this->users;
  58.     }
  59.     public function addUser(Users $user): self
  60.     {
  61.         if (!$this->users->contains($user)) {
  62.             $this->users->add($user);
  63.             $user->setZone($this);
  64.         }
  65.         return $this;
  66.     }
  67.     public function removeUser(Users $user): self
  68.     {
  69.         if ($this->users->removeElement($user)) {
  70.             // set the owning side to null (unless already changed)
  71.             if ($user->getZone() === $this) {
  72.                 $user->setZone(null);
  73.             }
  74.         }
  75.         return $this;
  76.     }
  77.     /**
  78.      * @return Collection<int, Station>
  79.      */
  80.     public function getStations(): Collection
  81.     {
  82.         return $this->stations;
  83.     }
  84.     public function addStation(Station $station): self
  85.     {
  86.         if (!$this->stations->contains($station)) {
  87.             $this->stations->add($station);
  88.             $station->setZone($this);
  89.         }
  90.         return $this;
  91.     }
  92.     public function removeStation(Station $station): self
  93.     {
  94.         if ($this->stations->removeElement($station)) {
  95.             // set the owning side to null (unless already changed)
  96.             if ($station->getZone() === $this) {
  97.                 $station->setZone(null);
  98.             }
  99.         }
  100.         return $this;
  101.     }
  102. }