Beispiel #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('MAILING_ID' => $data['primary']['ID']);
     MailingGroupTable::delete($primary);
     MailingChainTable::delete($primary);
     PostingTable::delete($primary);
     return $result;
 }
Beispiel #2
0
 /**
  * @param $postingId
  * @param bool $checkDuplicate
  * @return bool
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function initGroupRecipients($postingId, $checkDuplicate = false)
 {
     $arPosting = \Bitrix\Sender\PostingTable::getRowById(array('ID' => $postingId));
     if (!$arPosting) {
         return false;
     }
     $checkRecipientDuplicate = $checkDuplicate;
     if (!$checkDuplicate) {
         if ($arPosting['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
     $arEmailNotSend = array();
     $recipientUnsubDb = \Bitrix\Sender\PostingUnsubTable::getList(array('select' => array('EMAIL' => 'POSTING_RECIPIENT.EMAIL'), 'filter' => array('POSTING.MAILING_ID' => $arPosting['MAILING_ID'])));
     while ($recipientUnsub = $recipientUnsubDb->fetch()) {
         $arEmailNotSend[] = $recipientUnsub['EMAIL'];
     }
     $groupConnectorsDataCount = array();
     $connection = \Bitrix\Main\Application::getConnection();
     $conHelper = $connection->getSqlHelper();
     $statusRecipientNone = \Bitrix\Sender\PostingRecipientTable::SEND_RESULT_NONE;
     // fetch all connectors for getting emails
     $groupDb = \Bitrix\Sender\MailingGroupTable::getList(array('select' => array('INCLUDE', 'CONNECTOR_ENDPOINT' => 'GROUP.GROUP_CONNECTOR.ENDPOINT', 'GROUP_ID'), 'filter' => array('MAILING_ID' => $arPosting['MAILING_ID']), 'order' => array('INCLUDE' => 'DESC', 'GROUP_ID' => 'ASC')));
     while ($group = $groupDb->fetch()) {
         $connector = \Bitrix\Sender\ConnectorManager::getConnector($group['CONNECTOR_ENDPOINT']);
         if (!$connector) {
             continue;
         }
         $connectorDataCount = 0;
         $connector->setFieldValues($group['CONNECTOR_ENDPOINT']['FIELDS']);
         $connectorDataDb = $connector->getData();
         while (true) {
             $emailList = array();
             $connectorDataList = array();
             $maxPart = 200;
             while ($arConnectorData = $connectorDataDb->Fetch()) {
                 // collect connectors counter of addresses
                 $connectorDataCount++;
                 // exclude unsubscribed addresses
                 $arConnectorData['EMAIL'] = trim(strtolower($arConnectorData['EMAIL']));
                 if (strlen($arConnectorData['EMAIL']) <= 0 || in_array($arConnectorData['EMAIL'], $arEmailNotSend)) {
                     continue;
                 }
                 $emailList[] = $arConnectorData['EMAIL'];
                 $connectorDataList[$arConnectorData['EMAIL']] = $arConnectorData;
                 $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)) {
                     foreach ($connectorDataList as $email => $arConnectorData) {
                         $arRecipient = array('NAME' => "'" . $conHelper->forSql($arConnectorData['NAME']) . "'", 'EMAIL' => "'" . $conHelper->forSql($arConnectorData['EMAIL']) . "'", 'STATUS' => "'" . $statusRecipientNone . "'", 'POSTING_ID' => intval($postingId));
                         if (array_key_exists('USER_ID', $arConnectorData) && intval($arConnectorData['USER_ID']) > 0) {
                             $arRecipient['USER_ID'] = intval($arConnectorData['USER_ID']);
                         }
                         $insertColumnNamesString = implode(", ", array_keys($arRecipient));
                         $insertColumnValuesString = implode(", ", array_values($arRecipient));
                         $connection->query("insert into b_sender_posting_recipient(" . $insertColumnNamesString . ") values(" . $insertColumnValuesString . ")");
                     }
                 }
             } 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 (array_key_exists($group['GROUP_ID'], $groupConnectorsDataCount)) {
             $groupConnectorsDataCount[$group['GROUP_ID']] += $connectorDataCount;
         } else {
             $groupConnectorsDataCount[$group['GROUP_ID']] = $connectorDataCount;
         }
     }
     // update group counter of addresses
     foreach ($groupConnectorsDataCount as $groupId => $groupDataCount) {
         \Bitrix\Sender\GroupTable::update($groupId, array('ADDRESS_COUNT' => $groupDataCount));
     }
     return true;
 }
Beispiel #3
0
    }
    if ($res) {
        if ($apply != "") {
            LocalRedirect("/bitrix/admin/sender_mailing_edit.php?ID=" . $ID . "&lang=" . LANG . "&" . $tabControl->ActiveTabParam());
        } else {
            LocalRedirect("/bitrix/admin/sender_mailing_admin.php?lang=" . LANG);
        }
    } else {
        if (!empty($arError)) {
            $message = new CAdminMessage(implode("<br>", $arError));
        }
        $bVarsFromForm = true;
    }
} else {
    $GROUP_EXCLUDE = $GROUP_INCLUDE = array();
    $groupDb = \Bitrix\Sender\MailingGroupTable::getList(array('select' => array('ID' => 'GROUP_ID', 'INCLUDE'), 'filter' => array('MAILING_ID' => $ID)));
    while ($arGroup = $groupDb->fetch()) {
        if ($arGroup['INCLUDE']) {
            $GROUP_INCLUDE[] = $arGroup['ID'];
        } else {
            $GROUP_EXCLUDE[] = $arGroup['ID'];
        }
    }
}
//Edit/Add part
ClearVars();
$str_SORT = 100;
$str_ACTIVE = "Y";
$str_VISIBLE = "Y";
if ($ID > 0) {
    $rubric = new CDBResult(\Bitrix\Sender\MailingTable::getById($ID));
Beispiel #4
0
 public static function getPersonalizeList($id)
 {
     $result = array();
     // fetch all connectors for getting emails
     $groupConnectorDb = \Bitrix\Sender\MailingGroupTable::getList(array('select' => array('CONNECTOR_ENDPOINT' => 'GROUP.GROUP_CONNECTOR.ENDPOINT', 'GROUP_ID'), 'filter' => array('MAILING_ID' => $id, 'INCLUDE' => true), 'order' => array('GROUP_ID' => 'ASC')));
     while ($groupConnector = $groupConnectorDb->fetch()) {
         $connector = null;
         if (is_array($groupConnector['CONNECTOR_ENDPOINT'])) {
             $connector = \Bitrix\Sender\ConnectorManager::getConnector($groupConnector['CONNECTOR_ENDPOINT']);
         }
         if (!$connector) {
             continue;
         }
         $result = array_merge($result, $connector->getPersonalizeList());
     }
     return $result;
 }