if ($arParams["CONFIRMATION"]) { // check if email already subscribed $sendEmailToSubscriber = true; if (count($mailingIdList) > 0) { $arExistedSubscription = array(); $subscriptionDb = \Bitrix\Sender\MailingSubscriptionTable::getList(array('select' => array('EXISTED_MAILING_ID' => 'MAILING.ID'), 'filter' => array('=CONTACT.EMAIL' => strtolower($_POST["SENDER_SUBSCRIBE_EMAIL"]), '!MAILING.ID' => null))); while ($subscription = $subscriptionDb->fetch()) { $arExistedSubscription[] = $subscription['EXISTED_MAILING_ID']; } // send if it have new subscriptions only if (count(array_diff($mailingIdList, $arExistedSubscription)) <= 0) { $sendEmailToSubscriber = false; } } else { // do not send if no selected mailings and subscriber existed $contactDb = \Bitrix\Sender\ContactTable::getList(array('filter' => array('=EMAIL' => strtolower($_POST["SENDER_SUBSCRIBE_EMAIL"])))); if ($contact = $contactDb->fetch()) { $sendEmailToSubscriber = false; } } if ($sendEmailToSubscriber) { \Bitrix\Sender\Subscription::sendEventConfirm($_POST["SENDER_SUBSCRIBE_EMAIL"], $mailingIdList, SITE_ID); $APPLICATION->set_cookie("SENDER_SUBSCR_EMAIL", $_POST["SENDER_SUBSCRIBE_EMAIL"], $cookieLifeTime); $arResult['MESSAGE'] = array('TYPE' => 'NOTE', 'CODE' => 'message_confirm'); $subscr_EMAIL = $_POST["SENDER_SUBSCRIBE_EMAIL"]; } else { $APPLICATION->set_cookie("SENDER_SUBSCR_EMAIL", $_POST["SENDER_SUBSCRIBE_EMAIL"], $cookieLifeTime); $arResult['MESSAGE'] = array('TYPE' => 'NOTE', 'CODE' => 'message_success'); $subscr_EMAIL = $_POST["SENDER_SUBSCRIBE_EMAIL"]; } } else {
$connection->startTransaction(); $dataDeleteDb = \Bitrix\Sender\ContactTable::delete($dataPrimary); if (!$dataDeleteDb->isSuccess()) { $connection->rollbackTransaction(); $lAdmin->AddGroupError(GetMessage("rub_del_err"), $ID); } $connection->commitTransaction(); break; } } } $selectParams = array('select' => array('ID', 'DATE_INSERT', 'NAME', 'EMAIL'), 'filter' => $arFilter, 'order' => array($by => $order)); if ($needGroup) { $selectParams['group'] = array('ID', 'DATE_INSERT', 'NAME', 'EMAIL'); } $groupListDb = \Bitrix\Sender\ContactTable::getList($selectParams); $rsData = new CAdminResult($groupListDb, $sTableID); $rsData->NavStart(); $lAdmin->NavText($rsData->GetNavPrint(GetMessage("contact_nav"))); $lAdmin->AddHeaders(array(array("id" => "DATE_INSERT", "content" => GetMessage("rub_date_insert"), "sort" => "DATE_INSERT", "align" => "left", "default" => true), array("id" => "NAME", "content" => GetMessage("rub_name"), "sort" => "NAME", "default" => true), array("id" => "EMAIL", "content" => GetMessage("rub_email"), "sort" => "EMAIL", "default" => true), array("id" => "LIST", "content" => GetMessage("rub_list"), "default" => true))); while ($arRes = $rsData->NavNext(true, "f_")) { $row =& $lAdmin->AddRow($f_ID, $arRes); $row->AddViewField("DATE_INSERT", $f_DATE_INSERT); $row->AddInputField("NAME", array("size" => 20)); $row->AddViewField("NAME", $f_NAME); $row->AddInputField("EMAIL", array("size" => 20)); $row->AddViewField("EMAIL", $f_EMAIL); $arList = array(); $contactListDb = \Bitrix\Sender\ListTable::getList(array('select' => array('NAME', 'ID'), 'filter' => array('CONTACT_LIST.CONTACT_ID' => $f_ID))); while ($contactList = $contactListDb->fetch()) { $arList[] = htmlspecialcharsbx($contactList['NAME']);
switch ($_REQUEST['action']) { case "delete": @set_time_limit(0); $connection = \Bitrix\Main\Application::getInstance()->getConnection(); $connection->startTransaction(); $dataDeleteDb = \Bitrix\Sender\ContactTable::delete($dataPrimary); if (!$dataDeleteDb->isSuccess()) { $connection->rollbackTransaction(); $lAdmin->AddGroupError(GetMessage("rub_del_err"), $ID); } $connection->commitTransaction(); break; } } } $groupListDb = \Bitrix\Sender\ContactTable::getList(array('select' => array('ID', 'DATE_INSERT', 'NAME', 'EMAIL'), 'filter' => $arFilter, 'order' => array($by => $order))); $rsData = new CAdminResult($groupListDb, $sTableID); $rsData->NavStart(); $lAdmin->NavText($rsData->GetNavPrint(GetMessage("contact_nav"))); $lAdmin->AddHeaders(array(array("id" => "DATE_INSERT", "content" => GetMessage("rub_date_insert"), "sort" => "DATE_INSERT", "align" => "left", "default" => true), array("id" => "NAME", "content" => GetMessage("rub_name"), "sort" => "NAME", "default" => true), array("id" => "EMAIL", "content" => GetMessage("rub_email"), "sort" => "EMAIL", "default" => true), array("id" => "LIST", "content" => GetMessage("rub_list"), "default" => true))); while ($arRes = $rsData->NavNext(true, "f_")) { $row =& $lAdmin->AddRow($f_ID, $arRes); $row->AddViewField("DATE_INSERT", $f_DATE_INSERT); $row->AddInputField("NAME", array("size" => 20)); $row->AddViewField("NAME", $f_NAME); $row->AddInputField("EMAIL", array("size" => 20)); $row->AddViewField("EMAIL", $f_EMAIL); $arList = array(); $contactListDb = \Bitrix\Sender\ListTable::getList(array('select' => array('NAME', 'ID'), 'filter' => array('CONTACT_LIST.CONTACT_ID' => $f_ID))); while ($contactList = $contactListDb->fetch()) { $arList[] = htmlspecialcharsbx($contactList['NAME']);
/** * @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; }
/** * @param Connector $connector * @param null $pageNumber * @param int $timeout * @return array * @throws \Bitrix\Main\ArgumentException */ public static function addFromConnector(Connector $connector, $pageNumber = null, $timeout = 0) { $startTime = getmicrotime(); $withoutNav = empty($pageNumber); $result = false; $onlyOneLoop = false; $rowsInPage = 5; $countAll = 0; $countProcessed = 0; $countUpdated = 0; $countAdded = 0; $countError = 0; $dataDb = $connector->getResult(); if ($dataDb->resourceCDBResult) { $dataDb = $dataDb->resourceCDBResult; } elseif ($dataDb->resource) { $dataDb = new \CDBResult($dataDb->resource); } else { $dataDb = new \CDBResult(); $dataDb->InitFromArray(array()); } if (!is_subclass_of($dataDb, 'CDBResultMysql')) { $rowsInPage = 50; $onlyOneLoop = true; } while ($timeout == 0 || getmicrotime() - $startTime < $timeout) { if (!$withoutNav) { $dataDb->NavStart($rowsInPage, false, $pageNumber); $countAll = $dataDb->SelectedRowsCount(); } $listId = null; while ($arData = $dataDb->Fetch()) { if ($withoutNav) { $countAll++; } $countProcessed++; if (!$listId) { $listId = ListTable::addIfNotExist($connector->getModuleId() . '_' . $connector->getCode(), Loc::getMessage('CONTACT_PULL_LIST_PREFIX') . $connector->getName()); } $id = null; $contactDb = ContactTable::getList(array('select' => array('ID'), 'filter' => array('EMAIL' => $arData['EMAIL']))); if ($arContact = $contactDb->fetch()) { $id = $arContact['ID']; $countUpdated++; } else { $resultAdd = static::add(array('NAME' => $arData['NAME'], 'EMAIL' => $arData['EMAIL'], 'USER_ID' => $arData['USER_ID'])); if ($resultAdd->isSuccess()) { $id = $resultAdd->getId(); $countAdded++; } else { $countError++; } } if ($id) { ContactListTable::addIfNotExist($id, $listId); } } if ($withoutNav) { $result = false; break; } if ($dataDb->NavPageCount <= $pageNumber) { $result = false; break; } else { $pageNumber++; $result = $pageNumber; } if ($onlyOneLoop) { break; } } if ($withoutNav) { $countProgress = $countAll; } else { $countProgress = ($pageNumber - 1) * $dataDb->NavPageSize; if (!$result || $countProgress > $countAll) { $countProgress = $countAll; } } return array('STATUS' => $result, 'COUNT_ALL' => $countAll, 'COUNT_PROGRESS' => $countProgress, 'COUNT_PROCESSED' => $countProcessed, 'COUNT_NEW' => $countAdded, 'COUNT_ERROR' => $countError); }
$connection->startTransaction(); $dataDeleteDb = \Bitrix\Sender\ContactTable::delete($dataPrimary); if (!$dataDeleteDb->isSuccess()) { $connection->rollbackTransaction(); $lAdmin->AddGroupError(GetMessage("rub_del_err"), $ID); } $connection->commitTransaction(); break; } } } $groupListDb = \Bitrix\Sender\ContactTable::getList(array( 'select' => array('*'), 'filter' => $arFilter, 'order' => array($by=>$order) )); $rsData = new CAdminResult($groupListDb, $sTableID); $rsData->NavStart(); $lAdmin->NavText($rsData->GetNavPrint(GetMessage("contact_nav"))); $lAdmin->AddHeaders(array( array( "id" =>"DATE_INSERT", "content" =>GetMessage("rub_date_insert"), "sort" =>"DATE_INSERT", "align" =>"left", "default" =>true, ), array( "id" =>"NAME",
/** @return \CDBResult */ public function getData() { $listId = $this->getFieldValue('LIST_ID', null); $contactDb = ContactTable::getList(array('select' => array('NAME', 'EMAIL'), 'filter' => array('CONTACT_LIST.LIST_ID' => $listId))); return new \CDBResult($contactDb); }