src/Entity/User.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Application\Store;
  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\UserInterface;
  8. /**
  9. * @ORM\Entity
  10. * @ORM\Table(name="users")
  11. */
  12. class User implements UserInterface
  13. {
  14. /**
  15. * @ORM\Id
  16. * @ORM\Column(type="integer")
  17. * @ORM\GeneratedValue(strategy="AUTO")
  18. */
  19. protected $id;
  20. /**
  21. * @ORM\ManyToMany(targetEntity="App\Entity\Dealer", inversedBy="users")
  22. * @ORM\JoinTable(name="users_dealers")
  23. */
  24. private $dealers;
  25. /**
  26. * @ORM\ManyToMany(targetEntity="App\Entity\Application\Store", inversedBy="users")
  27. * @ORM\JoinTable(name="users_stores")
  28. */
  29. private $stores;
  30. /**
  31. * @ORM\Column(type="string", length=180, unique=true)
  32. */
  33. private $email;
  34. /**
  35. * @var string The hashed password
  36. * @ORM\Column(type="string")
  37. */
  38. private $password;
  39. /**
  40. * @ORM\Column(type="datetime", nullable=true)
  41. */
  42. private $lastLogin;
  43. /**
  44. * @ORM\Column(type="json")
  45. */
  46. private $roles = [];
  47. /**
  48. * @ORM\Column(type="string", length=100, nullable=true)
  49. */
  50. protected $firstName;
  51. /**
  52. * @ORM\Column(type="string", length=100, nullable=true)
  53. */
  54. protected $lastName;
  55. /**
  56. * @var string Tokeny
  57. * @ORM\Column(type="string", nullable=true)
  58. */
  59. private $confirmToken;
  60. /**
  61. * @ORM\Column(type="boolean")
  62. */
  63. private $isVerified = false;
  64. public function __construct()
  65. {
  66. $this->dealers = new ArrayCollection();
  67. $this->stores = new ArrayCollection();
  68. }
  69. /**
  70. * Get Id
  71. *
  72. * @return mixed
  73. */
  74. public function getId()
  75. {
  76. return $this->id;
  77. }
  78. /**
  79. * Set Id
  80. *
  81. * @param mixed $id
  82. */
  83. public function setId( $id )
  84. {
  85. $this->id = $id;
  86. }
  87. public function getFullName( )
  88. {
  89. return sprintf('%s %s',$this->getLastName(),$this->getFirstName());
  90. }
  91. /**
  92. * @return Collection|Dealer[]
  93. */
  94. public function getDealers(): Collection
  95. {
  96. return $this->dealers;
  97. }
  98. public function addDealer(Dealer $dealer): self
  99. {
  100. if (!$this->dealers->contains($dealer)) {
  101. $this->dealers[] = $dealer;
  102. $dealer->addUser($this);
  103. }
  104. return $this;
  105. }
  106. public function removeDealer(Dealer $dealer): self
  107. {
  108. if ($this->dealers->contains($dealer)) {
  109. $this->dealers->removeElement($dealer);
  110. $dealer->removeUser($this);
  111. }
  112. return $this;
  113. }
  114. /**
  115. * @return Collection|Store[]
  116. */
  117. public function getStores(): Collection
  118. {
  119. return $this->stores;
  120. }
  121. public function addStore(Store $store): self
  122. {
  123. if (!$this->stores->contains($store)) {
  124. $this->stores[] = $store;
  125. $store->addUser($this);
  126. }
  127. return $this;
  128. }
  129. public function removeStore(Store $store): self
  130. {
  131. if ($this->stores->contains($store)) {
  132. $this->stores->removeElement($store);
  133. $store->removeUser($this);
  134. }
  135. return $this;
  136. }
  137. /**
  138. * Get Email
  139. *
  140. * @return mixed
  141. */
  142. public function getEmail()
  143. {
  144. return $this->email;
  145. }
  146. /**
  147. * Set Email
  148. *
  149. * @param mixed $email
  150. */
  151. public function setEmail( $email )
  152. {
  153. $this->email = $email;
  154. }
  155. public function getFirstName(): ?string
  156. {
  157. return $this->firstName;
  158. }
  159. public function setFirstName(?string $firstName): self
  160. {
  161. $this->firstName = $firstName;
  162. return $this;
  163. }
  164. public function getLastName(): ?string
  165. {
  166. return $this->lastName;
  167. }
  168. public function setLastName(?string $lastName): self
  169. {
  170. $this->lastName = $lastName;
  171. return $this;
  172. }
  173. /**
  174. * addRoles -
  175. *
  176. * @param $role
  177. */
  178. public function addRoles($role)
  179. {
  180. $roles = $this->roles;
  181. $roles[] = $role;
  182. $this->setRoles(array_unique($roles));
  183. }
  184. public function getRoles(): array
  185. {
  186. $roles = $this->roles;
  187. // guarantee every user at least has ROLE_USER
  188. $roles[] = 'ROLE_USER';
  189. return array_unique($roles);
  190. }
  191. public function setRoles(array $roles): self
  192. {
  193. $this->roles = $roles;
  194. return $this;
  195. }
  196. /**
  197. * @see UserInterface
  198. */
  199. public function getPassword(): string
  200. {
  201. return (string) $this->password;
  202. }
  203. public function setPassword(string $password): self
  204. {
  205. $this->password = $password;
  206. return $this;
  207. }
  208. /**
  209. * @see UserInterface
  210. */
  211. public function getSalt()
  212. {
  213. // not needed when using the "bcrypt" algorithm in security.yaml
  214. }
  215. /**
  216. * @see UserInterface
  217. */
  218. public function eraseCredentials()
  219. {
  220. // If you store any temporary, sensitive data on the user, clear it here
  221. // $this->plainPassword = null;
  222. }
  223. /**
  224. * Returns the username used to authenticate the user.
  225. *
  226. * @return string The username
  227. */
  228. public function getUsername()
  229. {
  230. return $this->email;
  231. }
  232. /**
  233. * Get LastLogin
  234. *
  235. * @return mixed
  236. */
  237. public function getLastLogin()
  238. {
  239. return $this->lastLogin;
  240. }
  241. /**
  242. * Set LastLogin
  243. *
  244. * @param mixed $lastLogin
  245. */
  246. public function setLastLogin( $lastLogin )
  247. {
  248. $this->lastLogin = $lastLogin;
  249. }
  250. public function isVerified(): bool
  251. {
  252. return $this->isVerified;
  253. }
  254. public function setIsVerified(bool $isVerified): self
  255. {
  256. $this->isVerified = $isVerified;
  257. return $this;
  258. }
  259. /**
  260. * Get ConfirmToken
  261. *
  262. * @return string
  263. */
  264. public function getConfirmToken()
  265. {
  266. return $this->confirmToken;
  267. }
  268. /**
  269. * Set ConfirmToken
  270. *
  271. * @param string $confirmToken
  272. */
  273. public function setConfirmToken( $confirmToken )
  274. {
  275. $this->confirmToken = $confirmToken;
  276. }
  277. }