src/Entity/Region.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\RegionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. #[ORM\Entity(repositoryClassRegionRepository::class)]
  9. class Region
  10. {
  11.     use TimestampableEntity;
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $name null;
  18.     #[ORM\OneToMany(mappedBy'region'targetEntityUser::class)]
  19.     private Collection $users;
  20.     #[ORM\OneToMany(mappedBy'region'targetEntityUserRegion::class)]
  21.     private Collection $userRegions;
  22.     public function __construct()
  23.     {
  24.         $this->users = new ArrayCollection();
  25.         $this->userRegions = new ArrayCollection();
  26.     }
  27.     public function getId(): ?int
  28.     {
  29.         return $this->id;
  30.     }
  31.     public function getName(): ?string
  32.     {
  33.         return $this->name;
  34.     }
  35.     public function setName(string $name): static
  36.     {
  37.         $this->name $name;
  38.         return $this;
  39.     }
  40.     /**
  41.      * @return Collection<int, User>
  42.      */
  43.     public function getUsers(): Collection
  44.     {
  45.         return $this->users;
  46.     }
  47.     public function addUser(User $user): static
  48.     {
  49.         if (!$this->users->contains($user)) {
  50.             $this->users->add($user);
  51.             $user->setRegion($this);
  52.         }
  53.         return $this;
  54.     }
  55.     public function removeUser(User $user): static
  56.     {
  57.         if ($this->users->removeElement($user)) {
  58.             // set the owning side to null (unless already changed)
  59.             if ($user->getRegion() === $this) {
  60.                 $user->setRegion(null);
  61.             }
  62.         }
  63.         return $this;
  64.     }
  65.     public function getUsersCount()
  66.     {
  67.         return $this->users->count();
  68.     }
  69.     // add to string
  70.     public function __toString()
  71.     {
  72.         return $this->name;
  73.     }
  74.     /**
  75.      * @return Collection<int, UserRegion>
  76.      */
  77.     public function getUserRegions(): Collection
  78.     {
  79.         return $this->userRegions;
  80.     }
  81.     public function addUserRegion(UserRegion $userRegion): static
  82.     {
  83.         if (!$this->userRegions->contains($userRegion)) {
  84.             $this->userRegions->add($userRegion);
  85.             $userRegion->setRegion($this);
  86.         }
  87.         return $this;
  88.     }
  89.     public function removeUserRegion(UserRegion $userRegion): static
  90.     {
  91.         if ($this->userRegions->removeElement($userRegion)) {
  92.             // set the owning side to null (unless already changed)
  93.             if ($userRegion->getRegion() === $this) {
  94.                 $userRegion->setRegion(null);
  95.             }
  96.         }
  97.         return $this;
  98.     }
  99. }