src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Contest\Team;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. /**
  10. * @ORM\Entity()
  11. * @UniqueEntity(fields={"email"})
  12. * @UniqueEntity(fields={"username"})
  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=180, nullable=true)
  28. */
  29. private $firstname;
  30. /**
  31. * @ORM\Column(type="string", length=180, nullable=true)
  32. */
  33. private $lastname;
  34. /**
  35. * @ORM\Column(type="string", length=180, unique=true)
  36. */
  37. private $email;
  38. /**
  39. * @ORM\Column(type="json")
  40. */
  41. private $roles = [];
  42. /**
  43. * @var string The hashed password
  44. * @ORM\Column(type="string")
  45. */
  46. private $password;
  47. /**
  48. * @ORM\Column(name="enabled", type="boolean")
  49. */
  50. protected $enabled = false;
  51. /**
  52. * @ORM\OneToMany(targetEntity=Answear::class, mappedBy="user", orphanRemoval=true)
  53. */
  54. private $answears;
  55. public function __construct()
  56. {
  57. $this->answears = new ArrayCollection();
  58. }
  59. public function getId(): ?int
  60. {
  61. return $this->id;
  62. }
  63. public function getEmail(): ?string
  64. {
  65. return $this->email;
  66. }
  67. public function setEmail(string $email): self
  68. {
  69. $this->email = $email;
  70. return $this;
  71. }
  72. /**
  73. * @see UserInterface
  74. */
  75. public function getRoles(): array
  76. {
  77. $roles = $this->roles;
  78. // guarantee every user at least has ROLE_USER
  79. $roles[] = 'ROLE_USER';
  80. return array_unique($roles);
  81. }
  82. public function setRoles(array $roles): self
  83. {
  84. $this->roles = $roles;
  85. return $this;
  86. }
  87. /**
  88. * @see UserInterface
  89. */
  90. public function getPassword(): string
  91. {
  92. return (string)$this->password;
  93. }
  94. public function setPassword(string $password): self
  95. {
  96. $this->password = $password;
  97. return $this;
  98. }
  99. /**
  100. * @see UserInterface
  101. */
  102. public function getSalt()
  103. {
  104. // not needed when using the "bcrypt" algorithm in security.yaml
  105. }
  106. /**
  107. * @see UserInterface
  108. */
  109. public function eraseCredentials()
  110. {
  111. // If you store any temporary, sensitive data on the user, clear it here
  112. // $this->plainPassword = null;
  113. }
  114. /**
  115. * @return bool
  116. */
  117. public function isEnabled(): bool
  118. {
  119. return (bool)$this->enabled;
  120. }
  121. /**
  122. * @param bool $enabled
  123. * @return User
  124. */
  125. public function setEnabled(bool $enabled): self
  126. {
  127. $this->enabled = $enabled;
  128. return $this;
  129. }
  130. public function __toString()
  131. {
  132. return "".$this->getUsername();
  133. }
  134. /**
  135. * @return mixed
  136. */
  137. public function getUsername()
  138. {
  139. return $this->username;
  140. }
  141. /**
  142. * @param mixed $username
  143. * @return User
  144. */
  145. public function setUsername($username)
  146. {
  147. $this->username = $username;
  148. return $this;
  149. }
  150. /**
  151. * @return mixed
  152. */
  153. public function getFirstname()
  154. {
  155. return $this->firstname;
  156. }
  157. /**
  158. * @param mixed $firstname
  159. * @return User
  160. */
  161. public function setFirstname($firstname)
  162. {
  163. $this->firstname = $firstname;
  164. return $this;
  165. }
  166. /**
  167. * @return mixed
  168. */
  169. public function getLastname()
  170. {
  171. return $this->lastname;
  172. }
  173. /**
  174. * @param mixed $lastname
  175. * @return User
  176. */
  177. public function setLastname($lastname)
  178. {
  179. $this->lastname = $lastname;
  180. return $this;
  181. }
  182. /**
  183. * @return Collection|Answear[]
  184. */
  185. public function getAnswears(): Collection
  186. {
  187. return $this->answears;
  188. }
  189. public function addAnswear(Answear $answear): self
  190. {
  191. if (!$this->answears->contains($answear)) {
  192. $this->answears[] = $answear;
  193. $answear->setUser($this);
  194. }
  195. return $this;
  196. }
  197. public function removeAnswear(Answear $answear): self
  198. {
  199. if ($this->answears->removeElement($answear)) {
  200. // set the owning side to null (unless already changed)
  201. if ($answear->getUser() === $this) {
  202. $answear->setUser(null);
  203. }
  204. }
  205. return $this;
  206. }
  207. }