Contact.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model;
  3. class Contact extends \Magento\Framework\Model\AbstractModel
  4. {
  5. const EMAIL_CONTACT_IMPORTED = 1;
  6. const EMAIL_CONTACT_NOT_IMPORTED = null;
  7. const EMAIL_SUBSCRIBER_NOT_IMPORTED = null;
  8. /**
  9. * Constructor.
  10. *
  11. * @return null
  12. */
  13. public function _construct()
  14. {
  15. $this->_init(\Dotdigitalgroup\Email\Model\ResourceModel\Contact::class);
  16. }
  17. /**
  18. * Load contact by customer id.
  19. *
  20. * @param int $customerId
  21. *
  22. * @return $this
  23. */
  24. public function loadByCustomerId($customerId)
  25. {
  26. $contact = $this->getCollection()
  27. ->loadByCustomerId($customerId);
  28. if ($contact) {
  29. return $contact;
  30. }
  31. return $this;
  32. }
  33. /**
  34. * Get all customer contacts not imported for a website.
  35. *
  36. * @param int $websiteId
  37. * @param int $pageSize
  38. *
  39. * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
  40. */
  41. public function getContactsToImportForWebsite($websiteId, $pageSize = 100)
  42. {
  43. return $this->getCollection()
  44. ->getContactsToImportForWebsite($websiteId, $pageSize);
  45. }
  46. /**
  47. * Get missing contacts.
  48. *
  49. * @param int $websiteId
  50. * @param int $pageSize
  51. *
  52. * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
  53. */
  54. public function getMissingContacts($websiteId, $pageSize = 100)
  55. {
  56. return $this->getCollection()
  57. ->getMissingContacts($websiteId, $pageSize);
  58. }
  59. /**
  60. * Load Contact by Email.
  61. *
  62. * @param string $email
  63. * @param int $websiteId
  64. *
  65. * @return $this
  66. */
  67. public function loadByCustomerEmail($email, $websiteId)
  68. {
  69. $customer = $this->getCollection()
  70. ->loadByCustomerEmail($email, $websiteId);
  71. if ($customer) {
  72. return $customer;
  73. } else {
  74. return $this->setEmail($email)
  75. ->setWebsiteId($websiteId);
  76. }
  77. }
  78. /**
  79. * Contact subscribers to import for website.
  80. *
  81. * @param \Magento\Store\Model\Website $website
  82. * @param int $limit
  83. * @param bool $isCustomerCheck
  84. *
  85. * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
  86. */
  87. public function getSubscribersToImport(
  88. \Magento\Store\Model\Website $website,
  89. $limit = 1000,
  90. $isCustomerCheck = true
  91. ) {
  92. return $this->getCollection()
  93. ->getSubscribersToImport(
  94. $website,
  95. $limit,
  96. $isCustomerCheck
  97. );
  98. }
  99. /**
  100. * Contact subscribers to import for website.
  101. *
  102. * @param array $emails
  103. *
  104. * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
  105. */
  106. public function getSubscribersToImportFromEmails($emails)
  107. {
  108. return $this->getCollection()
  109. ->getSubscribersToImportFromEmails($emails);
  110. }
  111. /**
  112. * Get all not imported guests for a website.
  113. *
  114. * @param \Magento\Store\Model\Website $website
  115. * @param boolean $onlySubscriber
  116. *
  117. * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
  118. */
  119. public function getGuests($website, $onlySubscriber = false)
  120. {
  121. return $this->getCollection()
  122. ->getGuests($website->getId(), $onlySubscriber);
  123. }
  124. /**
  125. * Number contacts marked as imported.
  126. *
  127. * @return int
  128. */
  129. public function getNumberOfImportedContacs()
  130. {
  131. return $this->getCollection()
  132. ->getNumberOfImportedContacts();
  133. }
  134. /**
  135. * Get the number of customers for a website.
  136. *
  137. * @param int $websiteId
  138. *
  139. * @return int
  140. */
  141. public function getNumberCustomerContacts($websiteId = 0)
  142. {
  143. return $this->getCollection()
  144. ->getNumberCustomerContacts($websiteId);
  145. }
  146. /**
  147. * Get number of suppressed contacts as customer.
  148. *
  149. * @param int $websiteId
  150. *
  151. * @return int
  152. */
  153. public function getNumberCustomerSuppressed($websiteId = 0)
  154. {
  155. return $this->getCollection()
  156. ->getNumberCustomerSuppressed($websiteId);
  157. }
  158. /**
  159. * Get number of synced customers.
  160. *
  161. * @param int $websiteId
  162. *
  163. * @return int
  164. */
  165. public function getNumberCustomerSynced($websiteId = 0)
  166. {
  167. return $this->getCollection()
  168. ->getNumberCustomerSynced($websiteId);
  169. }
  170. /**
  171. * Get number of subscribers synced.
  172. *
  173. * @param int $websiteId
  174. *
  175. * @return int
  176. */
  177. public function getNumberSubscribersSynced($websiteId = 0)
  178. {
  179. return $this->getCollection()
  180. ->getNumberSubscribersSynced($websiteId);
  181. }
  182. /**
  183. * Get number of subscribers.
  184. *
  185. * @param int $websiteId
  186. *
  187. * @return int
  188. */
  189. public function getNumberSubscribers($websiteId = 0)
  190. {
  191. return $this->getCollection()
  192. ->getNumberSubscribers($websiteId);
  193. }
  194. }