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 Symfony\Component\String\Slugger\AsciiSlugger;
  8. #[ORM\Entity(repositoryClassRegionRepository::class)]
  9. class Region
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $name null;
  17.     #[ORM\Column]
  18.     private ?int $code null;
  19.     #[ORM\Column(length255uniquetrue)]
  20.     private ?string $url null;
  21.     #[ORM\OneToMany(mappedBy'region'targetEntityDistrict::class)]
  22.     private Collection $districts;
  23.     public function __construct()
  24.     {
  25.         $this->districts = new ArrayCollection();
  26.     }
  27.     public function getId(): ?int
  28.     {
  29.         return $this->id;
  30.     }
  31.     public function getUrl(): ?string
  32.     {
  33.         return $this->url;
  34.     }
  35.     public function setUrl(): self
  36.     {
  37.         $slugger = new AsciiSlugger('cs');
  38.         $slug =   $slugger->slug($this->getName(), '-')->lower();
  39.         $this->url $slug->toString();
  40.         return $this;
  41.     }
  42.     public function getName(): ?string
  43.     {
  44.         return $this->name;
  45.     }
  46.     public function setName(string $name): self
  47.     {
  48.         $this->name $name;
  49.         $this->setUrl();
  50.         return $this;
  51.     }
  52.     public function getCode(): ?int
  53.     {
  54.         return $this->code;
  55.     }
  56.     public function setCode(int $code): self
  57.     {
  58.         $this->code $code;
  59.         return $this;
  60.     }
  61.     /**
  62.      * @return Collection<int, District>
  63.      */
  64.     public function getDistricts(): Collection
  65.     {
  66.         return $this->districts;
  67.     }
  68.     public function addDistrict(District $district): self
  69.     {
  70.         if (!$this->districts->contains($district)) {
  71.             $this->districts->add($district);
  72.             $district->setRegion($this);
  73.         }
  74.         return $this;
  75.     }
  76.     public function removeDistrict(District $district): self
  77.     {
  78.         if ($this->districts->removeElement($district)) {
  79.             // set the owning side to null (unless already changed)
  80.             if ($district->getRegion() === $this) {
  81.                 $district->setRegion(null);
  82.             }
  83.         }
  84.         return $this;
  85.     }
  86. }