src/Entity/Region.php line 18

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use App\Repository\RegionRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping\Column;
  8. use Doctrine\ORM\Mapping\Entity;
  9. use Doctrine\ORM\Mapping\GeneratedValue;
  10. use Doctrine\ORM\Mapping\Id;
  11. use Doctrine\ORM\Mapping\ManyToOne;
  12. use Doctrine\ORM\Mapping\OneToMany;
  13. #[Entity(RegionRepository::class)]
  14. class Region
  15. {
  16.     #[Id]
  17.     #[GeneratedValue]
  18.     #[Column(type'integer'options: ['unsigned' => true])]
  19.     private ?int $id null;
  20.     #[ManyToOne(targetEntityRegion::class, inversedBy'children')]
  21.     private ?Region $parent null;
  22.     #[OneToMany(mappedBy'parent'targetEntityRegion::class)]
  23.     private Collection $children;
  24.     #[OneToMany(mappedBy'region'targetEntityCountry::class)]
  25.     private Collection $countries;
  26.     #[Column(type'string')]
  27.     private string $name;
  28.     public function __construct()
  29.     {
  30.         $this->children = new ArrayCollection();
  31.         $this->countries = new ArrayCollection();
  32.     }
  33.     public function getId(): ?int
  34.     {
  35.         return $this->id;
  36.     }
  37.     public function getParent(): ?Region
  38.     {
  39.         return $this->parent;
  40.     }
  41.     public function setParent(?Region $parent): void
  42.     {
  43.         $this->parent $parent;
  44.     }
  45.     public function getChildren(): Collection
  46.     {
  47.         return $this->children;
  48.     }
  49.     public function setChildren(Collection $children): void
  50.     {
  51.         $this->children $children;
  52.     }
  53.     public function getCountries(): Collection
  54.     {
  55.         return $this->countries;
  56.     }
  57.     public function setCountries(Collection $countries): void
  58.     {
  59.         $this->countries $countries;
  60.     }
  61.     public function getName(): string
  62.     {
  63.         return $this->name;
  64.     }
  65.     public function setName(string $name): void
  66.     {
  67.         $this->name $name;
  68.     }
  69.     public function addChild(Region $child): self
  70.     {
  71.         if (!$this->children->contains($child)) {
  72.             $this->children[] = $child;
  73.             $child->setParent($this);
  74.         }
  75.         return $this;
  76.     }
  77.     public function removeChild(Region $child): self
  78.     {
  79.         if ($this->children->removeElement($child)) {
  80.             if ($child->getParent() === $this) {
  81.                 $child->setParent(null);
  82.             }
  83.         }
  84.         return $this;
  85.     }
  86.     public function addCountry(Country $country): self
  87.     {
  88.         if (!$this->countries->contains($country)) {
  89.             $this->countries[] = $country;
  90.             $country->setRegion($this);
  91.         }
  92.         return $this;
  93.     }
  94.     public function removeCountry(Country $country): self
  95.     {
  96.         if ($this->countries->removeElement($country)) {
  97.             if ($country->getRegion() === $this) {
  98.                 $country->setRegion(null);
  99.             }
  100.         }
  101.         return $this;
  102.     }
  103. }