/** @return \CDBResult */
 public function getData()
 {
     $mailingId = $this->getFieldValue('MAILING_ID', 0);
     $send = $this->getFieldValue('SEND', null);
     $read = $this->getFieldValue('READ', null);
     $click = $this->getFieldValue('CLICK', null);
     $unsub = $this->getFieldValue('UNSUB', null);
     $filter = array('POSTING.MAILING_ID' => $mailingId);
     if ($send == 'Y') {
         $filter['!STATUS'] = PostingRecipientTable::SEND_RESULT_NONE;
     } elseif ($send == 'N') {
         $filter['STATUS'] = PostingRecipientTable::SEND_RESULT_NONE;
     }
     if ($read == 'Y') {
         $filter['!POSTING_READ.ID'] = null;
     } elseif ($read == 'N') {
         $filter['POSTING_READ.ID'] = null;
     }
     if ($click == 'Y') {
         $filter['!POSTING_CLICK.ID'] = null;
     } elseif ($click == 'N') {
         $filter['POSTING_CLICK.ID'] = null;
     }
     if ($unsub == 'Y') {
         $filter['!POSTING_UNSUB.ID'] = null;
     } elseif ($unsub == 'N') {
         $filter['POSTING_UNSUB.ID'] = null;
     }
     $recipientDb = PostingRecipientTable::getList(array('select' => array('NAME', 'EMAIL'), 'filter' => $filter, 'group' => array('NAME', 'EMAIL')));
     return new \CDBResult($recipientDb);
 }
Example #2
0
 public static function onSetDayContextAttributes(DayContext $context)
 {
     $id = null;
     if (isset($_SESSION[self::CLICK_PARAM_NAME])) {
         $id = $_SESSION[self::CLICK_PARAM_NAME];
     }
     if (!is_numeric($id) || $id <= 0) {
         return;
     }
     $recipientDb = PostingRecipientTable::getList(array('select' => array('MAILING_CHAIN_ID' => 'POSTING.MAILING_CHAIN_ID'), 'filter' => array('ID' => $id)));
     if ($recipient = $recipientDb->fetch()) {
         $context->setAttribute('sender_chain_source', $recipient['MAILING_CHAIN_ID']);
     }
 }
Example #3
0
 /**
  * @param $id
  * @return array
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function getRecipientCountByStatus($id)
 {
     $arStatus = array();
     $arSelect = array('CNT', 'STATUS');
     $arFilter = array('POSTING_ID' => $id);
     $postingContactDb = PostingRecipientTable::getList(array('select' => $arSelect, 'filter' => $arFilter, 'runtime' => array(new Entity\ExpressionField('CNT', 'COUNT(*)'))));
     while ($arPostingContact = $postingContactDb->fetch()) {
         $arStatus[$arPostingContact['STATUS']] = intval($arPostingContact['CNT']);
     }
     return $arStatus;
 }
Example #4
0
 /**
  * Return true if chain can resend mails to recipients who have error sending
  *
  * @param $id
  * @return bool
  */
 public static function canReSendErrorRecipients($id)
 {
     $mailingChainDb = static::getList(array('select' => array('POSTING_ID'), 'filter' => array('=ID' => $id, '!REITERATE' => 'Y', '!POSTING_ID' => null, '=STATUS' => static::STATUS_END)));
     if ($mailingChain = $mailingChainDb->fetch()) {
         $errorRecipientDb = PostingRecipientTable::getList(array('select' => array('ID'), 'filter' => array('=POSTING_ID' => $mailingChain['POSTING_ID'], '=STATUS' => PostingRecipientTable::SEND_RESULT_ERROR), 'limit' => 1));
         if ($errorRecipientDb->fetch()) {
             return true;
         }
     }
     return false;
 }
