123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- <?php
- namespace Dotdigitalgroup\Email\Model;
- class Contact extends \Magento\Framework\Model\AbstractModel
- {
- const EMAIL_CONTACT_IMPORTED = 1;
- const EMAIL_CONTACT_NOT_IMPORTED = null;
- const EMAIL_SUBSCRIBER_NOT_IMPORTED = null;
- /**
- * Constructor.
- *
- * @return null
- */
- public function _construct()
- {
- $this->_init(\Dotdigitalgroup\Email\Model\ResourceModel\Contact::class);
- }
- /**
- * Load contact by customer id.
- *
- * @param int $customerId
- *
- * @return $this
- */
- public function loadByCustomerId($customerId)
- {
- $contact = $this->getCollection()
- ->loadByCustomerId($customerId);
- if ($contact) {
- return $contact;
- }
- return $this;
- }
- /**
- * Get all customer contacts not imported for a website.
- *
- * @param int $websiteId
- * @param int $pageSize
- *
- * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
- */
- public function getContactsToImportForWebsite($websiteId, $pageSize = 100)
- {
- return $this->getCollection()
- ->getContactsToImportForWebsite($websiteId, $pageSize);
- }
- /**
- * Get missing contacts.
- *
- * @param int $websiteId
- * @param int $pageSize
- *
- * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
- */
- public function getMissingContacts($websiteId, $pageSize = 100)
- {
- return $this->getCollection()
- ->getMissingContacts($websiteId, $pageSize);
- }
- /**
- * Load Contact by Email.
- *
- * @param string $email
- * @param int $websiteId
- *
- * @return $this
- */
- public function loadByCustomerEmail($email, $websiteId)
- {
- $customer = $this->getCollection()
- ->loadByCustomerEmail($email, $websiteId);
- if ($customer) {
- return $customer;
- } else {
- return $this->setEmail($email)
- ->setWebsiteId($websiteId);
- }
- }
- /**
- * Contact subscribers to import for website.
- *
- * @param \Magento\Store\Model\Website $website
- * @param int $limit
- * @param bool $isCustomerCheck
- *
- * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
- */
- public function getSubscribersToImport(
- \Magento\Store\Model\Website $website,
- $limit = 1000,
- $isCustomerCheck = true
- ) {
- return $this->getCollection()
- ->getSubscribersToImport(
- $website,
- $limit,
- $isCustomerCheck
- );
- }
- /**
- * Contact subscribers to import for website.
- *
- * @param array $emails
- *
- * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
- */
- public function getSubscribersToImportFromEmails($emails)
- {
- return $this->getCollection()
- ->getSubscribersToImportFromEmails($emails);
- }
- /**
- * Get all not imported guests for a website.
- *
- * @param \Magento\Store\Model\Website $website
- * @param boolean $onlySubscriber
- *
- * @return \Dotdigitalgroup\Email\Model\ResourceModel\Contact\Collection
- */
- public function getGuests($website, $onlySubscriber = false)
- {
- return $this->getCollection()
- ->getGuests($website->getId(), $onlySubscriber);
- }
- /**
- * Number contacts marked as imported.
- *
- * @return int
- */
- public function getNumberOfImportedContacs()
- {
- return $this->getCollection()
- ->getNumberOfImportedContacts();
- }
- /**
- * Get the number of customers for a website.
- *
- * @param int $websiteId
- *
- * @return int
- */
- public function getNumberCustomerContacts($websiteId = 0)
- {
- return $this->getCollection()
- ->getNumberCustomerContacts($websiteId);
- }
- /**
- * Get number of suppressed contacts as customer.
- *
- * @param int $websiteId
- *
- * @return int
- */
- public function getNumberCustomerSuppressed($websiteId = 0)
- {
- return $this->getCollection()
- ->getNumberCustomerSuppressed($websiteId);
- }
- /**
- * Get number of synced customers.
- *
- * @param int $websiteId
- *
- * @return int
- */
- public function getNumberCustomerSynced($websiteId = 0)
- {
- return $this->getCollection()
- ->getNumberCustomerSynced($websiteId);
- }
- /**
- * Get number of subscribers synced.
- *
- * @param int $websiteId
- *
- * @return int
- */
- public function getNumberSubscribersSynced($websiteId = 0)
- {
- return $this->getCollection()
- ->getNumberSubscribersSynced($websiteId);
- }
- /**
- * Get number of subscribers.
- *
- * @param int $websiteId
- *
- * @return int
- */
- public function getNumberSubscribers($websiteId = 0)
- {
- return $this->getCollection()
- ->getNumberSubscribers($websiteId);
- }
- }
|