TimestampableEntity.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace AppBundle\Entity\Traits;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Dunglas\ApiBundle\Annotation\Iri;
  5. use Gedmo\Mapping\Annotation as Gedmo;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. /**
  9. * @Iri("http://schema.org/Generic")
  10. */
  11. trait TimestampableEntity
  12. {
  13. /**
  14. * @var \DateTime
  15. *
  16. * @Gedmo\Timestampable(on="create")
  17. */
  18. #[ORM\Column(type: 'datetime', nullable: true)]
  19. #[Assert\Date]
  20. #[Groups(['timestampable', 'template_list', 'notification_list', 'education_student_wish_list', 'email_detail', 'access_files_person', 'messagesend_list', 'online_registration_access_family_accesswishes'])]
  21. private $createDate;
  22. /**
  23. * @var \DateTime
  24. *
  25. * @Gedmo\Timestampable(on="update")
  26. */
  27. #[ORM\Column(type: 'datetime', nullable: true)]
  28. #[Assert\Date]
  29. #[Groups(['timestampable', 'education_student_next_year', 'education_student_wish_list'])]
  30. private $updateDate;
  31. /**
  32. * Sets createDate.
  33. *
  34. * @param \DateTime $createDate
  35. *
  36. * @return $this
  37. */
  38. public function setCreateDate(\DateTime $createDate = null)
  39. {
  40. $this->createDate = $createDate;
  41. return $this;
  42. }
  43. /**
  44. * Gets createDate.
  45. *
  46. * @return \DateTime
  47. */
  48. public function getCreateDate()
  49. {
  50. return $this->createDate;
  51. }
  52. /**
  53. * Sets updateDate.
  54. *
  55. * @param \DateTime $updateDate
  56. *
  57. * @return $this
  58. */
  59. public function setUpdateDate(\DateTime $updateDate = null)
  60. {
  61. $this->updateDate = $updateDate;
  62. return $this;
  63. }
  64. /**
  65. * Gets updateDate.
  66. *
  67. * @return \DateTime
  68. */
  69. public function getUpdateDate()
  70. {
  71. return $this->updateDate ? $this->updateDate->format('Y-m-d') : $this->updateDate;
  72. }
  73. }