Example #5
0
 /**
  * @param $id
  * @param int $timeout
  * @param int $maxMailCount
  * @return bool|string
  * @throws \Bitrix\Main\ArgumentException
  * @throws \Bitrix\Main\DB\Exception
  * @throws \Bitrix\Main\Db\SqlQueryException
  * @throws \Exception
  */
 public static function send($id, $timeout = 0, $maxMailCount = 0)
 {
     $start_time = getmicrotime();
     @set_time_limit(0);
     static::$emailSentPerIteration = 0;
     $postingDb = PostingTable::getList(array('select' => array('ID', 'STATUS', 'MAILING_ID', 'MAILING_CHAIN_ID', 'MAILING_CHAIN_REITERATE' => 'MAILING_CHAIN.REITERATE', 'MAILING_CHAIN_IS_TRIGGER' => 'MAILING_CHAIN.IS_TRIGGER'), 'filter' => array('ID' => $id, 'MAILING.ACTIVE' => 'Y', 'MAILING_CHAIN.STATUS' => MailingChainTable::STATUS_SEND)));
     $postingData = $postingDb->fetch();
     // posting not found
     if (!$postingData) {
         return static::SEND_RESULT_ERROR;
     }
     // if posting in new status, then import recipients from groups and set right status for sending
     $isInitGroupRecipients = false;
     $isChangeStatusToPart = false;
     if ($postingData["STATUS"] == PostingTable::STATUS_NEW) {
         $isInitGroupRecipients = true;
         $isChangeStatusToPart = true;
     }
     if ($postingData["STATUS"] != PostingTable::STATUS_PART && $postingData["MAILING_CHAIN_IS_TRIGGER"] == 'Y') {
         $isInitGroupRecipients = false;
         $isChangeStatusToPart = true;
     }
     if ($isInitGroupRecipients) {
         PostingTable::initGroupRecipients($postingData['ID']);
     }
     if ($isChangeStatusToPart) {
         PostingTable::update(array('ID' => $postingData['ID']), array('STATUS' => PostingTable::STATUS_PART));
         $postingData["STATUS"] = PostingTable::STATUS_PART;
     }
     // posting not in right status
     if ($postingData["STATUS"] != PostingTable::STATUS_PART) {
         return static::SEND_RESULT_ERROR;
     }
     // lock posting for exclude double parallel sending
     if (static::lockPosting($id) === false) {
         throw new \Bitrix\Main\DB\Exception(Loc::getMessage('SENDER_POSTING_MANAGER_ERR_LOCK'));
     }
     // select all recipients of posting, only not processed
     $recipientDataDb = PostingRecipientTable::getList(array('filter' => array('POSTING_ID' => $postingData['ID'], 'STATUS' => PostingRecipientTable::SEND_RESULT_NONE), 'limit' => $maxMailCount));
     while ($recipientData = $recipientDataDb->fetch()) {
         // create name from email
         $recipientEmail = $recipientData["EMAIL"];
         if (empty($recipientData["NAME"])) {
             $recipientEmailParts = explode('@', $recipientEmail);
             $recipientName = $recipientEmailParts[0];
         } else {
             $recipientName = $recipientData["NAME"];
         }
         // prepare params for send
         $sendParams = array('FIELDS' => array('EMAIL_TO' => $recipientEmail, 'NAME' => $recipientName, 'USER_ID' => $recipientData["USER_ID"], 'SENDER_CHAIN_CODE' => 'sender_chain_item_' . $postingData["MAILING_CHAIN_ID"], 'UNSUBSCRIBE_LINK' => Subscription::getLinkUnsub(array('MAILING_ID' => $postingData['MAILING_ID'], 'EMAIL' => $recipientEmail, 'RECIPIENT_ID' => $recipientData["ID"]))), 'TRACK_READ' => array('MODULE_ID' => "sender", 'FIELDS' => array('RECIPIENT_ID' => $recipientData["ID"])), 'TRACK_CLICK' => array('MODULE_ID' => "sender", 'FIELDS' => array('RECIPIENT_ID' => $recipientData["ID"]), 'URL_PARAMS' => array('bx_sender_conversion_id' => $recipientData["ID"])));
         if (is_array($recipientData['FIELDS']) && count($recipientData) > 0) {
             $sendParams['FIELDS'] = $sendParams['FIELDS'] + $recipientData['FIELDS'];
         }
         // set sending result to recipient
         $mailSendResult = static::sendInternal($postingData['MAILING_CHAIN_ID'], $sendParams);
         PostingRecipientTable::update(array('ID' => $recipientData["ID"]), array('STATUS' => $mailSendResult, 'DATE_SENT' => new Type\DateTime()));
         // send event
         $eventData = array('SEND_RESULT' => $mailSendResult == PostingRecipientTable::SEND_RESULT_SUCCESS, 'RECIPIENT' => $recipientData, 'POSTING' => $postingData);
         $event = new Event('sender', 'OnAfterPostingSendRecipient', array($eventData));
         $event->send();
         // limit executing script by time
         if ($timeout > 0 && getmicrotime() - $start_time >= $timeout) {
             break;
         }
         // increment sending statistic
         static::$emailSentPerIteration++;
     }
     //set status and delivered and error emails
     $statusList = PostingTable::getRecipientCountByStatus($id);
     if (!array_key_exists(PostingRecipientTable::SEND_RESULT_NONE, $statusList)) {
         if (array_key_exists(PostingRecipientTable::SEND_RESULT_ERROR, $statusList)) {
             $STATUS = PostingTable::STATUS_SENT_WITH_ERRORS;
         } else {
             $STATUS = PostingTable::STATUS_SENT;
         }
         $DATE = new Type\DateTime();
     } else {
         $STATUS = PostingTable::STATUS_PART;
         $DATE = null;
     }
     // unlock posting for exclude double parallel sending
     static::unlockPosting($id);
     // update status of posting
     PostingTable::update(array('ID' => $id), array('STATUS' => $STATUS, 'DATE_SENT' => $DATE));
     // return status to continue or end of sending
     if ($STATUS == PostingTable::STATUS_PART) {
         return static::SEND_RESULT_CONTINUE;
     } else {
         return static::SEND_RESULT_SENT;
     }
 }
        $arFilter['CLICK_TBL.RECIPIENT_ID'] = null;
        $arGroup = $arSelect;
    }
    if ($find_unsub == 'Y') {
        $arRuntime[] = new \Bitrix\Main\Entity\ReferenceField('UNSUB_TBL', 'Bitrix\\Sender\\PostingUnsubTable', array('=this.ID' => 'ref.RECIPIENT_ID'), array('join_type' => 'INNER'));
        $arGroup = $arSelect;
    } elseif ($find_unsub == 'N') {
        $arRuntime[] = new \Bitrix\Main\Entity\ReferenceField('UNSUB_TBL', 'Bitrix\\Sender\\PostingUnsubTable', array('=this.ID' => 'ref.RECIPIENT_ID'), array('join_type' => 'LEFT'));
        $arFilter['UNSUB_TBL.RECIPIENT_ID'] = null;
        $arGroup = $arSelect;
    }
}
if (isset($order)) {
    $order = $order == 'asc' ? 'ASC' : 'DESC';
}
$groupListDb = \Bitrix\Sender\PostingRecipientTable::getList(array('select' => $arSelect, 'filter' => $arFilter, 'runtime' => $arRuntime, 'group' => $arGroup, 'order' => array($by => $order)));
$aContext = array();
$rsData = new CAdminResult($groupListDb, $sTableID);
$rsData->NavStart();
$lAdmin->NavText($rsData->GetNavPrint(GetMessage("rub_nav")));
$lAdmin->AddHeaders(array(array("id" => "EMAIL", "content" => GetMessage("rub_email"), "sort" => "EMAIL", "default" => true), array("id" => "NAME", "content" => GetMessage("rub_name"), "sort" => "NAME", "default" => true)));
while ($arRes = $rsData->NavNext(true, "f_")) {
    $row =& $lAdmin->AddRow(false, $arRes);
    $row->AddViewField("NAME", $f_NAME);
    $row->AddViewField("EMAIL", $f_EMAIL);
}
$lAdmin->AddFooter(array(array("title" => GetMessage("MAIN_ADMIN_LIST_SELECTED"), "value" => $rsData->SelectedRowsCount()), array("counter" => true, "title" => GetMessage("MAIN_ADMIN_LIST_CHECKED"), "value" => "0")));
$lAdmin->AddAdminContextMenu($aContext);
$lAdmin->CheckListMode();
$APPLICATION->SetTitle(GetMessage("rub_title"));
require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php";
Example #7
0
 /**
  * @param $arData
  * @return bool
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function unsubscribe($arData)
 {
     $result = false;
     if (isset($arData['TEST']) && $arData['TEST'] == 'Y') {
         return true;
     }
     $arPosting = null;
     if ($arData['RECIPIENT_ID']) {
         $postingDb = PostingRecipientTable::getList(array('select' => array('POSTING_ID', 'POSTING_MAILING_ID' => 'POSTING.MAILING_ID'), 'filter' => array('ID' => $arData['RECIPIENT_ID'], 'EMAIL' => $arData['EMAIL'])));
         $arPosting = $postingDb->fetch();
     }
     $mailingDb = MailingTable::getList(array('select' => array('ID'), 'filter' => array('ID' => $arData['UNSUBSCRIBE_LIST'])));
     while ($mailing = $mailingDb->fetch()) {
         $unsub = null;
         if ($arPosting && $arPosting['POSTING_MAILING_ID'] == $mailing['ID']) {
             $unsub = array('POSTING_ID' => $arPosting['POSTING_ID'], 'RECIPIENT_ID' => $arData['RECIPIENT_ID']);
         } else {
             $mailingPostingDb = PostingRecipientTable::getList(array('select' => array('RECIPIENT_ID' => 'ID', 'POSTING_ID'), 'filter' => array('=POSTING.MAILING_ID' => $mailing['ID'], 'EMAIL' => $arData['EMAIL'])));
             if ($arMailingPosting = $mailingPostingDb->fetch()) {
                 $unsub = $arMailingPosting;
             }
         }
         if (!empty($unsub)) {
             $unsubExists = PostingUnsubTable::getRowById($unsub);
             if (!$unsubExists) {
                 PostingUnsubTable::add($unsub);
             }
             $result = true;
         }
         $contactDb = ContactTable::getList(array('select' => array('ID'), 'filter' => array('=EMAIL' => $arData['EMAIL'])));
         while ($contact = $contactDb->fetch()) {
             MailingSubscriptionTable::delete(array('MAILING_ID' => $mailing['ID'], 'CONTACT_ID' => $contact['ID']));
             $result = true;
         }
     }
     return $result;
 }
Example #8
0
}
$statList = array();
if ($MAILING_ID > 0) {
    $i = 1;
    $chainList = \Bitrix\Sender\MailingTable::getChain($MAILING_ID);
    foreach ($chainList as $chain) {
        $stat = array('NAME' => GetMessage("sender_stat_trig_letter") . $i++, 'SUBJECT' => $chain['SUBJECT'], 'CNT' => array('SENT_SUCCESS' => 0, 'SENT_ERROR' => 0, 'READ' => 0, 'CLICK' => 0, 'UNSUB' => 0, 'GOAL' => 0, 'START' => 0));
        $statRawDb = \Bitrix\Sender\PostingRecipientTable::getList(array('select' => array('CNT', 'READ_CNT', 'CLICK_CNT', 'UNSUB_CNT'), 'filter' => array('=POSTING.MAILING_CHAIN_ID' => $chain['ID'], '=STATUS' => array(\Bitrix\Sender\PostingRecipientTable::SEND_RESULT_SUCCESS)), 'runtime' => array(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(DISTINCT %s)', 'ID'), new \Bitrix\Main\Entity\ExpressionField('READ_CNT', 'COUNT(DISTINCT %s)', 'POSTING_READ.RECIPIENT_ID'), new \Bitrix\Main\Entity\ExpressionField('CLICK_CNT', 'COUNT(DISTINCT %s)', 'POSTING_CLICK.RECIPIENT_ID'), new \Bitrix\Main\Entity\ExpressionField('UNSUB_CNT', 'COUNT(DISTINCT %s)', 'POSTING_UNSUB.RECIPIENT_ID'))));
        while ($statRaw = $statRawDb->fetch()) {
            $stat['CNT']['SENT_SUCCESS'] += $statRaw['CNT'];
            $stat['CNT']['READ'] += $statRaw['READ_CNT'];
            $stat['CNT']['CLICK'] += $statRaw['CLICK_CNT'];
            $stat['CNT']['UNSUB'] += $statRaw['UNSUB_CNT'];
            $stat['CNT']['START'] += $statRaw['CNT'];
        }
        $statRawDb = \Bitrix\Sender\PostingRecipientTable::getList(array('select' => array('ID'), 'filter' => array('=POSTING.MAILING_CHAIN_ID' => $chain['ID'], '=STATUS' => array(\Bitrix\Sender\PostingRecipientTable::SEND_RESULT_SUCCESS, \Bitrix\Sender\PostingRecipientTable::SEND_RESULT_DENY), '!DATE_DENY' => null)));
        $stat['CNT']['GOAL'] = $statRawDb->getSelectedRowsCount();
        $statList['CHAIN'][] = $stat;
    }
}
if (!empty($statList)) {
    foreach ($statList['CHAIN'] as $chain) {
        foreach ($chain['CNT'] as $k => $v) {
            if (!isset($statList['CNT'][$k])) {
                $statList['CNT'][$k] = 0;
            }
            $statList['CNT'][$k] += $v;
        }
    }
    $statList['CNT']['START'] = $statList['CHAIN'][0]['CNT']['START'];
    $goalStart = 0;
Example #9
0
			{
				ksort($arPostingReiterateList);
				$arPostingReiterateList = array_values($arPostingReiterateList);
			}
		}
	}

	if(!empty($arPosting))
	{
		$statListDb = \Bitrix\Sender\PostingRecipientTable::getList(array(
			'select' => array(
				'STATUS', 'CNT', 'READ_CNT', 'CLICK_CNT', 'UNSUB_CNT'
			),
			'filter' => array('POSTING_ID' => $arPosting['ID']),
			'runtime' => array(
				new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(DISTINCT %s)', 'ID'),
				new \Bitrix\Main\Entity\ExpressionField('READ_CNT', 'COUNT(DISTINCT %s)', 'POSTING_READ.RECIPIENT_ID'),
				new \Bitrix\Main\Entity\ExpressionField('CLICK_CNT', 'COUNT(DISTINCT %s)', 'POSTING_CLICK.RECIPIENT_ID'),
				new \Bitrix\Main\Entity\ExpressionField('UNSUB_CNT', 'COUNT(DISTINCT %s)', 'POSTING_UNSUB.RECIPIENT_ID')
			),
			//'group' => array('STATUS')
		));

		while($stat = $statListDb->fetch())
		{
			switch($stat['STATUS'])
			{
				case \Bitrix\Sender\PostingRecipientTable::SEND_RESULT_SUCCESS:
					$arStatDeliveried = $stat;
					break;
				case \Bitrix\Sender\PostingRecipientTable::SEND_RESULT_ERROR:
Example #10
0
	/**
	 * @param $data
	 * @return bool
	 * @throws \Bitrix\Main\ArgumentException
	 */
	public static function unsubscribe($data)
	{
		$result = false;

		if(isset($data['TEST']) && $data['TEST'] == 'Y')
			return true;

		$posting = null;
		if($data['RECIPIENT_ID'])
		{
			$postingDb = PostingRecipientTable::getList(array(
				'select' => array('POSTING_ID', 'POSTING_MAILING_ID' => 'POSTING.MAILING_ID'),
				'filter' => array('ID' => $data['RECIPIENT_ID'], 'EMAIL' => $data['EMAIL'])
			));
			$posting = $postingDb->fetch();
		}

		$mailingDb = MailingTable::getList(array(
			'select' => array('ID'),
			'filter' => array(
				'ID' => $data['UNSUBSCRIBE_LIST'],
			)
		));
		while($mailing = $mailingDb->fetch())
		{
			$unsub = null;

			if($posting && $posting['POSTING_MAILING_ID'] == $mailing['ID'])
			{
				$unsub = array(
					'POSTING_ID' => $posting['POSTING_ID'],
					'RECIPIENT_ID' => $data['RECIPIENT_ID'],
				);
			}
			else
			{
				$mailingPostingDb = PostingRecipientTable::getList(array(
					'select' => array('RECIPIENT_ID' => 'ID', 'POSTING_ID'),
					'filter' => array('=POSTING.MAILING_ID' => $mailing['ID'], 'EMAIL' => $data['EMAIL'])
				));
				if($mailingPosting = $mailingPostingDb->fetch())
				{
					$unsub = $mailingPosting;
				}
			}

			if(!empty($unsub))
			{
				$unsubExists = PostingUnsubTable::getRowById($unsub);
				if(!$unsubExists)
				{
					$unsubResult = PostingUnsubTable::add($unsub);
					if($unsubResult->isSuccess())
					{
						$eventData = array(
							'MAILING_ID' => $mailing['ID'],
							'RECIPIENT_ID' => $unsub['RECIPIENT_ID'],
							'EMAIL' => $data['EMAIL'],
						);
						$event = new \Bitrix\Main\Event('sender', 'OnAfterRecipientUnsub', array($eventData));
						$event->send();
					}
				}

				$result = true;
			}

			$contactDb = ContactTable::getList(array(
				'select' => array('ID'),
				'filter' => array('=EMAIL' => $data['EMAIL'])
			));
			while($contact = $contactDb->fetch())
			{
				MailingSubscriptionTable::delete(array('MAILING_ID' => $mailing['ID'], 'CONTACT_ID' => $contact['ID']));
				$result = true;
			}
		}

		return $result;
	}
