src/Entity/District.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\DistrictRepository;
  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(repositoryClassDistrictRepository::class)]
  9. class District
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne(inversedBy'districts')]
  16.     private ?Region $region null;
  17.     #[ORM\Column(length255)]
  18.     private ?string $name null;
  19.     #[ORM\Column]
  20.     private ?int $code null;
  21.     #[ORM\Column(length255uniquetrue )]
  22.     private ?string $url null;
  23.     #[ORM\OneToMany(mappedBy'district'targetEntityDealer::class)]
  24.     private Collection $dealers;
  25.     public function __construct()
  26.     {
  27.         $this->dealers = new ArrayCollection();
  28.     }
  29.     public function getId(): ?int
  30.     {
  31.         return $this->id;
  32.     }
  33.     public function getUrl(): ?string
  34.     {
  35.         return $this->url;
  36.     }
  37.     public function setUrl(): self
  38.     {
  39.         $slugger = new AsciiSlugger('cs');
  40.         $slug =   $slugger->slug($this->getName(), '-')->lower();
  41.         $this->url $slug->toString();
  42.         return $this;
  43.     }
  44.     public function getRegion(): ?Region
  45.     {
  46.         return $this->region;
  47.     }
  48.     public function setRegion(?Region $region): self
  49.     {
  50.         $this->region $region;
  51.         return $this;
  52.     }
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): self
  58.     {
  59.         $this->name $name;
  60.         $this->setUrl();
  61.         return $this;
  62.     }
  63.     public function getCode(): ?int
  64.     {
  65.         return $this->code;
  66.     }
  67.     public function setCode(int $code): self
  68.     {
  69.         $this->code $code;
  70.         return $this;
  71.     }
  72.     /**
  73.      * @return Collection<int, Dealer>
  74.      */
  75.     public function getDealers(): Collection
  76.     {
  77.         return $this->dealers;
  78.     }
  79.     public function addDealer(Dealer $dealer): self
  80.     {
  81.         if (!$this->dealers->contains($dealer)) {
  82.             $this->dealers->add($dealer);
  83.             $dealer->setDistrict($this);
  84.         }
  85.         return $this;
  86.     }
  87.     public function removeDealer(Dealer $dealer): self
  88.     {
  89.         if ($this->dealers->removeElement($dealer)) {
  90.             // set the owning side to null (unless already changed)
  91.             if ($dealer->getDistrict() === $this) {
  92.                 $dealer->setDistrict(null);
  93.             }
  94.         }
  95.         return $this;
  96.     }
  97. }