src/Entity/User.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimestampableTrait;
  4. use App\Repository\UserRepository;
  5. use DateTimeImmutable;
  6. use DateTimeInterface;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Security\Core\User\EquatableInterface;
  11. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. /**
  14. * @ORM\Entity(repositoryClass=UserRepository::class)
  15. */
  16. class User implements UserInterface, PasswordAuthenticatedUserInterface, EquatableInterface
  17. {
  18. use TimestampableTrait;
  19. /**
  20. * @ORM\Id
  21. * @ORM\GeneratedValue
  22. * @ORM\Column(type="integer")
  23. */
  24. private $id;
  25. /**
  26. * @ORM\Column(type="string", length=255)
  27. */
  28. private $email;
  29. /**
  30. * @ORM\Column(type="string", length=255)
  31. */
  32. private $password;
  33. /**
  34. * @ORM\Column(type="string", length=255, nullable=true)
  35. */
  36. private $firstname;
  37. /**
  38. * @ORM\Column(type="string", length=255, nullable=true)
  39. */
  40. private $lastname;
  41. /**
  42. * @ORM\Column(type="json")
  43. */
  44. private $roles = [];
  45. /**
  46. * @ORM\OneToMany(targetEntity=Demand::class, mappedBy="user")
  47. */
  48. private $demands;
  49. /**
  50. * @ORM\Column(type="date", nullable=true)
  51. */
  52. private $dateOfBirth;
  53. /**
  54. * @ORM\Column(type="string", length=10, nullable=true)
  55. */
  56. private $phone;
  57. /**
  58. * @ORM\OneToMany(targetEntity=Company::class, mappedBy="user", orphanRemoval=true)
  59. */
  60. private $companies;
  61. /**
  62. * @ORM\OneToMany(targetEntity=File::class, mappedBy="user", orphanRemoval=true)
  63. */
  64. private $files;
  65. /**
  66. * @ORM\OneToMany(targetEntity=Token::class, mappedBy="user", orphanRemoval=true)
  67. */
  68. private $tokens;
  69. /**
  70. * @ORM\OneToMany(targetEntity=Article::class, mappedBy="user", orphanRemoval=true)
  71. */
  72. private $articles;
  73. /**
  74. * @ORM\OneToMany(targetEntity=News::class, mappedBy="user", orphanRemoval=true)
  75. */
  76. private $news;
  77. /**
  78. * @ORM\Column(type="boolean")
  79. */
  80. private $completed = false;
  81. /**
  82. * @ORM\Column(type="boolean")
  83. */
  84. private $archived = false;
  85. /**
  86. * @ORM\Column(type="boolean")
  87. */
  88. private $commitmentCharterValidated = false;
  89. /**
  90. * @ORM\Column(type="datetime_immutable", nullable=true)
  91. */
  92. private $commitmentCharterValidatedAt;
  93. public function __construct()
  94. {
  95. $this->demands = new ArrayCollection();
  96. $this->companies = new ArrayCollection();
  97. $this->files = new ArrayCollection();
  98. $this->tokens = new ArrayCollection();
  99. $this->articles = new ArrayCollection();
  100. $this->news = new ArrayCollection();
  101. }
  102. public function getId(): ?int
  103. {
  104. return $this->id;
  105. }
  106. public function getEmail(): ?string
  107. {
  108. return $this->email;
  109. }
  110. public function setEmail(string $email): self
  111. {
  112. $this->email = $email;
  113. return $this;
  114. }
  115. public function getPassword(): ?string
  116. {
  117. return $this->password;
  118. }
  119. public function setPassword(string $password): self
  120. {
  121. $this->password = $password;
  122. return $this;
  123. }
  124. public function getFirstname(): ?string
  125. {
  126. return $this->firstname;
  127. }
  128. public function setFirstname(string $firstname): self
  129. {
  130. $this->firstname = $firstname;
  131. return $this;
  132. }
  133. public function getLastname(): ?string
  134. {
  135. return $this->lastname;
  136. }
  137. public function setLastname(string $lastname): self
  138. {
  139. $this->lastname = $lastname;
  140. return $this;
  141. }
  142. public function getRoles(): ?array
  143. {
  144. $roles = $this->roles;
  145. // guarantee every user at least has ROLE_USER
  146. $roles[] = 'ROLE_USER';
  147. return array_unique($roles);
  148. }
  149. public function setRoles(array $roles): self
  150. {
  151. $this->roles = $roles;
  152. return $this;
  153. }
  154. public function getDateOfBirth(): ?DateTimeInterface
  155. {
  156. return $this->dateOfBirth;
  157. }
  158. public function setDateOfBirth(DateTimeInterface $dateOfBirth): self
  159. {
  160. $this->dateOfBirth = $dateOfBirth;
  161. return $this;
  162. }
  163. /**
  164. * @return Collection|Demand[]
  165. */
  166. public function getDemands(): Collection
  167. {
  168. return $this->demands;
  169. }
  170. public function addDemand(Demand $demand): self
  171. {
  172. if (!$this->demands->contains($demand)) {
  173. $this->demands[] = $demand;
  174. $demand->setUser($this);
  175. }
  176. return $this;
  177. }
  178. public function removeDemand(Demand $demand): self
  179. {
  180. if ($this->demands->removeElement($demand)) {
  181. // set the owning side to null (unless already changed)
  182. if ($demand->getUser() === $this) {
  183. $demand->setUser(null);
  184. }
  185. }
  186. return $this;
  187. }
  188. public function getSalt()
  189. {
  190. return null;
  191. }
  192. public function eraseCredentials()
  193. {
  194. return null;
  195. }
  196. public function getUsername()
  197. {
  198. return $this->getUserIdentifier();
  199. }
  200. public function getUserIdentifier()
  201. {
  202. return $this->email;
  203. }
  204. public function getPhone(): ?string
  205. {
  206. return $this->phone;
  207. }
  208. public function setPhone(string $phone): self
  209. {
  210. $this->phone = $phone;
  211. return $this;
  212. }
  213. public function isEqualTo(UserInterface|User $user): bool
  214. {
  215. // TODO: Implement isEqualTo() method.
  216. return $this->id === $user->getId();
  217. }
  218. /**
  219. * @return Collection|Company[]
  220. */
  221. public function getCompanies(): Collection
  222. {
  223. return $this->companies;
  224. }
  225. public function addCompany(Company $company): self
  226. {
  227. if (!$this->companies->contains($company)) {
  228. $this->companies[] = $company;
  229. $company->setUser($this);
  230. }
  231. return $this;
  232. }
  233. public function removeCompany(Company $company): self
  234. {
  235. if ($this->companies->removeElement($company)) {
  236. // set the owning side to null (unless already changed)
  237. if ($company->getUser() === $this) {
  238. $company->setUser(null);
  239. }
  240. }
  241. return $this;
  242. }
  243. /**
  244. * @return Collection|File[]
  245. */
  246. public function getFiles(): Collection
  247. {
  248. return $this->files;
  249. }
  250. public function addFile(File $file): self
  251. {
  252. if (!$this->files->contains($file)) {
  253. $this->files[] = $file;
  254. $file->setUser($this);
  255. }
  256. return $this;
  257. }
  258. public function removeFile(File $file): self
  259. {
  260. if ($this->files->removeElement($file)) {
  261. // set the owning side to null (unless already changed)
  262. if ($file->getUser() === $this) {
  263. $file->setUser(null);
  264. }
  265. }
  266. return $this;
  267. }
  268. /**
  269. * @return Collection|Token[]
  270. */
  271. public function getTokens(): Collection
  272. {
  273. return $this->tokens;
  274. }
  275. public function addToken(Token $token): self
  276. {
  277. if (!$this->tokens->contains($token)) {
  278. $this->tokens[] = $token;
  279. $token->setUser($this);
  280. }
  281. return $this;
  282. }
  283. public function removeToken(Token $token): self
  284. {
  285. if ($this->tokens->removeElement($token)) {
  286. // set the owning side to null (unless already changed)
  287. if ($token->getUser() === $this) {
  288. $token->setUser(null);
  289. }
  290. }
  291. return $this;
  292. }
  293. /**
  294. * @return Collection|Article[]
  295. */
  296. public function getArticles(): Collection
  297. {
  298. return $this->articles;
  299. }
  300. public function addArticle(Article $article): self
  301. {
  302. if (!$this->articles->contains($article)) {
  303. $this->articles[] = $article;
  304. $article->setUser($this);
  305. }
  306. return $this;
  307. }
  308. public function removeArticle(Article $article): self
  309. {
  310. if ($this->articles->removeElement($article)) {
  311. // set the owning side to null (unless already changed)
  312. if ($article->getUser() === $this) {
  313. $article->setUser(null);
  314. }
  315. }
  316. return $this;
  317. }
  318. /**
  319. * @return Collection|News[]
  320. */
  321. public function getNews(): Collection
  322. {
  323. return $this->news;
  324. }
  325. public function addNews(News $news): self
  326. {
  327. if (!$this->news->contains($news)) {
  328. $this->news[] = $news;
  329. $news->setUser($this);
  330. }
  331. return $this;
  332. }
  333. public function removeNews(News $news): self
  334. {
  335. if ($this->news->removeElement($news)) {
  336. // set the owning side to null (unless already changed)
  337. if ($news->getUser() === $this) {
  338. $news->setUser(null);
  339. }
  340. }
  341. return $this;
  342. }
  343. public function isCompleted(): ?bool
  344. {
  345. return $this->completed;
  346. }
  347. public function setCompleted(bool $completed): self
  348. {
  349. $this->completed = $completed;
  350. return $this;
  351. }
  352. public function getArchived(): ?bool
  353. {
  354. return $this->archived;
  355. }
  356. public function setArchived(bool $archived): self
  357. {
  358. $this->archived = $archived;
  359. return $this;
  360. }
  361. public function isCommitmentCharterValidated(): ?bool
  362. {
  363. return $this->commitmentCharterValidated;
  364. }
  365. public function setCommitmentCharterValidated(bool $commitmentCharterValidated): self
  366. {
  367. $this->commitmentCharterValidated = $commitmentCharterValidated;
  368. return $this;
  369. }
  370. public function getCommitmentCharterValidatedAt(): ?DateTimeImmutable
  371. {
  372. return $this->commitmentCharterValidatedAt;
  373. }
  374. public function setCommitmentCharterValidatedAt(?DateTimeImmutable $commitmentCharterValidatedAt): self
  375. {
  376. $this->commitmentCharterValidatedAt = $commitmentCharterValidatedAt;
  377. return $this;
  378. }
  379. }