Example #11
0
         $cntDivider = $arPostingReiterate['CNT'] > 0 ? $arPostingReiterate['CNT'] : 1;
         $cntDivider = $cntDivider / 100;
         $defaultDateTimeStamp = $arPostingReiterate['DATE_SENT']->getTimestamp();
         $arPostingReiterateList[$defaultDateTimeStamp] = array('date' => $arPostingReiterate['DATE_SENT']->format("d/m"), 'sent' => $arPostingReiterate['CNT'], 'read' => $arPostingReiterate['READ_CNT'], 'click' => $arPostingReiterate['CLICK_CNT'], 'unsub' => $arPostingReiterate['UNSUB_CNT'], 'sent_prsnt' => '100', 'read_prsnt' => round($arPostingReiterate['READ_CNT'] / $cntDivider, 2), 'click_prsnt' => round($arPostingReiterate['CLICK_CNT'] / $cntDivider, 2), 'unsub_prsnt' => round($arPostingReiterate['UNSUB_CNT'] / $cntDivider, 2));
     }
     if (!empty($arPostingReiterateList)) {
         if (count($arPostingReiterateList) < 2) {
             $arPostingReiterateList = array();
         } else {
             ksort($arPostingReiterateList);
             $arPostingReiterateList = array_values($arPostingReiterateList);
         }
     }
 }
 if (!empty($arPosting)) {
     $statListDb = \Bitrix\Sender\PostingRecipientTable::getList(array('select' => array('STATUS', 'CNT'), 'filter' => array('POSTING_ID' => $arPosting['ID']), 'runtime' => array(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(%s)', 'ID'))));
     while ($stat = $statListDb->fetch()) {
         $statResult['all'] += $stat['CNT'];
         switch ($stat['STATUS']) {
             case \Bitrix\Sender\PostingRecipientTable::SEND_RESULT_SUCCESS:
                 $statResult['delivered'] = $stat['CNT'];
                 break;
             case \Bitrix\Sender\PostingRecipientTable::SEND_RESULT_ERROR:
                 $statResult['error'] = $stat['CNT'];
                 break;
             case \Bitrix\Sender\PostingRecipientTable::SEND_RESULT_NONE:
                 $statResult['not_send'] = $stat['CNT'];
                 break;
         }
     }
     $statResult['all_print'] = $statResult['all'];
    }
    if (in_array($find_read, array('Y', 'N'))) {
        $arFilter['=IS_READ'] = $find_read;
    }
    if (in_array($find_click, array('Y', 'N'))) {
        $arFilter['=IS_CLICK'] = $find_click;
    }
    if (in_array($find_unsub, array('Y', 'N'))) {
        $arFilter['=IS_UNSUB'] = $find_unsub;
    }
}
if (isset($order)) {
    $order = $order == 'asc' ? 'ASC' : 'DESC';
}
$nav = new \Bitrix\Main\UI\AdminPageNavigation("nav-sender-recipient");
$recipientListDb = \Bitrix\Sender\PostingRecipientTable::getList(array('select' => array('NAME', 'EMAIL', 'CALC_IS_READ', 'CALC_IS_CLICK', 'CALC_IS_UNSUB'), 'filter' => $arFilter, 'runtime' => array(new \Bitrix\Main\Entity\ExpressionField('CALC_IS_READ', 'MAX(%s)', 'IS_READ'), new \Bitrix\Main\Entity\ExpressionField('CALC_IS_CLICK', 'MAX(%s)', 'IS_CLICK'), new \Bitrix\Main\Entity\ExpressionField('CALC_IS_UNSUB', 'MAX(%s)', 'IS_UNSUB')), 'group' => array('NAME', 'EMAIL'), 'order' => array($by => $order), 'count_total' => true, 'offset' => $nav->getOffset(), 'limit' => $nav->getLimit()));
$aContext = array();
$nav->setRecordCount($recipientListDb->getCount());
$lAdmin->setNavigation($nav, \Bitrix\Main\Localization\Loc::getMessage("rub_nav"));
$lAdmin->AddHeaders(array(array("id" => "EMAIL", "content" => GetMessage("rub_email"), "sort" => "EMAIL", "default" => true), array("id" => "NAME", "content" => GetMessage("rub_name"), "sort" => "NAME", "default" => true), array("id" => "IS_READ", "content" => GetMessage("rub_f_read"), "sort" => "IS_READ", "default" => true), array("id" => "IS_CLICK", "content" => GetMessage("rub_f_click"), "sort" => "IS_CLICK", "default" => true), array("id" => "IS_UNSUB", "content" => GetMessage("rub_f_unsub"), "sort" => "IS_UNSUB", "default" => true)));
while ($resultRow = $recipientListDb->fetch()) {
    $row =& $lAdmin->AddRow(false, $resultRow);
    $row->AddViewField("NAME", htmlspecialcharsbx($resultRow['NAME']));
    $row->AddViewField("EMAIL", htmlspecialcharsbx($resultRow['EMAIL']));
    $row->AddViewField("IS_READ", $resultRow['CALC_IS_READ'] == 'Y' ? GetMessage("POST_U_YES") : GetMessage("POST_U_NO"));
    $row->AddViewField("IS_CLICK", $resultRow['CALC_IS_CLICK'] == 'Y' ? GetMessage("POST_U_YES") : GetMessage("POST_U_NO"));
    $row->AddViewField("IS_UNSUB", $resultRow['CALC_IS_UNSUB'] == 'Y' ? GetMessage("POST_U_YES") : GetMessage("POST_U_NO"));
}
$lAdmin->AddFooter(array(array("title" => GetMessage("MAIN_ADMIN_LIST_SELECTED"), "value" => $recipientListDb->getCount()), array("counter" => true, "title" => GetMessage("MAIN_ADMIN_LIST_CHECKED"), "value" => "0")));
$lAdmin->AddAdminContextMenu($aContext);
$lAdmin->CheckListMode();
Example #13
0
 /**
  * @param array $chain
  * @param TriggerSettings $settings
  * @param array $rpnt
  * @return void
  */
 protected static function addRecipient($chain, $settings, $rpnt)
 {
     if (!$rpnt || empty($rpnt['EMAIL'])) {
         return;
     }
     $rpnt['EMAIL'] = strtolower($rpnt['EMAIL']);
     // check email to unsubscription
     if (Subscription::isUnsubscibed($chain['MAILING_ID'], $rpnt['EMAIL'])) {
         return;
     }
     // if this is event for child
     if (!empty($chain['PARENT_ID'])) {
         $recipientDb = PostingRecipientTable::getList(array('select' => array('ID', 'EMAIL', 'NAME', 'STATUS', 'USER_ID'), 'filter' => array('=EMAIL' => $rpnt['EMAIL'], '=POSTING.MAILING_CHAIN_ID' => $chain['ID'], '=POSTING.STATUS' => array(PostingTable::STATUS_NEW, PostingTable::STATUS_PART))));
         while ($recipient = $recipientDb->fetch()) {
             // check if event should came or didn't came
             $statusNew = null;
             if ($settings->isEventOccur() && $recipient['STATUS'] == PostingRecipientTable::SEND_RESULT_WAIT) {
                 $statusNew = PostingRecipientTable::SEND_RESULT_NONE;
             } elseif (!$settings->isEventOccur() && $recipient['STATUS'] == PostingRecipientTable::SEND_RESULT_NONE) {
                 $statusNew = PostingRecipientTable::SEND_RESULT_WAIT;
             }
             if ($statusNew !== null) {
                 $updateDb = PostingRecipientTable::update(array('ID' => $recipient['ID']), array('STATUS' => $statusNew));
                 if ($updateDb->isSuccess()) {
                 } else {
                 }
             }
         }
     } else {
         // check email to have not finished mailing
         $recipientExistsDb = PostingRecipientTable::getList(array('select' => array('ID', 'ROOT_ID', 'POSTING_ID', 'STATUS', 'POSTING_STATUS' => 'POSTING.STATUS'), 'filter' => array('=EMAIL' => $rpnt['EMAIL'], '=POSTING.MAILING_ID' => $chain['MAILING_ID'], '=STATUS' => array(PostingRecipientTable::SEND_RESULT_NONE, PostingRecipientTable::SEND_RESULT_WAIT)), 'limit' => 1));
         if ($recipientExistsDb->fetch()) {
             return;
         }
         if (static::$postingId) {
             $postingId = static::$postingId;
         } else {
             $postingAddDb = PostingTable::add(array('MAILING_ID' => $chain['MAILING_ID'], 'MAILING_CHAIN_ID' => $chain['ID']));
             if (!$postingAddDb->isSuccess()) {
                 return;
             }
             $postingId = $postingAddDb->getId();
             static::$postingId = $postingId;
         }
         $recipient = array('EMAIL' => $rpnt['EMAIL'], 'POSTING_ID' => $postingId);
         if (!empty($rpnt['NAME'])) {
             $recipient['NAME'] = $rpnt['NAME'];
         }
         if (!empty($rpnt['USER_ID'])) {
             $recipient['USER_ID'] = $rpnt['USER_ID'];
         }
         if (is_array($rpnt['FIELDS']) && count($rpnt['FIELDS']) > 0) {
             $recipient['FIELDS'] = $rpnt['FIELDS'];
         }
         $addDb = PostingRecipientTable::add($recipient);
         if ($addDb->isSuccess()) {
         } else {
         }
     }
 }
Example #14
0
 public static function updatePostingReadCounters($type)
 {
     $dataDb = \Bitrix\Sender\PostingRecipientTable::getList(array('select' => array('POSTING_ID', 'CNT'), 'filter' => array('=UPDATE_POSTING.COUNT_' . $type => 0, '>CNT' => 0, '=IS_' . $type => 'Y'), 'runtime' => array(new \Bitrix\Main\Entity\ReferenceField('UPDATE_POSTING', 'Bitrix\\Sender\\PostingTable', array('=this.POSTING_ID' => 'ref.ID'), array('join_type' => 'INNER')), new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(%s)', 'ID')), 'order' => array('CNT' => 'DESC', 'POSTING_ID' => 'ASC')));
     while ($item = $dataDb->fetch()) {
         if (self::isTimeUp()) {
             return true;
         }
         \Bitrix\Sender\PostingTable::update(array('ID' => $item['POSTING_ID']), array('COUNT_' . $type => $item['CNT']));
     }
     return false;
 }