src/Entity/Prefecture.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\PrefectureRepository;
  5. use DateTimeImmutable;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. #[ORM\Entity(repositoryClass: PrefectureRepository::class)]
  11. #[ORM\HasLifecycleCallbacks]
  12. class Prefecture
  13. {
  14.     use TimeStampable;
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column(type: 'integer')]
  18.     private ?int $id = null;
  19.     #[ORM\Column(type: 'string', length: 30)]
  20.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  21.     private ?string $name;
  22.     #[ORM\Column(type: 'decimal', precision: 10, scale: 8, nullable: true)]
  23.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  24.     private ?string $latitude;
  25.     
  26.     #[ORM\Column(type: 'decimal', precision: 10, scale: 8, nullable: true)]
  27.     #[Assert\NotBlank(message:"Veuillez remplir ce champ")]
  28.     private ?string $longitude;
  29.     #[ORM\OneToMany(mappedBy: 'prefecture', targetEntity: Municipality::class)]
  30.     private Collection $municipalities;
  31.     #[ORM\ManyToOne]
  32.     private ?User $createdBy = null;
  33.     #[ORM\ManyToOne]
  34.     private ?User $updatedBy = null;
  35.     
  36.     #[ORM\Column]
  37.     private ?bool $isRegion = null;
  38.     #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'prefectures')]
  39.     private ?self $region = null;
  40.     #[ORM\OneToMany(mappedBy: 'region', targetEntity: self::class)]
  41.     private Collection $prefectures;
  42.     public function __construct()
  43.     {
  44.         $this->municipalities = new ArrayCollection();
  45.         $this->createdAt = new DateTimeImmutable();
  46.         $this->updatedAt = new DateTimeImmutable();
  47.         $this->prefectures = new ArrayCollection();
  48.     }
  49.     public function getId(): ?int
  50.     {
  51.         return $this->id;
  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.         return $this;
  61.     }
  62.     public function getLatitude(): ?string
  63.     {
  64.         return $this->latitude;
  65.     }
  66.     public function setLatitude(?string $latitude): self
  67.     {
  68.         $this->latitude = $latitude;
  69.         return $this;
  70.     }
  71.     public function getLongitude(): ?string
  72.     {
  73.         return $this->longitude;
  74.     }
  75.     public function setLongitude(?string $longitude): self
  76.     {
  77.         $this->longitude = $longitude;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @return Collection<int, Municipality>
  82.      */
  83.     public function getMunicipalities(): Collection
  84.     {
  85.         return $this->municipalities;
  86.     }
  87.     public function addMunicipality(Municipality $municipality): self
  88.     {
  89.         if (!$this->municipalities->contains($municipality)) {
  90.             $this->municipalities->add($municipality);
  91.             $municipality->setPrefecture($this);
  92.         }
  93.         return $this;
  94.     }
  95.     public function removeMunicipality(Municipality $municipality): self
  96.     {
  97.         if ($this->municipalities->removeElement($municipality)) {
  98.             // set the owning side to null (unless already changed)
  99.             if ($municipality->getPrefecture() === $this) {
  100.                 $municipality->setPrefecture(null);
  101.             }
  102.         }
  103.         return $this;
  104.     }
  105.     public function __toString()
  106.     {
  107.         return $this->name;
  108.     }
  109.     public function getCreatedBy(): ?User
  110.     {
  111.         return $this->createdBy;
  112.     }
  113.     public function setCreatedBy(?User $createdBy): self
  114.     {
  115.         $this->createdBy = $createdBy;
  116.         return $this;
  117.     }
  118.     public function getUpdatedBy(): ?User
  119.     {
  120.         return $this->updatedBy;
  121.     }
  122.     public function setUpdatedBy(?User $updatedBy): self
  123.     {
  124.         $this->updatedBy = $updatedBy;
  125.         return $this;
  126.     }
  127.     public function getCreatedAt(): ?DateTimeImmutable
  128.     {
  129.         return $this->createdAt;
  130.     }
  131.     public function setCreatedAt(DateTimeImmutable $createdAt): self
  132.     {
  133.         $this->createdAt = $createdAt;
  134.         return $this;
  135.     }
  136.     // public function getUpdatedAt(): ?DateTimeImmutable
  137.     // {
  138.     //     return $this->updatedAt;
  139.     // }
  140.     public function setUpdatedAt(?DateTimeImmutable $updatedAt): self
  141.     {
  142.         $this->updatedAt = $updatedAt;
  143.         return $this;
  144.     }
  145.     public function isIsRegion(): ?bool
  146.     {
  147.         return $this->isRegion;
  148.     }
  149.     public function setIsRegion(bool $isRegion): self
  150.     {
  151.         $this->isRegion = $isRegion;
  152.         return $this;
  153.     }
  154.     public function getRegion(): ?self
  155.     {
  156.         return $this->region;
  157.     }
  158.     public function setRegion(?self $region): self
  159.     {
  160.         $this->region = $region;
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return Collection<int, self>
  165.      */
  166.     public function getPrefectures(): Collection
  167.     {
  168.         return $this->prefectures;
  169.     }
  170.     public function addPrefecture(self $prefecture): self
  171.     {
  172.         if (!$this->prefectures->contains($prefecture)) {
  173.             $this->prefectures->add($prefecture);
  174.             $prefecture->setRegion($this);
  175.         }
  176.         return $this;
  177.     }
  178.     public function removePrefecture(self $prefecture): self
  179.     {
  180.         if ($this->prefectures->removeElement($prefecture)) {
  181.             // set the owning side to null (unless already changed)
  182.             if ($prefecture->getRegion() === $this) {
  183.                 $prefecture->setRegion(null);
  184.             }
  185.         }
  186.         return $this;
  187.     }
  188. }