BaseUser.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. class BaseUser extends AbstractedUser
  13. {
  14. protected $createdAt;
  15. protected $updatedAt;
  16. /**
  17. * Set createdAt
  18. *
  19. * @param \DateTime $createdAt
  20. */
  21. public function setCreatedAt(\DateTime $createdAt = null)
  22. {
  23. $this->createdAt = $createdAt;
  24. }
  25. /**
  26. * Get createdAt
  27. *
  28. * @return \DateTime $createdAt
  29. */
  30. public function getCreatedAt()
  31. {
  32. return $this->createdAt;
  33. }
  34. /**
  35. * Set updatedAt
  36. *
  37. * @param \DateTime $updatedAt
  38. */
  39. public function setUpdatedAt(\DateTime $updatedAt = null)
  40. {
  41. $this->updatedAt = $updatedAt;
  42. }
  43. /**
  44. * Get updatedAt
  45. *
  46. * @return \DateTime $updatedAt
  47. */
  48. public function getUpdatedAt()
  49. {
  50. return $this->updatedAt;
  51. }
  52. public function prePersist()
  53. {
  54. $this->createdAt = new \DateTime;
  55. $this->updatedAt = new \DateTime;
  56. }
  57. public function preUpdate()
  58. {
  59. $this->updatedAt = new \DateTime;
  60. }
  61. /**
  62. * @return \DateTime
  63. */
  64. public function getCredentialsExpireAt()
  65. {
  66. return $this->credentialsExpireAt;
  67. }
  68. public function setCredentialsExpireAt(\DateTime $date = null)
  69. {
  70. $this->credentialsExpireAt = $date;
  71. }
  72. public function __toString()
  73. {
  74. return $this->getUsername() ?: '-';
  75. }
  76. }