src/Entity/Municipality.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\MunicipalityRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=MunicipalityRepository::class)
  9. * @ORM\HasLifecycleCallbacks()
  10. */
  11. class Municipality
  12. {
  13. /**
  14. * @ORM\Id
  15. * @ORM\GeneratedValue
  16. * @ORM\Column(type="integer")
  17. */
  18. private $id;
  19. /**
  20. * @ORM\Column(type="string", length=255)
  21. */
  22. private $name;
  23. /**
  24. * @ORM\Column(type="string", length=255)
  25. */
  26. private $location;
  27. /**
  28. * @ORM\Column(type="datetime", nullable=true)
  29. */
  30. private $updadeAt;
  31. /**
  32. * @ORM\OneToMany(targetEntity=Hospital::class, mappedBy="municipality", orphanRemoval=true)
  33. */
  34. private $hospitals;
  35. /**
  36. * @ORM\OneToOne(targetEntity=Subdivision::class, inversedBy="municipality", cascade={"persist", "remove"})
  37. * @ORM\JoinColumn(nullable=false)
  38. */
  39. private $subdivision;
  40. /**
  41. * @ORM\OneToMany(targetEntity=User::class, mappedBy="municipality")
  42. */
  43. private $users;
  44. public function __construct()
  45. {
  46. $this->hospitals = new ArrayCollection();
  47. $this->__updateDate();
  48. $this->users = new ArrayCollection();
  49. }
  50. public function getId(): ?int
  51. {
  52. return $this->id;
  53. }
  54. public function getName(): ?string
  55. {
  56. return $this->name;
  57. }
  58. public function setName(string $name): self
  59. {
  60. $this->name = $name;
  61. return $this;
  62. }
  63. public function getLocation(): ?string
  64. {
  65. return $this->location;
  66. }
  67. public function setLocation(string $location): self
  68. {
  69. $this->location = $location;
  70. return $this;
  71. }
  72. public function getUpdadeAt(): ?\DateTimeInterface
  73. {
  74. return $this->updadeAt;
  75. }
  76. public function setUpdadeAt(?\DateTimeInterface $updadeAt): self
  77. {
  78. $this->updadeAt = $updadeAt;
  79. return $this;
  80. }
  81. /**
  82. * @return Collection|Hospital[]
  83. */
  84. public function getHospitals(): Collection
  85. {
  86. return $this->hospitals;
  87. }
  88. public function addHospital(Hospital $hospital): self
  89. {
  90. if (!$this->hospitals->contains($hospital)) {
  91. $this->hospitals[] = $hospital;
  92. $hospital->setMunicipality($this);
  93. }
  94. return $this;
  95. }
  96. public function removeHospital(Hospital $hospital): self
  97. {
  98. if ($this->hospitals->contains($hospital)) {
  99. $this->hospitals->removeElement($hospital);
  100. // set the owning side to null (unless already changed)
  101. if ($hospital->getMunicipality() === $this) {
  102. $hospital->setMunicipality(null);
  103. }
  104. }
  105. return $this;
  106. }
  107. public function __toString() {
  108. return $this->getName();
  109. }
  110. /**
  111. * @ORM\PreUpdate
  112. */
  113. public function __updateDate() {
  114. $this->setUpdadeAt(new \DateTime());
  115. }
  116. public function getSubdivision(): ?Subdivision
  117. {
  118. return $this->subdivision;
  119. }
  120. public function setSubdivision(Subdivision $subdivision): self
  121. {
  122. $this->subdivision = $subdivision;
  123. return $this;
  124. }
  125. /**
  126. * @return Collection|User[]
  127. */
  128. public function getUsers(): Collection
  129. {
  130. return $this->users;
  131. }
  132. public function addUser(User $user): self
  133. {
  134. if (!$this->users->contains($user)) {
  135. $this->users[] = $user;
  136. $user->setMunicipality($this);
  137. }
  138. return $this;
  139. }
  140. public function removeUser(User $user): self
  141. {
  142. if ($this->users->removeElement($user)) {
  143. // set the owning side to null (unless already changed)
  144. if ($user->getMunicipality() === $this) {
  145. $user->setMunicipality(null);
  146. }
  147. }
  148. return $this;
  149. }
  150. }