BaseUser.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /*
  3. * This file is part of the Sonata project.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\UserBundle\Entity;
  11. use FOS\UserBundle\Entity\User as AbstractedUser;
  12. use Sonata\UserBundle\Model\UserInterface;
  13. class BaseUser extends AbstractedUser implements UserInterface
  14. {
  15. protected $createdAt;
  16. protected $updatedAt;
  17. protected $twoStepVerificationCode;
  18. /**
  19. * Set createdAt
  20. *
  21. * @param \DateTime|null $createdAt
  22. * @return void
  23. */
  24. public function setCreatedAt(\DateTime $createdAt = null)
  25. {
  26. $this->createdAt = $createdAt;
  27. }
  28. /**
  29. * Get createdAt
  30. *
  31. * @return \DateTime|null
  32. */
  33. public function getCreatedAt()
  34. {
  35. return $this->createdAt;
  36. }
  37. /**
  38. * Set updatedAt
  39. *
  40. * @param \DateTime|null $updatedAt
  41. * @return void
  42. */
  43. public function setUpdatedAt(\DateTime $updatedAt = null)
  44. {
  45. $this->updatedAt = $updatedAt;
  46. }
  47. /**
  48. * Get updatedAt
  49. *
  50. * @return \DateTime|null
  51. */
  52. public function getUpdatedAt()
  53. {
  54. return $this->updatedAt;
  55. }
  56. /**
  57. * Get ExpiresAt
  58. *
  59. * @return \DateTime|null
  60. */
  61. public function getExpiresAt()
  62. {
  63. return $this->expiresAt;
  64. }
  65. /**
  66. * @return void
  67. */
  68. public function prePersist()
  69. {
  70. $this->createdAt = new \DateTime;
  71. $this->updatedAt = new \DateTime;
  72. }
  73. /**
  74. * @return void
  75. */
  76. public function preUpdate()
  77. {
  78. $this->updatedAt = new \DateTime;
  79. }
  80. /**
  81. * @return \DateTime
  82. */
  83. public function getCredentialsExpireAt()
  84. {
  85. return $this->credentialsExpireAt;
  86. }
  87. /**
  88. * @param \DateTime|null $date
  89. * @return void
  90. */
  91. public function setCredentialsExpireAt(\DateTime $date = null)
  92. {
  93. $this->credentialsExpireAt = $date;
  94. }
  95. /**
  96. * @return string
  97. */
  98. public function __toString()
  99. {
  100. return $this->getUsername() ?: '-';
  101. }
  102. /**
  103. * Set related groups
  104. *
  105. * @param aarrat $groups
  106. */
  107. public function setGroups($groups)
  108. {
  109. foreach ($groups as $group){
  110. $this->addGroup($group);
  111. }
  112. }
  113. /**
  114. * @param string $twoStepVerificationCode
  115. * @return void
  116. */
  117. public function setTwoStepVerificationCode($twoStepVerificationCode)
  118. {
  119. $this->twoStepVerificationCode = $twoStepVerificationCode;
  120. }
  121. /**
  122. * @return string
  123. */
  124. public function getTwoStepVerificationCode()
  125. {
  126. return $this->twoStepVerificationCode;
  127. }
  128. }