src/Entity/Province.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProvinceRepository;
  4. use App\Traits\TimeStampTrait;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassProvinceRepository::class)]
  9. #[ORM\HasLifecycleCallbacks]
  10. class Province
  11. {
  12.     use TimeStampTrait;
  13.     #[ORM\Id]
  14.     #[ORM\GeneratedValue]
  15.     #[ORM\Column]
  16.     private ?int $id null;
  17.     #[ORM\Column(length100)]
  18.     private ?string $code null;
  19.     #[ORM\Column(length30nullabletrue)]
  20.     private ?string $name null;
  21.     #[ORM\Column(length10)]
  22.     private ?string $isoCode null;
  23.     #[ORM\ManyToOne(inversedBy'provinces')]
  24.     private ?Country $country null;
  25.     #[ORM\OneToMany(mappedBy'province'targetEntityResidence::class)]
  26.     private Collection $residences;
  27.     public function __construct()
  28.     {
  29.         $this->residences = new ArrayCollection();
  30.     }
  31.     public function getId(): ?int
  32.     {
  33.         return $this->id;
  34.     }
  35.     public function getCode(): ?string
  36.     {
  37.         return $this->code;
  38.     }
  39.     public function setCode(string $code): static
  40.     {
  41.         $this->code $code;
  42.         return $this;
  43.     }
  44.     public function getName(): ?string
  45.     {
  46.         return $this->name;
  47.     }
  48.     public function setName(?string $name): static
  49.     {
  50.         $this->name $name;
  51.         return $this;
  52.     }
  53.     public function getIsoCode(): ?string
  54.     {
  55.         return $this->isoCode;
  56.     }
  57.     public function setIsoCode(string $isoCode): static
  58.     {
  59.         $this->isoCode $isoCode;
  60.         return $this;
  61.     }
  62.     public function getCountry(): ?Country
  63.     {
  64.         return $this->country;
  65.     }
  66.     public function setCountry(?Country $country): static
  67.     {
  68.         $this->country $country;
  69.         return $this;
  70.     }
  71.     /**
  72.      * @return Collection<int, Residence>
  73.      */
  74.     public function getResidences(): Collection
  75.     {
  76.         return $this->residences;
  77.     }
  78.     public function addResidence(Residence $residence): static
  79.     {
  80.         if (!$this->residences->contains($residence)) {
  81.             $this->residences->add($residence);
  82.             $residence->setProvince($this);
  83.         }
  84.         return $this;
  85.     }
  86.     public function removeResidence(Residence $residence): static
  87.     {
  88.         if ($this->residences->removeElement($residence)) {
  89.             // set the owning side to null (unless already changed)
  90.             if ($residence->getProvince() === $this) {
  91.                 $residence->setProvince(null);
  92.             }
  93.         }
  94.         return $this;
  95.     }
  96.     public function __toString(): string
  97.     {
  98.         return $this->name;
  99.     }
  100. }