Campaign.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\ResourceModel;
  3. use Dotdigitalgroup\Email\Setup\Schema;
  4. class Campaign extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  5. {
  6. /**
  7. * @var \Magento\Framework\Stdlib\DateTime\DateTime
  8. */
  9. public $datetime;
  10. /**
  11. * Initialize resource.
  12. * @return null
  13. */
  14. public function _construct()
  15. {
  16. $this->_init(Schema::EMAIL_CAMPAIGN_TABLE, 'id');
  17. }
  18. /**
  19. * Campaign constructor.
  20. *
  21. * @param \Magento\Framework\Model\ResourceModel\Db\Context $context
  22. * @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
  23. * @param null $connectionName
  24. */
  25. public function __construct(
  26. \Magento\Framework\Model\ResourceModel\Db\Context $context,
  27. \Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
  28. $connectionName = null
  29. ) {
  30. $this->datetime = $dateTime;
  31. parent::__construct(
  32. $context,
  33. $connectionName
  34. );
  35. }
  36. /**
  37. * Set error message
  38. *
  39. * @param array $ids
  40. * @param string $message
  41. *
  42. * @return null
  43. */
  44. public function setMessage($ids, $message)
  45. {
  46. $conn = $this->getConnection();
  47. $conn->update(
  48. $this->getMainTable(),
  49. [
  50. 'message' => $message,
  51. 'send_status' => \Dotdigitalgroup\Email\Model\Campaign::FAILED,
  52. 'sent_at' => $this->datetime->gmtDate()
  53. ],
  54. ["id in (?)" => $ids]
  55. );
  56. }
  57. /**
  58. * @param int $sendId
  59. * @param string $message
  60. *
  61. * @return null
  62. */
  63. public function setMessageWithSendId($sendId, $message)
  64. {
  65. $conn = $this->getConnection();
  66. $conn->update(
  67. $this->getMainTable(),
  68. [
  69. 'message' => $message,
  70. 'send_status' => \Dotdigitalgroup\Email\Model\Campaign::FAILED,
  71. 'sent_at' => $this->datetime->gmtDate()
  72. ],
  73. ['send_id = ?' => $sendId]
  74. );
  75. }
  76. /**
  77. * Set sent.
  78. *
  79. * @param int $sendId
  80. *
  81. * @return null
  82. */
  83. public function setSent($sendId)
  84. {
  85. $bind = [
  86. 'send_status' => \Dotdigitalgroup\Email\Model\Campaign::SENT,
  87. 'sent_at' => $this->datetime->gmtDate()
  88. ];
  89. $conn = $this->getConnection();
  90. $conn->update(
  91. $this->getMainTable(),
  92. $bind,
  93. ['send_id = ?' => $sendId]
  94. );
  95. }
  96. /**
  97. * Set processing
  98. *
  99. * @param array $ids
  100. * @param int $sendId
  101. *
  102. * @return null
  103. */
  104. public function setProcessing($ids, $sendId)
  105. {
  106. $bind = [
  107. 'send_status' => \Dotdigitalgroup\Email\Model\Campaign::PROCESSING,
  108. 'send_id' => $sendId
  109. ];
  110. $conn = $this->getConnection();
  111. $conn->update(
  112. $this->getMainTable(),
  113. $bind,
  114. ["id in (?)" => $ids]
  115. );
  116. }
  117. /**
  118. * Save item
  119. *
  120. * @param \Dotdigitalgroup\Email\Model\Campaign $item
  121. * @return \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  122. */
  123. public function saveItem($item)
  124. {
  125. return parent::save($item);
  126. }
  127. }