Guest User

Untitled

a guest
Nov 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Hybrid\UserBundle\Entity;
  4.  
  5. use Symfony\Component\Security\Core\User\UserInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Hybrid\UserBundle\Entity\Role;
  8.  
  9. /**
  10. * User entity. Implements UserInterface.
  11. *
  12. * ... Personal details removed ...
  13. */
  14. class User implements UserInterface
  15. {
  16. /**
  17. * @var integer $id
  18. */
  19. private $id;
  20.  
  21. /**
  22. * @var ArrayCollection
  23. */
  24. private $roles;
  25.  
  26. /**
  27. * @var string $email
  28. */
  29. private $email;
  30.  
  31. /**
  32. * @var string $password
  33. */
  34. private $password;
  35.  
  36. /*
  37. * @var string $password
  38. */
  39. private $plainpw;
  40.  
  41. /**
  42. * @var string $salt
  43. */
  44. private $salt;
  45.  
  46. /**
  47. * @var date $dob
  48. */
  49. private $dob;
  50.  
  51. /**
  52. * @var string $firstName
  53. */
  54. private $firstName;
  55.  
  56. /**
  57. * @var string $lastName
  58. */
  59. private $lastName;
  60.  
  61. /**
  62. * @var string $phoneNumber
  63. */
  64. private $phoneNumber;
  65.  
  66. /**
  67. * @var datetime $createdAt
  68. */
  69. private $createdAt;
  70.  
  71. /**
  72. * @var datetime $lastLogin
  73. */
  74. private $lastLogin;
  75.  
  76. public function __construct()
  77. {
  78. $this->setCreatedAt(new \DateTime());
  79. $this->roles = new ArrayCollection();
  80. }
  81.  
  82. /**
  83. * Get the user ID
  84. *
  85. * @return integer $id
  86. */
  87. public function getId()
  88. {
  89. return $this->id;
  90. }
  91.  
  92. /**
  93. * Add new role for user
  94. *
  95. * @param Role $roles
  96. */
  97. public function addRole(Role $role)
  98. {
  99. $this->roles->add($role);
  100. }
  101.  
  102. /**
  103. * Get user roles
  104. *
  105. * The $collection-parameter is used to detect if plain array or collection
  106. * is returned. Symfony2 Security system needs an array, so when false is
  107. * passed (the default), plain array is returned.
  108. *
  109. * @param boolean $collection
  110. * @return array $roles
  111. */
  112. public function getRoles($collection = false)
  113. {
  114. if(!$collection === false) {
  115. return $this->roles;
  116. }
  117.  
  118. return $this->roles->toArray();
  119. }
  120.  
  121. /**
  122. * Set the user email address
  123. *
  124. * @param string $email
  125. */
  126. public function setEmail($email)
  127. {
  128. $this->email = (string) $email;
  129. }
  130.  
  131. /**
  132. * Get the user email address
  133. *
  134. * @return string $email
  135. */
  136. public function getEmail()
  137. {
  138. return $this->email;
  139. }
  140.  
  141. /**
  142. * Set the user password
  143. *
  144. * @param string $password
  145. */
  146. public function setPassword($password)
  147. {
  148. $this->password = (string) $password;
  149. }
  150.  
  151. /**
  152. * Get the user password
  153. *
  154. * @return string $password
  155. */
  156. public function getPassword()
  157. {
  158. return $this->password;
  159. }
  160.  
  161. /**
  162. * Set plain password
  163. *
  164. * Plain password is used when changing password and when creating new user.
  165. * The plain password is sent to the user by email provided.
  166. *
  167. * @param string $plain
  168. */
  169. public function setPlainpw($plain)
  170. {
  171. $this->plainpw = $plain;
  172. }
  173.  
  174. /**
  175. * Get plain password
  176. *
  177. * @return string
  178. */
  179. public function getPlainpw()
  180. {
  181. return $this->plainpw;
  182. }
  183.  
  184. /**
  185. * Set salt
  186. *
  187. * @param string $salt
  188. */
  189. public function setSalt($salt)
  190. {
  191. $this->salt = $salt;
  192. }
  193.  
  194. /**
  195. * Get salt
  196. *
  197. * @return string $salt
  198. */
  199. public function getSalt()
  200. {
  201. return $this->salt;
  202. }
  203.  
  204. /**
  205. * Set dob (date of birth)
  206. *
  207. * @param date $dob
  208. */
  209. public function setDob($dob)
  210. {
  211. $this->dob = new \DateTime($dob);
  212. }
  213.  
  214. /**
  215. * Get dob
  216. *
  217. * @return date $dob
  218. */
  219. public function getDob()
  220. {
  221. return $this->dob;
  222. }
  223.  
  224. /**
  225. * Set first name of the user
  226. *
  227. * @param string $firstName
  228. */
  229. public function setFirstName($firstName)
  230. {
  231. $this->firstName = (string) $firstName;
  232. }
  233.  
  234. /**
  235. * Get first name of the user
  236. *
  237. * @return string $firstName
  238. */
  239. public function getFirstName()
  240. {
  241. return $this->firstName;
  242. }
  243.  
  244. /**
  245. * Set last name of the user
  246. *
  247. * @param string $lastName
  248. */
  249. public function setLastName($lastName)
  250. {
  251. $this->lastName = (string) $lastName;
  252. }
  253.  
  254. /**
  255. * Get last name of the user
  256. *
  257. * @return string $lastName
  258. */
  259. public function getLastName()
  260. {
  261. return $this->lastName;
  262. }
  263.  
  264. /**
  265. * Set phone number
  266. *
  267. * @param string $phoneNumber
  268. */
  269. public function setPhoneNumber($phoneNumber)
  270. {
  271. $this->phoneNumber = (string) $phoneNumber;
  272. }
  273.  
  274. /**
  275. * Get phone number
  276. *
  277. * @return string $phoneNumber
  278. */
  279. public function getPhoneNumber()
  280. {
  281. return $this->phoneNumber;
  282. }
  283.  
  284. /**
  285. * Set createdAt
  286. *
  287. * @param datetime $createdAt
  288. */
  289. public function setCreatedAt($createdAt)
  290. {
  291. $this->createdAt = $createdAt;
  292. }
  293.  
  294. /**
  295. * Get createdAt
  296. *
  297. * @return datetime $createdAt
  298. */
  299. public function getCreatedAt()
  300. {
  301. return $this->createdAt;
  302. }
  303.  
  304. /**
  305. * Set lastLogin
  306. *
  307. * @param datetime $lastLogin
  308. */
  309. public function setLastLogin($lastLogin)
  310. {
  311. $this->lastLogin = $lastLogin;
  312. }
  313.  
  314. /**
  315. * Get lastLogin
  316. *
  317. * @return datetime $lastLogin
  318. */
  319. public function getLastLogin()
  320. {
  321. return $this->lastLogin;
  322. }
  323.  
  324. /**
  325. * Implementing UserInterface
  326. */
  327.  
  328. public function eraseCredentials()
  329. {
  330. $this->setPassword(null);
  331. $this->setPlainpw(null);
  332. }
  333.  
  334. public function equals(UserInterface $user)
  335. {
  336. return (bool) md5($this->getUsername()) === md5($user->getUsername());
  337. }
  338.  
  339. public function getUsername()
  340. {
  341. return $this->getEmail();
  342. }
  343. }
Add Comment
Please, Sign In to add comment