src/Entity/User.php line 15

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\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10. * @ORM\Entity(repositoryClass=UserRepository::class)
  11. */
  12. class User implements UserInterface, PasswordAuthenticatedUserInterface
  13. {
  14. /**
  15. * @ORM\Id
  16. * @ORM\GeneratedValue
  17. * @ORM\Column(type="integer")
  18. */
  19. private $id;
  20. /**
  21. * @ORM\Column(type="string", length=180, unique=true)
  22. */
  23. private $email;
  24. /**
  25. * @ORM\Column(type="json")
  26. */
  27. private $roles = [];
  28. /**
  29. * @var string The hashed password
  30. * @ORM\Column(type="string")
  31. */
  32. private $password;
  33. /**
  34. * @ORM\OneToOne(targetEntity=Personne::class, inversedBy="user", cascade={"persist", "remove"})
  35. */
  36. private $personne;
  37. /**
  38. * @ORM\OneToOne(targetEntity=Membre::class, mappedBy="user", cascade={"persist", "remove"})
  39. */
  40. private $membre;
  41. /**
  42. * @ORM\OneToOne(targetEntity=Province::class, mappedBy="user", cascade={"persist", "remove"})
  43. */
  44. private $province;
  45. /**
  46. * @ORM\OneToOne(targetEntity=Federation::class, mappedBy="user", cascade={"persist", "remove"})
  47. */
  48. private $federation;
  49. /**
  50. * @ORM\OneToOne(targetEntity=Demande::class, mappedBy="user", cascade={"persist", "remove"})
  51. */
  52. private $demande;
  53. /**
  54. * @ORM\OneToMany(targetEntity=ForumSujet::class, mappedBy="auteur")
  55. */
  56. private $forumSujets;
  57. /**
  58. * @ORM\OneToMany(targetEntity=ForumMessage::class, mappedBy="auteur")
  59. */
  60. private $forumMessages;
  61. public function __construct()
  62. {
  63. $this->forumSujets = new ArrayCollection();
  64. $this->forumMessages = new ArrayCollection();
  65. }
  66. public function getId(): ?int
  67. {
  68. return $this->id;
  69. }
  70. public function getEmail(): ?string
  71. {
  72. return $this->email;
  73. }
  74. public function setEmail(string $email): self
  75. {
  76. $this->email = $email;
  77. return $this;
  78. }
  79. /**
  80. * A visual identifier that represents this user.
  81. *
  82. * @see UserInterface
  83. */
  84. public function getUsername(): string
  85. {
  86. return (string) $this->email;
  87. }
  88. /**
  89. * @see UserInterface
  90. */
  91. public function getRoles(): array
  92. {
  93. $roles = $this->roles;
  94. // guarantee every user at least has ROLE_USER
  95. //$roles[] = 'ROLE_USER';
  96. return array_unique($roles);
  97. }
  98. public function setRoles(array $roles): self
  99. {
  100. $this->roles = $roles;
  101. return $this;
  102. }
  103. /**
  104. * @see PasswordAuthenticatedUserInterface
  105. */
  106. public function getPassword(): string
  107. {
  108. return $this->password;
  109. }
  110. public function setPassword(string $password): self
  111. {
  112. $this->password = $password;
  113. return $this;
  114. }
  115. /**
  116. * Returning a salt is only needed, if you are not using a modern
  117. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  118. *
  119. * @see UserInterface
  120. */
  121. public function getSalt(): ?string
  122. {
  123. return null;
  124. }
  125. /**
  126. * @see UserInterface
  127. */
  128. public function eraseCredentials()
  129. {
  130. // If you store any temporary, sensitive data on the user, clear it here
  131. // $this->plainPassword = null;
  132. }
  133. public function getPersonne(): ?Personne
  134. {
  135. return $this->personne;
  136. }
  137. public function setPersonne(?Personne $personne): self
  138. {
  139. $this->personne = $personne;
  140. return $this;
  141. }
  142. public function getProvince(): ?Province
  143. {
  144. return $this->province;
  145. }
  146. public function getMembre(): ?Membre
  147. {
  148. return $this->membre;
  149. }
  150. public function setMembre(?Membre $membre): self
  151. {
  152. // unset the owning side of the relation if necessary
  153. if ($membre === null && $this->membre !== null) {
  154. $this->membre->setUser(null);
  155. }
  156. // set the owning side of the relation if necessary
  157. if ($membre !== null && $membre->getUser() !== $this) {
  158. $membre->setUser($this);
  159. }
  160. $this->membre = $membre;
  161. return $this;
  162. }
  163. public function getFederation(): ?Federation
  164. {
  165. return $this->federation;
  166. }
  167. public function setFederation(?Federation $federation): self
  168. {
  169. // unset the owning side of the relation if necessary
  170. if ($federation === null && $this->federation !== null) {
  171. $this->federation->setUser(null);
  172. }
  173. // set the owning side of the relation if necessary
  174. if ($federation !== null && $federation->getUser() !== $this) {
  175. $federation->setUser($this);
  176. }
  177. $this->federation = $federation;
  178. return $this;
  179. }
  180. public function getDemande(): ?Demande
  181. {
  182. return $this->demande;
  183. }
  184. public function setDemande(Demande $demande): self
  185. {
  186. // set the owning side of the relation if necessary
  187. if ($demande->getUser() !== $this) {
  188. $demande->setUser($this);
  189. }
  190. $this->demande = $demande;
  191. return $this;
  192. }
  193. /**
  194. * @return Collection<int, ForumSujet>
  195. */
  196. public function getForumSujets(): Collection
  197. {
  198. return $this->forumSujets;
  199. }
  200. public function addForumSujet(ForumSujet $forumSujet): self
  201. {
  202. if (!$this->forumSujets->contains($forumSujet)) {
  203. $this->forumSujets[] = $forumSujet;
  204. $forumSujet->setAuteur($this);
  205. }
  206. return $this;
  207. }
  208. public function removeForumSujet(ForumSujet $forumSujet): self
  209. {
  210. if ($this->forumSujets->removeElement($forumSujet)) {
  211. // set the owning side to null (unless already changed)
  212. if ($forumSujet->getAuteur() === $this) {
  213. $forumSujet->setAuteur(null);
  214. }
  215. }
  216. return $this;
  217. }
  218. /**
  219. * @return Collection<int, ForumMessage>
  220. */
  221. public function getForumMessages(): Collection
  222. {
  223. return $this->forumMessages;
  224. }
  225. public function addForumMessage(ForumMessage $forumMessage): self
  226. {
  227. if (!$this->forumMessages->contains($forumMessage)) {
  228. $this->forumMessages[] = $forumMessage;
  229. $forumMessage->setAuteur($this);
  230. }
  231. return $this;
  232. }
  233. public function removeForumMessage(ForumMessage $forumMessage): self
  234. {
  235. if ($this->forumMessages->removeElement($forumMessage)) {
  236. // set the owning side to null (unless already changed)
  237. if ($forumMessage->getAuteur() === $this) {
  238. $forumMessage->setAuteur(null);
  239. }
  240. }
  241. return $this;
  242. }
  243. }