BaseUser.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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\Document;
  11. use FOS\UserBundle\Document\User as AbstractedUser;
  12. use Sonata\UserBundle\Model\UserInterface;
  13. /**
  14. * Represents a Base User Document
  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 credentials expiration date
  68. *
  69. * @return \DateTime
  70. */
  71. public function getCredentialsExpireAt()
  72. {
  73. return $this->credentialsExpireAt;
  74. }
  75. /**
  76. * Sets the credentials expiration date
  77. *
  78. * @param \DateTime|null $date
  79. */
  80. public function setCredentialsExpireAt(\DateTime $date = null)
  81. {
  82. $this->credentialsExpireAt = $date;
  83. }
  84. /**
  85. * Hook on pre-persist operations
  86. */
  87. public function prePersist()
  88. {
  89. $this->createdAt = new \DateTime;
  90. $this->updatedAt = new \DateTime;
  91. }
  92. /**
  93. * Hook on pre-update operations
  94. */
  95. public function preUpdate()
  96. {
  97. $this->updatedAt = new \DateTime;
  98. }
  99. /**
  100. * Returns a string representation
  101. *
  102. * @return string
  103. */
  104. public function __toString()
  105. {
  106. return $this->getUsername() ?: '-';
  107. }
  108. /**
  109. * Sets the user groups
  110. *
  111. * @param array $groups
  112. */
  113. public function setGroups($groups)
  114. {
  115. foreach ($groups as $group){
  116. $this->addGroup($group);
  117. }
  118. }
  119. /**
  120. * Sets the two-step verification code
  121. *
  122. * @param string $twoStepVerificationCode
  123. */
  124. public function setTwoStepVerificationCode($twoStepVerificationCode)
  125. {
  126. $this->twoStepVerificationCode = $twoStepVerificationCode;
  127. }
  128. /**
  129. * Returns the two-step verification code
  130. *
  131. * @return string
  132. */
  133. public function getTwoStepVerificationCode()
  134. {
  135. return $this->twoStepVerificationCode;
  136. }
  137. }