src/Entity/City.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CityRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use Symfony\Component\Uid\Uuid;
  9. #[ORM\Entity(repositoryClassCityRepository::class)]
  10. class City
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\Column(type'uuid'uniquetrue)]
  14.     #[Groups(['BASE'])]
  15.     private ?string $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $name null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $code null;
  20.     #[ORM\OneToMany(mappedBy'city'targetEntityProperty::class)]
  21.     private Collection $properties;
  22.     public function __construct()
  23.     {
  24.         $this->id Uuid::v4();
  25.         $this->properties = new ArrayCollection();
  26.     }
  27.     public function getId(): ?string
  28.     {
  29.         return $this->id;
  30.     }
  31.     public function __toString()
  32.     {
  33.         return $this->getName();
  34.     }
  35.     public function getName(): ?string
  36.     {
  37.         return $this->name;
  38.     }
  39.     public function setName(string $name): static
  40.     {
  41.         $this->name $name;
  42.         return $this;
  43.     }
  44.     public function getCode(): ?string
  45.     {
  46.         return $this->code;
  47.     }
  48.     public function setCode(string $code): static
  49.     {
  50.         $this->code $code;
  51.         return $this;
  52.     }
  53.     /**
  54.      * @return Collection<int, Property>
  55.      */
  56.     public function getProperties(): Collection
  57.     {
  58.         return $this->properties;
  59.     }
  60.     public function addProperty(Property $property): static
  61.     {
  62.         if (!$this->properties->contains($property)) {
  63.             $this->properties->add($property);
  64.             $property->setCity($this);
  65.         }
  66.         return $this;
  67.     }
  68.     public function removeStore(Property $property): static
  69.     {
  70.         if ($this->properties->removeElement($property)) {
  71.             // set the owning side to null (unless already changed)
  72.             if ($property->getCity() === $this) {
  73.                 $property->setCity(null);
  74.             }
  75.         }
  76.         return $this;
  77.     }
  78. }