Guest User

Untitled

a guest
Jun 18th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Application\MyBundle\Entity;
  4.  
  5. use Doctrine\Common\Collections\ArrayCollection;
  6.  
  7. /**
  8. * @orm:Entity(repositoryClass="Application\MyBundle\Entity\UserRepository")
  9. * @orm:Table(name="user",
  10. * uniqueConstraints={
  11. * @orm:UniqueConstraint(name="username_idx", columns={"username"}),
  12. * @orm:UniqueConstraint(name="email_idx", columns={"email"})
  13. * }
  14. * )
  15. * @orm:HasLifecycleCallbacks
  16. */
  17. class User
  18. {
  19. /**
  20. * @orm:Column(name="id", type="integer")
  21. * @orm:Id
  22. * @orm:GeneratedValue(strategy="AUTO")
  23. * @var integer
  24. */
  25. protected $id;
  26.  
  27. /**
  28. * @orm:Column(name="username", type="string", length="32")
  29. * @validation:Min(3)
  30. * @validation:Max(32)
  31. * @validation:NotBlank
  32. * @var string
  33. */
  34. protected $username;
  35.  
  36. /**
  37. * @orm:Column(name="email", type="string", length="256")
  38. * @validation:Email
  39. * @validation:NotBlank
  40. * @var string
  41. */
  42. protected $email;
  43.  
  44. /**
  45. * @orm:Column(name="password", type="string", length="32")
  46. * @validation:NotBlank
  47. * @var string
  48. */
  49. protected $password;
  50.  
  51. /**
  52. * @orm:Column(name="activation_key", type="string", length="32")
  53. * @var \DateTime
  54. */
  55. protected $activationKey;
  56.  
  57. /**
  58. * @orm:Column(name="activation", type="datetime", nullable="true")
  59. * @var \DateTime
  60. */
  61. protected $activation;
  62.  
  63. /**
  64. * @orm:Column(name="last_login", type="datetime", nullable="true")
  65. * @var \DateTime
  66. */
  67. protected $lastLogin;
  68.  
  69. /**
  70. * @orm:Column(type="datetime")
  71. * @validation:NotBlank
  72. * @var \DateTime
  73. */
  74. protected $created;
  75.  
  76. /**
  77. * @orm:Column(type="datetime")
  78. * @validation:NotBlank
  79. * @var \DateTime
  80. */
  81. protected $updated;
  82.  
  83. /**
  84. * Constructor.
  85. */
  86. public function __construct()
  87. {
  88. $this->created = $this->updated = new \DateTime('now');
  89. }
  90.  
  91. /**
  92. * @return integer
  93. */
  94. public function getId()
  95. {
  96. return $this->id;
  97. }
  98.  
  99. /**
  100. * @return string
  101. */
  102. public function __toString()
  103. {
  104. return $this->getUsername();
  105. }
  106.  
  107. /**
  108. * @return string
  109. */
  110. public function getUsername()
  111. {
  112. return $this->username;
  113. }
  114.  
  115. /**
  116. * @param string $username
  117. */
  118. public function setUsername($username)
  119. {
  120. $this->username = $username;
  121. }
  122.  
  123. /**
  124. * @return string
  125. */
  126. public function getEmail()
  127. {
  128. return $this->email;
  129. }
  130.  
  131. /**
  132. * @param string $email
  133. */
  134. public function setEmail($email)
  135. {
  136. $this->email = $email;
  137. }
  138.  
  139. /**
  140. * @return string
  141. */
  142. public function getPassword()
  143. {
  144. return $this->password;
  145. }
  146.  
  147. /**
  148. * @param string $password
  149. */
  150. public function setPassword($password)
  151. {
  152. $this->password = md5($password);
  153. }
  154.  
  155. /**
  156. * @param string $password
  157. * @return boolean
  158. */
  159. public function checkPassword($password)
  160. {
  161. return md5($password) == $this->password;
  162. }
  163.  
  164. /**
  165. * @return string
  166. */
  167. public function getActivationKey()
  168. {
  169. return $this->activationKey;
  170. }
  171.  
  172. /**
  173. * @param string $activationKey
  174. */
  175. public function setActivationKey($activationKey)
  176. {
  177. $this->activationKey = $activationKey;
  178. }
  179.  
  180. /**
  181. * @return string
  182. */
  183. public function generateActivationKey()
  184. {
  185. return md5(sprintf('%s_%d_%s_%f',
  186. $this->getUsername(),
  187. rand(0, 99999),
  188. $this->getEmail(),
  189. microtime(true)
  190. ));
  191. }
  192.  
  193. /**
  194. * @return \DateTime
  195. */
  196. public function getActivation()
  197. {
  198. return $this->activation;
  199. }
  200.  
  201. /**
  202. * @param \DateTime $activation
  203. */
  204. public function setActivation(\DateTime $activation)
  205. {
  206. $this->activation = $activation;
  207. }
  208.  
  209. /**
  210. * @return \DateTime
  211. */
  212. public function isActivated()
  213. {
  214. return (boolean) $this->activation;
  215. }
  216.  
  217. /**
  218. * @return \DateTime
  219. */
  220. public function getLastLogin()
  221. {
  222. return $this->lastLogin;
  223. }
  224.  
  225. /**
  226. * @param \DateTime $lastLogin
  227. */
  228. public function setLastLogin(\DateTime $lastLogin)
  229. {
  230. $this->lastLogin = $lastLogin;
  231. }
  232.  
  233. /**
  234. * @return \DateTime
  235. */
  236. public function getLast_login()
  237. {
  238. return $this->lastLogin;
  239. }
  240.  
  241. /**
  242. * @param \DateTime $last_login
  243. */
  244. public function setLast_login(\DateTime $last_login)
  245. {
  246. $this->lastLogin = $last_login;
  247. }
  248.  
  249. /**
  250. * @return \DateTime
  251. */
  252. public function getCreated()
  253. {
  254. return $this->created;
  255. }
  256.  
  257. /**
  258. * @param \DateTime $created
  259. */
  260. public function setCreated(\DateTime $created)
  261. {
  262. $this->created = $created;
  263. }
  264.  
  265. /**
  266. * @return \DateTime
  267. */
  268. public function getUpdated()
  269. {
  270. return $this->updated;
  271. }
  272.  
  273. /**
  274. * @param \DateTime $updated
  275. */
  276. public function setUpdated(\DateTime $updated)
  277. {
  278. $this->updated = $updated;
  279. }
  280.  
  281. /**
  282. * @orm:PreUpdate
  283. */
  284. public function update()
  285. {
  286. $this->updated = new \DateTime('now');
  287. }
  288. }
Add Comment
Please, Sign In to add comment