Review.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model;
  3. class Review extends \Magento\Framework\Model\AbstractModel
  4. {
  5. const EMAIL_REVIEW_IMPORTED = 1;
  6. /**
  7. * @var \Magento\Framework\Stdlib\DateTime
  8. */
  9. private $dateTime;
  10. /**
  11. * Review constructor.
  12. *
  13. * @param \Magento\Framework\Model\Context $context
  14. * @param \Magento\Framework\Registry $registry
  15. * @param \Magento\Framework\Stdlib\DateTime $dateTime
  16. * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
  17. * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
  18. * @param array $data
  19. */
  20. public function __construct(
  21. \Magento\Framework\Model\Context $context,
  22. \Magento\Framework\Registry $registry,
  23. \Magento\Framework\Stdlib\DateTime $dateTime,
  24. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  25. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  26. array $data = []
  27. ) {
  28. $this->dateTime = $dateTime;
  29. parent::__construct(
  30. $context,
  31. $registry,
  32. $resource,
  33. $resourceCollection,
  34. $data
  35. );
  36. }
  37. /**
  38. * Constructor.
  39. *
  40. * @return null
  41. */
  42. public function _construct()
  43. {
  44. parent::_construct();
  45. $this->_init(\Dotdigitalgroup\Email\Model\ResourceModel\Review::class);
  46. }
  47. /**
  48. * Prepare data to be saved to database.
  49. *
  50. * @return $this
  51. */
  52. public function beforeSave()
  53. {
  54. parent::beforeSave();
  55. if ($this->isObjectNew() && !$this->getCreatedAt()) {
  56. $this->setCreatedAt($this->dateTime->formatDate(true));
  57. }
  58. $this->setUpdatedAt($this->dateTime->formatDate(true));
  59. return $this;
  60. }
  61. }