Пример #1
0
 /**
  * @param Entity\Event $event
  * @return Entity\EventResult
  */
 public static function onAfterDelete(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     $data = $event->getParameters();
     $primary = array('CONTACT_ID' => $data['primary']['ID']);
     ContactListTable::delete($primary);
     MailingSubscriptionTable::delete($primary);
     return $result;
 }
Пример #2
0
 /**
  * @param Entity\Event $event
  * @return Entity\EventResult
  */
 public static function onAfterDelete(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     $data = $event->getParameters();
     $primary = array('MAILING_ID' => $data['primary']['ID']);
     MailingGroupTable::delete($primary);
     MailingChainTable::delete($primary);
     MailingSubscriptionTable::delete($primary);
     PostingTable::delete($primary);
     return $result;
 }
Пример #3
0
    //get current user subscription from cookies
    if (empty($subscr_EMAIL)) {
        $subscr_EMAIL = $APPLICATION->get_cookie('SENDER_SUBSCR_EMAIL');
    }
    $subscr_EMAIL = strtolower(strlen($subscr_EMAIL) > 0 ? $subscr_EMAIL : $USER->GetParam("EMAIL"));
    if (isset($_SESSION['SENDER_SUBSCRIBE_LIST']) && is_array($_SESSION['SENDER_SUBSCRIBE_LIST'])) {
        $arSubscription = $_SESSION['SENDER_SUBSCRIBE_LIST']['SUBSCRIPTION'];
        $arSubscriptionRubrics = $_SESSION['SENDER_SUBSCRIBE_LIST']['RUBRIC'];
    } else {
        if (!CModule::IncludeModule("sender")) {
            $obCache->AbortDataCache();
            ShowError(GetMessage("SENDER_SUBSCR_MODULE_NOT_INSTALLED"));
            return;
        }
        if ($subscr_EMAIL != "") {
            $subscriptionDb = \Bitrix\Sender\MailingSubscriptionTable::getList(array('select' => array('ID' => 'CONTACT_ID', 'EMAIL' => 'CONTACT.EMAIL', 'EXISTED_MAILING_ID' => 'MAILING.ID'), 'filter' => array('=CONTACT.EMAIL' => $subscr_EMAIL, '!MAILING.ID' => null)));
            while ($subscription = $subscriptionDb->fetch()) {
                $arSubscription = $subscription;
                //get user's newsletter categories
                if (intval($subscription['EXISTED_MAILING_ID']) > 0) {
                    $arSubscriptionRubrics[] = $subscription['EXISTED_MAILING_ID'];
                }
            }
        }
        $_SESSION['SENDER_SUBSCRIBE_LIST']['SUBSCRIPTION'] = $arSubscription;
        $_SESSION['SENDER_SUBSCRIBE_LIST']['RUBRIC'] = $arSubscriptionRubrics;
    }
}
//page title
if ($arParams["SET_TITLE"] == "Y") {
    $APPLICATION->SetTitle(GetMessage("SENDER_SUBSCR_TITLE"), array('COMPONENT_NAME' => $this->GetName()));
Пример #4
0
 /**
  * @param $postingId
  * @param bool $checkDuplicate
  * @return bool
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function initGroupRecipients($postingId, $checkDuplicate = true)
 {
     $posting = \Bitrix\Sender\PostingTable::getRowById(array('ID' => $postingId));
     if (!$posting) {
         return false;
     }
     $checkRecipientDuplicate = $checkDuplicate;
     if (!$checkDuplicate) {
         if ($posting['STATUS'] == \Bitrix\Sender\PostingTable::STATUS_NEW) {
             $primary = array('POSTING_ID' => $postingId);
             \Bitrix\Sender\PostingRecipientTable::delete($primary);
             $checkRecipientDuplicate = false;
         }
     }
     // fetch all unsubscribed emails of current mailing for excluding from recipients
     $emailNotSendList = array();
     $unSubEmailDb = \Bitrix\Sender\MailingSubscriptionTable::getUnSubscriptionList(array('select' => array('EMAIL' => 'CONTACT.EMAIL'), 'filter' => array('=MAILING_ID' => $posting['MAILING_ID'])));
     while ($unSubEmail = $unSubEmailDb->fetch()) {
         $emailNotSendList[] = $unSubEmail['EMAIL'];
     }
     $groupConnectorsDataCount = array();
     $connection = \Bitrix\Main\Application::getConnection();
     $conHelper = $connection->getSqlHelper();
     $statusRecipientNone = \Bitrix\Sender\PostingRecipientTable::SEND_RESULT_NONE;
     // fetch all connectors for getting emails
     $groupConnectorList = array();
     $groupConnectorDb = \Bitrix\Sender\MailingGroupTable::getList(array('select' => array('INCLUDE', 'CONNECTOR_ENDPOINT' => 'GROUP.GROUP_CONNECTOR.ENDPOINT', 'GROUP_ID'), 'filter' => array('MAILING_ID' => $posting['MAILING_ID']), 'order' => array('INCLUDE' => 'DESC', 'GROUP_ID' => 'ASC')));
     while ($group = $groupConnectorDb->fetch()) {
         $groupConnectorList[] = $group;
     }
     $groupConnectorList[] = array('INCLUDE' => true, 'CONNECTOR_ENDPOINT' => array('FIELDS' => array('MAILING_ID' => $posting['MAILING_ID'])), 'GROUP_ID' => null, 'CONNECTOR' => new \Bitrix\Sender\SenderConnectorSubscriber());
     foreach ($groupConnectorList as $group) {
         $connector = null;
         if (isset($group['CONNECTOR']) && is_object($group['CONNECTOR'])) {
             $connector = $group['CONNECTOR'];
         } elseif (is_array($group['CONNECTOR_ENDPOINT'])) {
             $connector = \Bitrix\Sender\ConnectorManager::getConnector($group['CONNECTOR_ENDPOINT']);
         }
         if (!$connector) {
             continue;
         }
         $connectorDataCount = 0;
         $connector->setFieldValues($group['CONNECTOR_ENDPOINT']['FIELDS']);
         $connectorDataDb = $connector->getResult();
         while (true) {
             $emailList = array();
             $connectorDataList = array();
             $maxPart = 200;
             while ($connectorData = $connectorDataDb->fetch()) {
                 // collect connectors counter of addresses
                 $connectorDataCount++;
                 // exclude unsubscribed addresses
                 $connectorData['EMAIL'] = trim(strtolower($connectorData['EMAIL']));
                 if (strlen($connectorData['EMAIL']) <= 0 || in_array($connectorData['EMAIL'], $emailNotSendList)) {
                     continue;
                 }
                 $emailList[] = $connectorData['EMAIL'];
                 $connectorDataList[$connectorData['EMAIL']] = $connectorData;
                 $maxPart--;
                 if ($maxPart == 0) {
                     break;
                 }
             }
             if (empty($emailList)) {
                 break;
             }
             foreach ($emailList as &$email) {
                 $email = $conHelper->forSql($email);
             }
             $emailListString = "'" . implode("', '", $emailList) . "'";
             if ($group['INCLUDE']) {
                 // add address if not exists
                 if ($checkRecipientDuplicate) {
                     $recipientEmailDb = $connection->query("select EMAIL from b_sender_posting_recipient where EMAIL in (" . $emailListString . ") and POSTING_ID=" . intval($postingId));
                     while ($recipientEmail = $recipientEmailDb->fetch()) {
                         unset($connectorDataList[$recipientEmail['EMAIL']]);
                     }
                 }
                 if (!empty($connectorDataList)) {
                     $insertDataList = array();
                     $insertColumnNamesString = array();
                     foreach ($connectorDataList as $email => $connectorData) {
                         $recipientInsert = array('NAME' => "'" . $conHelper->forSql($connectorData['NAME']) . "'", 'EMAIL' => "'" . $conHelper->forSql($connectorData['EMAIL']) . "'", 'STATUS' => "'" . $statusRecipientNone . "'", 'POSTING_ID' => intval($postingId), 'USER_ID' => "NULL", 'FIELDS' => "NULL");
                         if (array_key_exists('USER_ID', $connectorData) && intval($connectorData['USER_ID']) > 0) {
                             $recipientInsert['USER_ID'] = intval($connectorData['USER_ID']);
                         }
                         if (array_key_exists('FIELDS', $connectorData) && count($connectorData['FIELDS']) > 0) {
                             $recipientInsert['FIELDS'] = "'" . $conHelper->forSql(serialize($connectorData['FIELDS'])) . "'";
                         }
                         $insertColumnNamesString = implode(", ", array_keys($recipientInsert));
                         $insertColumnValuesString = implode(", ", array_values($recipientInsert));
                         $insertDataList[] = $insertColumnValuesString;
                     }
                     if ($insertDataList && $insertColumnNamesString) {
                         $insertDataListString = implode('),(', $insertDataList);
                         $connection->query("insert into b_sender_posting_recipient(" . $insertColumnNamesString . ") values(" . $insertDataListString . ")");
                     }
                 }
             } else {
                 // delete address from posting
                 $connection->query("delete from b_sender_posting_recipient where EMAIL in (" . $emailListString . ") and POSTING_ID=" . intval($postingId));
             }
         }
         //\Bitrix\Sender\GroupConnectorTable::update(array('ID' => $group['GROUP_CONNECTOR_ID']), array('ADDRESS_COUNT' => $connectorDataCount));
         // collect groups counter of addresses
         if (!empty($group['GROUP_ID'])) {
             if (array_key_exists($group['GROUP_ID'], $groupConnectorsDataCount)) {
                 $groupConnectorsDataCount[$group['GROUP_ID']] += $connectorDataCount;
             } else {
                 $groupConnectorsDataCount[$group['GROUP_ID']] = $connectorDataCount;
             }
         }
         unset($connector);
     }
     // update group counter of addresses
     foreach ($groupConnectorsDataCount as $groupId => $groupDataCount) {
         \Bitrix\Sender\GroupTable::update($groupId, array('ADDRESS_COUNT' => $groupDataCount));
     }
     return true;
 }
Пример #5
0
 /**
  * @param string $email
  * @param array $mailingList
  * @param string $siteId
  * @return int $contactId
  * //add subscription and returns subscription id
  */
 public static function add($email, array $mailingIdList)
 {
     $contactId = null;
     $email = strtolower($email);
     $contactDb = ContactTable::getList(array('filter' => array('=EMAIL' => $email)));
     if ($contact = $contactDb->fetch()) {
         $contactId = $contact['ID'];
     } else {
         $contactAddDb = ContactTable::add(array('EMAIL' => $email));
         if ($contactAddDb->isSuccess()) {
             $contactId = $contactAddDb->getId();
         }
     }
     if (!empty($contactId)) {
         foreach ($mailingIdList as $mailingId) {
             $primary = array('MAILING_ID' => $mailingId, 'CONTACT_ID' => $contactId);
             $existSub = MailingSubscriptionTable::getRowById($primary);
             if (!$existSub) {
                 MailingSubscriptionTable::add($primary);
             }
         }
     } else {
     }
     return $contactId;
 }
Пример #6
0
 /**
  * Return true if email address was unsubscribed
  *
  * @param int $mailingId
  * @param string $email
  * @return bool
  */
 public static function isUnsubscibed($mailingId, $email)
 {
     $email = strtolower($email);
     $unSubDb = MailingSubscriptionTable::getUnSubscriptionList(array('select' => array('MAILING_ID'), 'filter' => array('=MAILING_ID' => $mailingId, '=CONTACT.EMAIL' => $email)));
     if ($unSubDb->fetch()) {
         return true;
     }
     return false;
 }
Пример #7
0
 public static function updateMailingSubscription()
 {
     // get list of all subscribers and unsubscribers
     $existedSubList = array();
     $existedSubDb = \Bitrix\Sender\MailingSubscriptionTable::getList(array('select' => array('EMAIL' => 'CONTACT.EMAIL', 'MAILING_ID')));
     while ($existedSub = $existedSubDb->fetch()) {
         $existedSubList[$existedSub['EMAIL']][] = $existedSub['MAILING_ID'];
     }
     // get list of all unsubscribers
     $dataDb = \Bitrix\Sender\PostingUnsubTable::getList(array('select' => array('EMAIL' => 'UPDATE_RECIPIENT.EMAIL', 'MAILING_ID' => 'UPDATE_POSTING.MAILING_ID'), 'filter' => array(), 'runtime' => array(new \Bitrix\Main\Entity\ReferenceField('UPDATE_RECIPIENT', 'Bitrix\\Sender\\PostingRecipientTable', array('=this.RECIPIENT_ID' => 'ref.ID'), array('join_type' => 'INNER')), new \Bitrix\Main\Entity\ReferenceField('UPDATE_POSTING', 'Bitrix\\Sender\\PostingTable', array('=this.POSTING_ID' => 'ref.ID'), array('join_type' => 'INNER'))), 'order' => array('ID' => 'ASC')));
     while ($data = $dataDb->fetch()) {
         if (self::isTimeUp()) {
             return true;
         }
         if (isset($existedSubList[$data['EMAIL']]) && in_array($data['MAILING_ID'], $existedSubList[$data['EMAIL']])) {
             continue;
         }
         $contactId = \Bitrix\Sender\ContactTable::addIfNotExist(array('EMAIL' => $data['EMAIL']));
         $primary = array('MAILING_ID' => $data['MAILING_ID'], 'CONTACT_ID' => $contactId);
         $fields = array('IS_UNSUB' => 'Y');
         $row = \Bitrix\Sender\MailingSubscriptionTable::getRowById($primary);
         if (!$row) {
             $result = \Bitrix\Sender\MailingSubscriptionTable::add($fields + $primary);
             $result->isSuccess();
         }
     }
     return false;
 }