/** * @param $ar * @param bool $checkDuplicate */ public static function addRecipient($ar, $checkDuplicate = false) { $ar['EMAIL'] = trim(strtolower($ar['EMAIL'])); if (!$checkDuplicate) { $needAdd = true; } else { if (!PostingRecipientTable::getRowById(array('EMAIL' => $ar['EMAIL'], 'POSTING_ID' => $ar['POSTING_ID']))) { $needAdd = true; } else { $needAdd = false; } } if ($needAdd) { PostingRecipientTable::add($ar); } }
/** * @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 { } } }