src/Entity/User.php line 20

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\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. #[ORM\Entity(repositoryClass: UserRepository::class)]
  13. #[ORM\Table(name: '`user`')]
  14. #[ORM\HasLifecycleCallbacks]
  15. #[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
  16. #[UniqueEntity(fields: ['apiKey'], message: 'There is already an account with this API key')]
  17. class User implements UserInterface, PasswordAuthenticatedUserInterface
  18. {
  19. use TimestampableEntity;
  20. #[ORM\Id]
  21. #[ORM\GeneratedValue]
  22. #[ORM\Column]
  23. private ?int $id = null;
  24. #[ORM\Column(length: 180, unique: true)]
  25. private ?string $email = null;
  26. #[ORM\Column]
  27. private array $roles = [];
  28. /**
  29. * @var string The hashed password
  30. */
  31. #[ORM\Column]
  32. private ?string $password = null;
  33. #[ORM\Column(length: 255)]
  34. private ?string $firstName = null;
  35. #[ORM\Column(length: 255)]
  36. private ?string $lastName = null;
  37. #[ORM\Column(type: 'boolean')]
  38. private $isVerified = false;
  39. #[ORM\OneToMany(mappedBy: 'user', targetEntity: Product::class, orphanRemoval: true)]
  40. private Collection $products;
  41. #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserStore::class)]
  42. private Collection $userStores;
  43. #[ORM\Column(length: 255, nullable: true)]
  44. private ?string $stripe_customer_id = null;
  45. #[ORM\Column(nullable: true)]
  46. private ?\DateTimeImmutable $lastLogin = null;
  47. #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserProductImage::class, orphanRemoval: true)]
  48. private Collection $userProductImages;
  49. #[ORM\Column(length: 255, unique: true)]
  50. private ?string $apiKey = null;
  51. #[ORM\Column(length: 255)]
  52. private ?string $apiKeyShippo = null;
  53. #[ORM\OneToMany(mappedBy: 'user', targetEntity: PurchaseAPOD::class)]
  54. private Collection $purchaseAPODs;
  55. public function __construct()
  56. {
  57. $this->products = new ArrayCollection();
  58. $this->userStores = new ArrayCollection();
  59. $this->userProductImages = new ArrayCollection();
  60. }
  61. public function getId(): ?int
  62. {
  63. return $this->id;
  64. }
  65. public function getEmail(): ?string
  66. {
  67. return $this->email;
  68. }
  69. public function setEmail(string $email): self
  70. {
  71. $this->email = $email;
  72. return $this;
  73. }
  74. /**
  75. * A visual identifier that represents this user.
  76. *
  77. * @see UserInterface
  78. */
  79. public function getUserIdentifier(): string
  80. {
  81. return (string) $this->email;
  82. }
  83. /**
  84. * @deprecated since Symfony 5.3, use getUserIdentifier instead
  85. */
  86. public function getUsername(): string
  87. {
  88. return (string) $this->email;
  89. }
  90. public function getRoles(): array
  91. {
  92. return $this->roles;
  93. }
  94. public function setRoles(array $roles): self
  95. {
  96. $this->roles = $roles;
  97. return $this;
  98. }
  99. public function getPassword(): ?string
  100. {
  101. return $this->password;
  102. }
  103. public function setPassword(string $password): self
  104. {
  105. $this->password = $password;
  106. return $this;
  107. }
  108. /**
  109. * Returning a salt is only needed, if you are not using a modern
  110. * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  111. *
  112. * @see UserInterface
  113. */
  114. public function getSalt(): ?string
  115. {
  116. return null;
  117. }
  118. /**
  119. * @see UserInterface
  120. */
  121. public function eraseCredentials()
  122. {
  123. // If you store any temporary, sensitive data on the user, clear it here
  124. // $this->plainPassword = null;
  125. }
  126. public function getFirstName(): ?string
  127. {
  128. return $this->firstName;
  129. }
  130. public function setFirstName(string $firstName): self
  131. {
  132. $this->firstName = $firstName;
  133. return $this;
  134. }
  135. public function getLastName(): ?string
  136. {
  137. return $this->lastName;
  138. }
  139. public function setLastName(string $lastName): self
  140. {
  141. $this->lastName = $lastName;
  142. return $this;
  143. }
  144. public function isVerified(): bool
  145. {
  146. return $this->isVerified;
  147. }
  148. public function setIsVerified(bool $isVerified): self
  149. {
  150. $this->isVerified = $isVerified;
  151. return $this;
  152. }
  153. /**
  154. * @return Collection<int, Product>
  155. */
  156. public function getProducts(): Collection
  157. {
  158. return $this->products;
  159. }
  160. public function addProduct(Product $product): self
  161. {
  162. if (!$this->products->contains($product)) {
  163. $this->products->add($product);
  164. $product->setUser($this);
  165. }
  166. return $this;
  167. }
  168. public function removeProduct(Product $product): self
  169. {
  170. if ($this->products->removeElement($product)) {
  171. // set the owning side to null (unless already changed)
  172. if ($product->getUser() === $this) {
  173. $product->setUser(null);
  174. }
  175. }
  176. return $this;
  177. }
  178. public function isIsVerified(): ?bool
  179. {
  180. return $this->isVerified;
  181. }
  182. /**
  183. * @return Collection<int, UserStore>
  184. */
  185. public function getUserStores(): Collection
  186. {
  187. return $this->userStores;
  188. }
  189. public function addUserStore(UserStore $userStore): self
  190. {
  191. if (!$this->userStores->contains($userStore)) {
  192. $this->userStores->add($userStore);
  193. $userStore->setUser($this);
  194. }
  195. return $this;
  196. }
  197. public function removeUserStore(UserStore $userStore): self
  198. {
  199. if ($this->userStores->removeElement($userStore)) {
  200. // set the owning side to null (unless already changed)
  201. if ($userStore->getUser() === $this) {
  202. $userStore->setUser(null);
  203. }
  204. }
  205. return $this;
  206. }
  207. public function getStripeCustomerId(): ?string
  208. {
  209. return $this->stripe_customer_id;
  210. }
  211. public function setStripeCustomerId(?string $stripe_customer_id): self
  212. {
  213. $this->stripe_customer_id = $stripe_customer_id;
  214. return $this;
  215. }
  216. public function getLastLogin(): ?\DateTimeImmutable
  217. {
  218. return $this->lastLogin;
  219. }
  220. public function setLastLogin(?\DateTimeImmutable $lastLogin): self
  221. {
  222. $this->lastLogin = $lastLogin;
  223. return $this;
  224. }
  225. /**
  226. * @return Collection<int, UserProductImage>
  227. */
  228. public function getUserProductImages(): Collection
  229. {
  230. return $this->userProductImages;
  231. }
  232. public function addUserProductImage(UserProductImage $userProductImage): static
  233. {
  234. if (!$this->userProductImages->contains($userProductImage)) {
  235. $this->userProductImages->add($userProductImage);
  236. $userProductImage->setUser($this);
  237. }
  238. return $this;
  239. }
  240. public function removeUserProductImage(UserProductImage $userProductImage): static
  241. {
  242. if ($this->userProductImages->removeElement($userProductImage)) {
  243. // set the owning side to null (unless already changed)
  244. if ($userProductImage->getUser() === $this) {
  245. $userProductImage->setUser(null);
  246. }
  247. }
  248. return $this;
  249. }
  250. public function getAPIKey(): ?string
  251. {
  252. return $this->apiKey;
  253. }
  254. #[ORM\PrePersist]
  255. public function setAPIKey(): void
  256. {
  257. $this->apiKey = implode('-', str_split(substr(strtolower(md5(microtime().rand(1000, 9999))), 0, 30), 6));
  258. }
  259. public function getAPIKeyShippo(): ?string
  260. {
  261. return $this->apiKeyShippo;
  262. }
  263. public function setAPIKeyShippo(string $apiKeyShippo): self
  264. {
  265. $this->apiKeyShippo = $apiKeyShippo;
  266. return $this;
  267. }
  268. /**
  269. * @return Collection<int, PurchaseAPOD>
  270. */
  271. public function getPurchaseAPODs(): Collection
  272. {
  273. return $this->purchaseAPODs;
  274. }
  275. }