src/Entity/Municipality.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\MunicipalityRepository;
  5. use DateTimeImmutable;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity(repositoryClass: MunicipalityRepository::class)]
  10. #[ORM\HasLifecycleCallbacks]
  11. class Municipality
  12. {
  13.     use TimeStampable;
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type: 'integer')]
  17.     private ?int $id = null;
  18.     #[ORM\Column(type: 'string', length: 45)]
  19.     private ?string $name;
  20.     #[ORM\Column(type: 'decimal', precision: 10, scale: 8, nullable: true)]
  21.     private ?string $latitude;
  22.     #[ORM\Column(type: 'decimal', precision: 10, scale: 8, nullable: true)]
  23.     private ?string $longitude;
  24.     #[ORM\ManyToOne(inversedBy: 'municipalities')]
  25.     private ?Prefecture $prefecture = null;
  26.     #[ORM\ManyToOne]
  27.     private ?User $CreatedBy = null;
  28.     #[ORM\ManyToOne]
  29.     private ?User $UpdatedBy = null;
  30.    
  31.    
  32.     #[ORM\OneToMany(mappedBy: 'municipality', targetEntity: District::class)]
  33.     private Collection $districts;
  34.     public function __construct()
  35.     {
  36.         $this->createdAt = new DateTimeImmutable();
  37.         $this->updatedAt = new DateTimeImmutable();
  38.         $this->districts = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getName(): ?string
  45.     {
  46.         return $this->name;
  47.     }
  48.     public function setName(string $name): self
  49.     {
  50.         $this->name = $name;
  51.         return $this;
  52.     }
  53.     public function getLatitude(): ?string
  54.     {
  55.         return $this->latitude;
  56.     }
  57.     public function setLatitude(?string $latitude): self
  58.     {
  59.         $this->latitude = $latitude;
  60.         return $this;
  61.     }
  62.     public function getLongitude(): ?string
  63.     {
  64.         return $this->longitude;
  65.     }
  66.     public function setLongitude(?string $longitude): self
  67.     {
  68.         $this->longitude = $longitude;
  69.         return $this;
  70.     }
  71.     public function getPrefecture(): ?Prefecture
  72.     {
  73.         return $this->prefecture;
  74.     }
  75.     public function setPrefecture(?Prefecture $prefecture): self
  76.     {
  77.         $this->prefecture = $prefecture;
  78.         return $this;
  79.     }
  80.     public function getCreatedBy(): ?User
  81.     {
  82.         return $this->CreatedBy;
  83.     }
  84.     public function setCreatedBy(?User $CreatedBy): self
  85.     {
  86.         $this->CreatedBy = $CreatedBy;
  87.         return $this;
  88.     }
  89.     public function getUpdatedBy(): ?User
  90.     {
  91.         return $this->UpdatedBy;
  92.     }
  93.     public function setUpdatedBy(?User $UpdatedBy): self
  94.     {
  95.         $this->UpdatedBy = $UpdatedBy;
  96.         return $this;
  97.     }
  98.     public function getCreatedAt(): ?DateTimeImmutable
  99.     {
  100.         return $this->createdAt;
  101.     }
  102.     public function setCreatedAt(DateTimeImmutable $createdAt): self
  103.     {
  104.         $this->createdAt = $createdAt;
  105.         return $this;
  106.     }
  107.     // public function getUpdatedAt(): ?DateTimeImmutable
  108.     // {
  109.     //     return $this->updatedAt;
  110.     // }
  111.     public function setUpdatedAt(?DateTimeImmutable $updatedAt): self
  112.     {
  113.         $this->updatedAt = $updatedAt;
  114.         return $this;
  115.     }
  116.     public function __toString()
  117.     {
  118.         return $this->name;
  119.     }
  120.     /**
  121.      * @return Collection<int, District>
  122.      */
  123.     public function getDistricts(): Collection
  124.     {
  125.         return $this->districts;
  126.     }
  127.     public function addDistrict(District $district): self
  128.     {
  129.         if (!$this->districts->contains($district)) {
  130.             $this->districts->add($district);
  131.             $district->setMunicipality($this);
  132.         }
  133.         return $this;
  134.     }
  135.     public function removeDistrict(District $district): self
  136.     {
  137.         if ($this->districts->removeElement($district)) {
  138.             // set the owning side to null (unless already changed)
  139.             if ($district->getMunicipality() === $this) {
  140.                 $district->setMunicipality(null);
  141.             }
  142.         }
  143.         return $this;
  144.     }
  145. }