src/Entity/City.php line 13

Open in your IDE?
  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. /**
  8.  * @ORM\Entity(repositoryClass=CityRepository::class)
  9.  */
  10. class City
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=100)
  20.      */
  21.     private $label;
  22.     /**
  23.      * @ORM\Column(type="integer", length=2)
  24.      */
  25.     private $code;
  26.     /**
  27.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="city")
  28.      */
  29.     private $users;
  30.     public function __construct()
  31.     {
  32.         $this->users = new ArrayCollection();
  33.     }
  34.     public function getId(): ?int
  35.     {
  36.         return $this->id;
  37.     }
  38.     public function getLabel(): ?string
  39.     {
  40.         return $this->label;
  41.     }
  42.     public function setLabel(string $label): self
  43.     {
  44.         $this->label $label;
  45.         return $this;
  46.     }
  47.     /**
  48.      * @return Collection<int, User>
  49.      */
  50.     public function getUsers(): Collection
  51.     {
  52.         return $this->users;
  53.     }
  54.     public function addUsers(User $user): self
  55.     {
  56.         if (!$this->users->contains($user)) {
  57.             $this->users[] = $user;
  58.             $user->setCity($this);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeUser(User $user): self
  63.     {
  64.         if ($this->users->removeElement($user)) {
  65.             // set the owning side to null (unless already changed)
  66.             if ($user->getCity() === $this) {
  67.                 $user->setCity(null);
  68.             }
  69.         }
  70.         return $this;
  71.     }
  72.     /**
  73.      * @return mixed
  74.      */
  75.     public function getCode()
  76.     {
  77.         return $this->code;
  78.     }
  79.     /**
  80.      * @param mixed $code
  81.      */
  82.     public function setCode($code): void
  83.     {
  84.         $this->code $code;
  85.     }
  86. }