BaseUser.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. /**
  14. * Represents a Base User Entity
  15. */
  16. class BaseUser extends AbstractedUser implements UserInterface
  17. {
  18. /**
  19. * @var \DateTime
  20. */
  21. protected $createdAt;
  22. /**
  23. * @var \DateTime
  24. */
  25. protected $updatedAt;
  26. /**
  27. * @var string
  28. */
  29. protected $twoStepVerificationCode;
  30. /**
  31. * Sets the creation date
  32. *
  33. * @param \DateTime|null $createdAt
  34. */
  35. public function setCreatedAt(\DateTime $createdAt = null)
  36. {
  37. $this->createdAt = $createdAt;
  38. }
  39. /**
  40. * Returns the creation date
  41. *
  42. * @return \DateTime|null
  43. */
  44. public function getCreatedAt()
  45. {
  46. return $this->createdAt;
  47. }
  48. /**
  49. * Sets the last update date
  50. *
  51. * @param \DateTime|null $updatedAt
  52. */
  53. public function setUpdatedAt(\DateTime $updatedAt = null)
  54. {
  55. $this->updatedAt = $updatedAt;
  56. }
  57. /**
  58. * Returns the last update date
  59. *
  60. * @return \DateTime|null
  61. */
  62. public function getUpdatedAt()
  63. {
  64. return $this->updatedAt;
  65. }
  66. /**
  67. * Returns the expiration date
  68. *
  69. * @return \DateTime|null
  70. */
  71. public function getExpiresAt()
  72. {
  73. return $this->expiresAt;
  74. }
  75. /**
  76. * Hook on pre-persist operations
  77. */
  78. public function prePersist()
  79. {
  80. $this->createdAt = new \DateTime;
  81. $this->updatedAt = new \DateTime;
  82. }
  83. /**
  84. * Hook on pre-update operations
  85. */
  86. public function preUpdate()
  87. {
  88. $this->updatedAt = new \DateTime;
  89. }
  90. /**
  91. * Returns the credentials expiration date
  92. *
  93. * @return \DateTime
  94. */
  95. public function getCredentialsExpireAt()
  96. {
  97. return $this->credentialsExpireAt;
  98. }
  99. /**
  100. * Sets the credentials expiration date
  101. *
  102. * @param \DateTime|null $date
  103. */
  104. public function setCredentialsExpireAt(\DateTime $date = null)
  105. {
  106. $this->credentialsExpireAt = $date;
  107. }
  108. /**
  109. * Returns a string representation
  110. *
  111. * @return string
  112. */
  113. public function __toString()
  114. {
  115. return $this->getUsername() ?: '-';
  116. }
  117. /**
  118. * Sets the user groups
  119. *
  120. * @param array $groups
  121. */
  122. public function setGroups($groups)
  123. {
  124. foreach ($groups as $group){
  125. $this->addGroup($group);
  126. }
  127. }
  128. /**
  129. * Sets the two-step verification code
  130. *
  131. * @param string $twoStepVerificationCode
  132. */
  133. public function setTwoStepVerificationCode($twoStepVerificationCode)
  134. {
  135. $this->twoStepVerificationCode = $twoStepVerificationCode;
  136. }
  137. /**
  138. * Returns the two-step verification code
  139. *
  140. * @return string
  141. */
  142. public function getTwoStepVerificationCode()
  143. {
  144. return $this->twoStepVerificationCode;
  145. }
  146. }