src/Entity/User.php line 13

  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. #[ORM\Entity(repositoryClass: UserRepository::class)]
  10. class User implements UserInterface, PasswordAuthenticatedUserInterface
  11. {
  12. #[ORM\Id]
  13. #[ORM\GeneratedValue]
  14. #[ORM\Column(type: 'integer')]
  15. private $id;
  16. #[ORM\Column(type: 'string', length: 180, unique: true)]
  17. private $email;
  18. #[ORM\Column(type: 'json')]
  19. private $roles = [];
  20. /**
  21. * @var string The hashed password
  22. */
  23. #[ORM\Column(type: 'string', nullable: true)]
  24. private $password;
  25. #[ORM\Column(type: 'string', length: 255)]
  26. private $firstName;
  27. #[ORM\Column(type: 'string', length: 255)]
  28. private $lastName;
  29. #[ORM\Column(type: 'datetime')]
  30. private $modified;
  31. #[ORM\Column(type: 'datetime')]
  32. private $created;
  33. #[ORM\OneToMany(targetEntity: ArticleDetails::class, mappedBy: 'user')]
  34. private $articleDetails;
  35. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  36. private $hashedEmail;
  37. public function __construct()
  38. {
  39. $date = new \DateTime("now", new \DateTimeZone('Asia/Dubai'));
  40. $this->setModified($date);
  41. if ($this->getCreated() == null)
  42. {
  43. $this->setCreated($date);
  44. }
  45. $this->articleDetails = new ArrayCollection();
  46. }
  47. public function getId(): ?int
  48. {
  49. return $this->id;
  50. }
  51. public function getEmail(): ?string
  52. {
  53. return $this->email;
  54. }
  55. public function setEmail(string $email): self
  56. {
  57. $this->email = $email;
  58. return $this;
  59. }
  60. /**
  61. * A visual identifier that represents this user.
  62. *
  63. * @see UserInterface
  64. */
  65. public function getUserIdentifier(): string
  66. {
  67. return (string) $this->email;
  68. }
  69. /**
  70. * @deprecated since Symfony 5.3, use getUserIdentifier instead
  71. */
  72. public function getUsername(): string
  73. {
  74. return (string) $this->email;
  75. }
  76. /**
  77. * @see UserInterface
  78. */
  79. public function getRoles(): array
  80. {
  81. $roles = $this->roles;
  82. // guarantee every user at least has ROLE_USER
  83. $roles[] = 'ROLE_USER';
  84. return array_unique($roles);
  85. }
  86. public function setRoles(array $roles): self
  87. {
  88. $this->roles = $roles;
  89. return $this;
  90. }
  91. /**
  92. * @see PasswordAuthenticatedUserInterface
  93. */
  94. public function getPassword(): string
  95. {
  96. return $this->password;
  97. }
  98. public function setPassword(string $password): self
  99. {
  100. $this->password = $password;
  101. return $this;
  102. }
  103. /**
  104. * Returning a salt is only needed, if you are not using a modern
  105. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  106. *
  107. * @see UserInterface
  108. */
  109. public function getSalt(): ?string
  110. {
  111. return null;
  112. }
  113. /**
  114. * @see UserInterface
  115. */
  116. public function eraseCredentials()
  117. {
  118. // If you inventory any temporary, sensitive data on the user, clear it here
  119. // $this->plainPassword = null;
  120. }
  121. public function getFirstName(): ?string
  122. {
  123. return $this->firstName;
  124. }
  125. public function setFirstName(string $firstName): self
  126. {
  127. $this->firstName = $firstName;
  128. return $this;
  129. }
  130. public function getLastName(): ?string
  131. {
  132. return $this->lastName;
  133. }
  134. public function setLastName(string $lastName): self
  135. {
  136. $this->lastName = $lastName;
  137. return $this;
  138. }
  139. public function getModified(): ?\DateTimeInterface
  140. {
  141. return $this->modified;
  142. }
  143. public function setModified(\DateTimeInterface $modified): self
  144. {
  145. $this->modified = $modified;
  146. return $this;
  147. }
  148. public function getCreated(): ?\DateTimeInterface
  149. {
  150. return $this->created;
  151. }
  152. public function setCreated(\DateTimeInterface $created): self
  153. {
  154. $this->created = $created;
  155. return $this;
  156. }
  157. /**
  158. * @return Collection<int, ArticleDetails>
  159. */
  160. public function getArticleDetails(): Collection
  161. {
  162. return $this->articleDetails;
  163. }
  164. public function addArticleDetail(ArticleDetails $articleDetail): self
  165. {
  166. if (!$this->articleDetails->contains($articleDetail)) {
  167. $this->articleDetails[] = $articleDetail;
  168. $articleDetail->setUser($this);
  169. }
  170. return $this;
  171. }
  172. public function removeArticleDetail(ArticleDetails $articleDetail): self
  173. {
  174. if ($this->articleDetails->removeElement($articleDetail)) {
  175. // set the owning side to null (unless already changed)
  176. if ($articleDetail->getUser() === $this) {
  177. $articleDetail->setUser(null);
  178. }
  179. }
  180. return $this;
  181. }
  182. public function getHashedEmail(): ?string
  183. {
  184. return $this->hashedEmail;
  185. }
  186. public function setHashedEmail(?string $hashedEmail): self
  187. {
  188. $this->hashedEmail = $hashedEmail;
  189. return $this;
  190. }
  191. }