Example #1
0
 /**
  * @param Entity\Event $event
  * @return Entity\EventResult
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function onDelete(Entity\Event $event)
 {
     $result = new Entity\EventResult();
     $data = $event->getParameters();
     $arId = array();
     if (array_key_exists('ID', $data['primary'])) {
         $arId[] = $data['primary']['ID'];
     } else {
         $arFilter = array();
         foreach ($data['primary'] as $primKey => $primVal) {
             $arFilter[$primKey] = $primVal;
         }
         $tableDataList = static::getList(array('select' => array('ID'), 'filter' => $arFilter));
         while ($tableData = $tableDataList->fetch()) {
             $arId[] = $tableData['ID'];
         }
     }
     foreach ($arId as $primaryId) {
         $primary = array('POSTING_ID' => $primaryId);
         PostingReadTable::delete($primary);
         PostingClickTable::delete($primary);
         PostingUnsubTable::delete($primary);
         PostingRecipientTable::delete($primary);
     }
     return $result;
 }
Example #2
0
	/**
	 * @param $recipientId
	 * @param $url
	 * @throws \Bitrix\Main\ArgumentException
	 */
	public static function click($recipientId, $url)
	{

		$postingContactPrimary = array('ID' => $recipientId);
		$recipient = PostingRecipientTable::getRowById($postingContactPrimary);
		if ($recipient && $recipient['ID'])
		{
			$read = PostingReadTable::getRowById(array(
				'POSTING_ID' => $recipient['POSTING_ID'],
				'RECIPIENT_ID' => $recipient['ID']
			));
			if ($read === null)
			{
				static::read($recipientId);
			}

			$postingDb = PostingTable::getList(array(
				'select' => array('ID'),
				'filter' => array('ID' => $recipient['POSTING_ID']),
			));
			if ($postingDb->fetch())
			{
				$fixedUrl = str_replace(
					array(
						'&bx_sender_conversion_id=' . $recipient['ID'],
						'?bx_sender_conversion_id=' . $recipient['ID']
					),
					array('', ''),
					$url
				);
				$addClickDb = PostingClickTable::add(array(
					'POSTING_ID' => $recipient['POSTING_ID'],
					'RECIPIENT_ID' => $recipient['ID'],
					'URL' => $fixedUrl
				));
				if($addClickDb->isSuccess())
				{
					// send event
					$eventData = array(
						'URL' => $url,
						'URL_FIXED' => $fixedUrl,
						'CLICK_ID' => $addClickDb->getId(),
						'RECIPIENT' => $recipient
					);
					$event = new Event('sender', 'OnAfterRecipientClick', array($eventData));
					$event->send();
				}
			}
		}
	}
Example #3
0
 /**
  * @param $recipientId
  * @param $url
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function click($recipientId, $url)
 {
     $postingContactPrimary = array('ID' => $recipientId);
     $arPostingEmail = PostingRecipientTable::getRowById($postingContactPrimary);
     if ($arPostingEmail && $arPostingEmail['ID']) {
         $arPostingRead = PostingReadTable::getRowById(array('POSTING_ID' => $arPostingEmail['POSTING_ID'], 'RECIPIENT_ID' => $arPostingEmail['ID']));
         if ($arPostingRead === null) {
             static::read($recipientId);
         }
         $postingDb = PostingTable::getList(array('select' => array('ID'), 'filter' => array('ID' => $arPostingEmail['POSTING_ID'], 'MAILING.TRACK_CLICK' => 'Y')));
         if ($postingDb->fetch()) {
             PostingClickTable::add(array('POSTING_ID' => $arPostingEmail['POSTING_ID'], 'RECIPIENT_ID' => $arPostingEmail['ID'], 'URL' => $url));
         }
     }
 }
Example #4
0
 /**
  * Do click actions
  *
  * @param $recipientId
  * @param $url
  * @return void
  * @throws \Bitrix\Main\ArgumentException
  */
 public static function click($recipientId, $url)
 {
     $postingContactPrimary = array('ID' => $recipientId);
     $recipient = PostingRecipientTable::getRowById($postingContactPrimary);
     if ($recipient && $recipient['ID']) {
         $read = PostingReadTable::getRowById(array('POSTING_ID' => $recipient['POSTING_ID'], 'RECIPIENT_ID' => $recipient['ID']));
         if ($read === null) {
             static::read($recipientId);
         }
         $postingDb = PostingTable::getList(array('select' => array('ID'), 'filter' => array('ID' => $recipient['POSTING_ID'])));
         if ($postingDb->fetch()) {
             $uri = new \Bitrix\Main\Web\Uri($url);
             $fixedUrl = $uri->deleteParams(array('bx_sender_conversion_id'))->getLocator();
             $addClickDb = PostingClickTable::add(array('POSTING_ID' => $recipient['POSTING_ID'], 'RECIPIENT_ID' => $recipient['ID'], 'URL' => $fixedUrl));
             if ($addClickDb->isSuccess()) {
                 // send event
                 $eventData = array('URL' => $url, 'URL_FIXED' => $fixedUrl, 'CLICK_ID' => $addClickDb->getId(), 'RECIPIENT' => $recipient);
                 $event = new Event('sender', 'OnAfterRecipientClick', array($eventData));
                 $event->send();
             }
         }
     }
 }
Example #5
0
 public static function updateRecipientReadCounters($type)
 {
     $params = array('select' => array('RECIPIENT_ID'), 'runtime' => array(new \Bitrix\Main\Entity\ReferenceField('UPDATE_RECIPIENT', 'Bitrix\\Sender\\PostingRecipientTable', array('=this.RECIPIENT_ID' => 'ref.ID'))), 'filter' => array('!UPDATE_RECIPIENT.ID' => null, '=UPDATE_RECIPIENT.IS_' . $type => 'N'), 'group' => array('RECIPIENT_ID'));
     $dataDb = null;
     switch ($type) {
         case 'READ':
             $dataDb = \Bitrix\Sender\PostingReadTable::getList($params);
             break;
         case 'CLICK':
             $dataDb = \Bitrix\Sender\PostingClickTable::getList($params);
             break;
         case 'UNSUB':
             $dataDb = \Bitrix\Sender\PostingUnsubTable::getList($params);
             break;
     }
     if (!$dataDb) {
         return false;
     }
     while ($item = $dataDb->fetch()) {
         if (self::isTimeUp()) {
             return true;
         }
         \Bitrix\Sender\PostingRecipientTable::update(array('ID' => $item['RECIPIENT_ID']), array('IS_' . $type => 'Y'));
     }
     return false;
 }