src/Entity/User.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10. * @ORM\Entity(repositoryClass=UserRepository::class)
  11. * @UniqueEntity(fields={"username"}, message="There is already an account with this username")
  12. * @ORM\HasLifecycleCallbacks()
  13. */
  14. class User implements UserInterface
  15. {
  16. /**
  17. * @ORM\Id
  18. * @ORM\GeneratedValue
  19. * @ORM\Column(type="integer")
  20. */
  21. private $id;
  22. /**
  23. * @ORM\Column(type="string", length=180, unique=true)
  24. */
  25. private $username;
  26. /**
  27. * @ORM\Column(type="string", length=255)
  28. */
  29. private $email;
  30. /**
  31. * @ORM\Column(type="json")
  32. */
  33. private $roles = [];
  34. /**
  35. * @var string The hashed password
  36. * @ORM\Column(type="string")
  37. */
  38. private $password;
  39. /**
  40. * @ORM\Column(type="datetime")
  41. */
  42. private $dateDeNaissance;
  43. /**
  44. * @ORM\Column(type="string", length=255, nullable=true)
  45. */
  46. private $lieuDeNaissance;
  47. /**
  48. * @ORM\Column(type="string", length=255)
  49. */
  50. private $locale;
  51. /**
  52. * @ORM\Column(type="datetime", nullable=true)
  53. */
  54. private $updateAt;
  55. /**
  56. * @ORM\ManyToOne(targetEntity=Hospital::class, inversedBy="users")
  57. */
  58. private $hospital;
  59. /**
  60. * @ORM\ManyToOne(targetEntity=Municipality::class, inversedBy="users")
  61. */
  62. private $municipality;
  63. /**
  64. * @ORM\OneToMany(targetEntity=Child::class, mappedBy="user")
  65. */
  66. private $children;
  67. public function __construct() {
  68. $this->setUpdateAt(new \DateTime());
  69. $this->children = new ArrayCollection();
  70. }
  71. public function getId(): ?int
  72. {
  73. return $this->id;
  74. }
  75. public function getUsername(): ?string
  76. {
  77. return $this->username;
  78. }
  79. public function setUsername(string $username): self
  80. {
  81. $this->username = $username;
  82. return $this;
  83. }
  84. public function getRoles(): ?array
  85. {
  86. return $this->roles;
  87. }
  88. public function setRoles(array $roles): self
  89. {
  90. $this->roles = $roles;
  91. return $this;
  92. }
  93. public function getPassword(): ?string
  94. {
  95. return $this->password;
  96. }
  97. public function setPassword(string $password): self
  98. {
  99. $this->password = $password;
  100. return $this;
  101. }
  102. /**
  103. * @see UserInterface
  104. */
  105. public function getSalt()
  106. {
  107. // not needed when using the "bcrypt" algorithm in security.yaml
  108. }
  109. /**
  110. * @see UserInterface
  111. */
  112. public function eraseCredentials()
  113. {
  114. // If you store any temporary, sensitive data on the user, clear it here
  115. // $this->plainPassword = null;
  116. }
  117. public function getEmail(): ?string
  118. {
  119. return $this->email;
  120. }
  121. public function setEmail(string $email): self
  122. {
  123. $this->email = $email;
  124. return $this;
  125. }
  126. public function getDateDeNaissance(): ?\DateTimeInterface
  127. {
  128. return $this->dateDeNaissance;
  129. }
  130. public function setDateDeNaissance(\DateTimeInterface $dateDeNaissance): self
  131. {
  132. $this->dateDeNaissance = $dateDeNaissance;
  133. return $this;
  134. }
  135. public function getLieuDeNaissance(): ?string
  136. {
  137. return $this->lieuDeNaissance;
  138. }
  139. public function setLieuDeNaissance(?string $lieuDeNaissance): self
  140. {
  141. $this->lieuDeNaissance = $lieuDeNaissance;
  142. return $this;
  143. }
  144. public function getLocale(): ?string
  145. {
  146. return $this->locale;
  147. }
  148. public function setLocale(string $locale): self
  149. {
  150. $this->locale = $locale;
  151. return $this;
  152. }
  153. public function __toString() {
  154. return $this->getUsername();
  155. }
  156. public function getUpdateAt(): ?\DateTimeInterface
  157. {
  158. return $this->updateAt;
  159. }
  160. public function setUpdateAt(?\DateTimeInterface $updateAt): self
  161. {
  162. $this->updateAt = $updateAt;
  163. return $this;
  164. }
  165. public function getHospital(): ?Hospital
  166. {
  167. return $this->hospital;
  168. }
  169. public function setHospital(?Hospital $hospital): self
  170. {
  171. $this->hospital = $hospital;
  172. return $this;
  173. }
  174. public function getMunicipality(): ?municipality
  175. {
  176. return $this->municipality;
  177. }
  178. public function setMunicipality(?municipality $municipality): self
  179. {
  180. $this->municipality = $municipality;
  181. return $this;
  182. }
  183. /**
  184. * @return Collection|Child[]
  185. */
  186. public function getChildren(): Collection
  187. {
  188. return $this->children;
  189. }
  190. public function addChild(Child $child): self
  191. {
  192. if (!$this->children->contains($child)) {
  193. $this->children[] = $child;
  194. $child->setUser($this);
  195. }
  196. return $this;
  197. }
  198. public function removeChild(Child $child): self
  199. {
  200. if ($this->children->removeElement($child)) {
  201. // set the owning side to null (unless already changed)
  202. if ($child->getUser() === $this) {
  203. $child->setUser(null);
  204. }
  205. }
  206. return $this;
  207. }
  208. }