47 return 'b_sender_mailing_chain';
57 'data_type' =>
'integer',
58 'autocomplete' =>
true,
61 'MAILING_ID' => array(
62 'data_type' =>
'integer',
66 'MESSAGE_CODE' => array(
67 'data_type' =>
'string',
69 'default_value' =>
function ()
71 return Message\iBase::CODE_MAIL;
74 'MESSAGE_ID' => array(
75 'data_type' =>
'integer',
77 'POSTING_ID' => array(
78 'data_type' =>
'integer',
81 'data_type' =>
'integer',
83 'CREATED_BY' => array(
84 'data_type' =>
'integer',
86 'DATE_INSERT' => array(
87 'data_type' =>
'datetime',
91 'data_type' =>
'string',
93 'default_value' => static::STATUS_NEW,
96 'data_type' =>
'string',
97 'default_value' =>
'N',
99 'LAST_EXECUTED' => array(
100 'data_type' =>
'datetime',
104 'data_type' =>
'string',
105 'title' =>
Loc::getMessage(
'SENDER_ENTITY_MAILING_CHAIN_FIELD_TITLE_TITLE1'),
108 'EMAIL_FROM' => array(
109 'data_type' =>
'string',
111 'title' =>
Loc::getMessage(
'SENDER_ENTITY_MAILING_CHAIN_FIELD_TITLE_EMAIL_FROM1'),
112 'validation' => array(__CLASS__,
'validateEmailForm'),
115 'data_type' =>
'string',
117 'title' =>
Loc::getMessage(
'SENDER_ENTITY_MAILING_CHAIN_FIELD_TITLE_SUBJECT')
120 'data_type' =>
'string',
122 'title' =>
Loc::getMessage(
'SENDER_ENTITY_MAILING_CHAIN_FIELD_TITLE_MESSAGE')
125 'TEMPLATE_TYPE' => array(
126 'data_type' =>
'string',
129 'TEMPLATE_ID' => array(
130 'data_type' =>
'string',
133 'IS_TRIGGER' => array(
134 'data_type' =>
'string',
136 'default_value' =>
'N',
139 'TIME_SHIFT' => array(
140 'data_type' =>
'integer',
142 'default_value' => 0,
145 'AUTO_SEND_TIME' => array(
146 'data_type' =>
'datetime',
149 'MONTHS_OF_YEAR' => array(
150 'data_type' =>
'string',
152 'DAYS_OF_MONTH' => array(
153 'data_type' =>
'string',
155 'DAYS_OF_WEEK' => array(
156 'data_type' =>
'string',
158 'TIMES_OF_DAY' => array(
159 'data_type' =>
'string',
163 'data_type' =>
'string',
166 'LINK_PARAMS' => array(
167 'data_type' =>
'string',
171 'data_type' =>
'Bitrix\Sender\MailingTable',
172 'reference' => array(
'=this.MAILING_ID' =>
'ref.ID'),
174 'CURRENT_POSTING' => array(
175 'data_type' =>
'Bitrix\Sender\PostingTable',
176 'reference' => array(
'=this.POSTING_ID' =>
'ref.ID'),
179 'data_type' =>
'Bitrix\Sender\PostingTable',
180 'reference' => array(
'=this.ID' =>
'ref.MAILING_CHAIN_ID'),
182 'ATTACHMENT' => array(
183 'data_type' =>
'Bitrix\Sender\MailingAttachmentTable',
184 'reference' => array(
'=this.ID' =>
'ref.CHAIN_ID'),
186 'CREATED_BY_USER' => array(
187 'data_type' =>
'Bitrix\Main\UserTable',
188 'reference' => array(
'=this.CREATED_BY' =>
'ref.ID'),
190 'WAITING_RECIPIENT' => array(
191 'data_type' =>
'boolean',
192 'default_value' =>
'N',
193 'values' => array(
'N',
'Y')
207 array(__CLASS__,
'checkEmail')
217 if(empty($value) || check_email($value))
220 return Loc::getMessage(
'SENDER_ENTITY_MAILING_CHAIN_VALID_EMAIL_FROM');
232 public static function copy(?
int $id): ?int
234 $dataDb = static::getList(array(
'filter' => array(
'ID' => $id)));
235 if (!$data = $dataDb->fetch())
240 $copiedDb = static::add(array(
241 'MAILING_ID' => $data[
'MAILING_ID'],
242 'EMAIL_FROM' => $data[
'EMAIL_FROM'],
243 'TITLE' => $data[
'TITLE'],
244 'SUBJECT' => $data[
'SUBJECT'],
245 'MESSAGE' => $data[
'MESSAGE'],
246 'TEMPLATE_TYPE' => $data[
'TEMPLATE_TYPE'],
247 'TEMPLATE_ID' => $data[
'TEMPLATE_ID'],
248 'PRIORITY' => $data[
'PRIORITY'],
249 'LINK_PARAMS' => $data[
'LINK_PARAMS'],
252 if (!$copiedDb->isSuccess())
256 $copiedId = $copiedDb->getId();
258 $attachmentDb = MailingAttachmentTable::getList(array(
259 'filter' => array(
'=CHAIN_ID' => $id)
261 while($attachment = $attachmentDb->fetch())
263 $copiedFileId = \CFile::copyFile($attachment[
'FILE_ID']);
269 MailingAttachmentTable::add(array(
270 'CHAIN_ID' => $copiedId,
271 'FILE_ID' => $copiedFileId
288 $chainPrimary = array(
'ID' => $mailingChainId);
289 $mailingChain = static::getRowById($chainPrimary);
296 $needAddPosting =
true;
297 if(!empty($mailingChain[
'POSTING_ID']))
299 $posting = PostingTable::getRowById(array(
'ID' => $mailingChain[
'POSTING_ID']));
304 $postingId = $mailingChain[
'POSTING_ID'];
305 $needAddPosting =
false;
319 $consentSupported =
false;
322 $consentSupported = Transport\Adapter::create($mailingChain[
'MESSAGE_CODE'])->isConsentSupported();
328 $postingAddDb = PostingTable::add(array(
329 'MAILING_ID' => $mailingChain[
'MAILING_ID'],
330 'MAILING_CHAIN_ID' => $mailingChain[
'ID'],
331 'CONSENT_SUPPORT' => $consentSupported
333 if ($postingAddDb->isSuccess())
335 $postingId = $postingAddDb->getId();
336 Model\LetterTable::update($mailingChainId, [
'POSTING_ID' => $postingId]);
340 if($postingId && $mailingChain[
'IS_TRIGGER'] !=
'Y')
344 Model\LetterTable::update($mailingChainId, [
'WAITING_RECIPIENT' =>
'Y']);
369 if(array_key_exists(
'STATUS', $data[
'fields']) || array_key_exists(
'AUTO_SEND_TIME', $data[
'fields']))
371 Runtime\Job::actualizeByLetterId($data[
'primary'][
'ID']);
374 if(isset($data[
'fields'][
'PARENT_ID']))
376 Trigger\Manager::actualizeHandlerForChild();
379 if(isset($data[
'fields'][
'IS_TRIGGER']) && $data[
'fields'][
'IS_TRIGGER'] ==
'Y')
381 MailingTable::updateChainTrigger($data[
'fields'][
'CAMPAIGN_ID']);
395 Integration\EventHandler::onBeforeUpdateLetterTable($event, $result);
408 if(array_key_exists(
'STATUS', $data[
'fields']) || array_key_exists(
'AUTO_SEND_TIME', $data[
'fields']))
410 if(array_key_exists(
'STATUS', $data[
'fields']) && $data[
'fields'][
'STATUS'] == static::STATUS_NEW)
412 static::initPosting($data[
'primary'][
'ID']);
415 Runtime\Job::actualizeByLetterId($data[
'primary'][
'ID']);
418 if(isset($data[
'fields'][
'PARENT_ID']))
420 Trigger\Manager::actualizeHandlerForChild();
435 $deleteIdList = array();
436 if(!empty($data[
'primary']))
438 $itemDb = static::getList(array(
439 'select' => array(
'ID'),
440 'filter' => $data[
'primary']
442 while($item = $itemDb->fetch())
444 $deleteIdList[] = $item[
'ID'];
448 foreach($deleteIdList as $chainId)
467 $entity = static::getEntity();
468 $connection = $entity->getConnection();
470 \CTimeZone::disable();
472 'DELETE FROM %s WHERE %s',
473 $connection->getSqlHelper()->quote($entity->getDbTableName()),
474 Query::buildFilterSql($entity, $filter)
476 $res = $connection->query($sql);
477 \CTimeZone::enable();
487 Trigger\Manager::actualizeHandlerForChild();
497 $mailingChainDb = static::getList(array(
498 'select' => array(
'ID'),
501 '=MAILING.ACTIVE' =>
'Y',
502 '=STATUS' => array(static::STATUS_NEW, static::STATUS_PAUSE),
505 $mailingChain = $mailingChainDb->fetch();
507 return !empty($mailingChain);
517 $mailingChainDb = static::getList(array(
518 'select' => array(
'ID'),
521 '=MAILING.ACTIVE' =>
'Y',
522 '=AUTO_SEND_TIME' =>
null,
524 '=STATUS' => array(static::STATUS_SEND),
527 $mailingChain = $mailingChainDb->fetch();
529 return !empty($mailingChain);
541 $mailingChainDb = static::getList(array(
542 'select' => array(
'ID'),
545 '!AUTO_SEND_TIME' =>
null,
549 $mailingChain = $mailingChainDb->fetch();
551 return !empty($mailingChain);
562 $mailingChainDb = static::getList(array(
563 'select' => array(
'POSTING_ID'),
567 '!POSTING_ID' =>
null,
568 '=STATUS' => static::STATUS_END,
571 if($mailingChain = $mailingChainDb->fetch())
573 $errorRecipientDb = PostingRecipientTable::getList(array(
574 'select' => array(
'ID'),
576 '=POSTING_ID' => $mailingChain[
'POSTING_ID'],
581 if($errorRecipientDb->fetch())
598 if(!static::canReSendErrorRecipients($id))
603 $mailingChain = static::getRowById(array(
'ID' => $id));
606 " WHERE POSTING_ID=" . intval($mailingChain[
'POSTING_ID']) .
610 static::update(array(
'ID' => $id), array(
'STATUS' => static::STATUS_SEND));
618 static::update(array(
'MAILING_ID' => $mailingId), array(
'STATUS' => static::STATUS_NEW));
641 $addressFromList = array();
642 $siteEmailDb = SiteTable::getList(array(
'select'=>array(
'EMAIL')));
643 while($siteEmail = $siteEmailDb->fetch())
645 $addressFromList[] = $siteEmail[
'EMAIL'];
650 $mainEmail = Option::get(
'main',
'email_from');
651 if (!empty($mainEmail))
652 $addressFromList[] = $mainEmail;
654 $saleEmail = Option::get(
'sale',
'order_email');
655 if(!empty($saleEmail))
656 $addressFromList[] = $saleEmail;
658 $addressFromList = array_unique($addressFromList);
659 trimArr($addressFromList,
true);
667 return $addressFromList;
675 $addressFromList = static::getDefaultEmailFromList();
676 $email = Option::get(
'sender',
'address_from');
679 $arEmail = explode(
',', $email);
680 $addressFromList = array_merge($arEmail, $addressFromList);
681 $addressFromList = array_unique($addressFromList);
682 trimArr($addressFromList,
true);
685 return $addressFromList;
693 $emailList = Option::get(
'sender',
'address_from');
696 $addressFromList = explode(
',', $emailList);
697 $addressFromList = array_merge(array($email), $addressFromList);
698 $addressFromList = array_unique($addressFromList);
699 trimArr($addressFromList,
true);
700 Option::set(
'sender',
'address_from', implode(
',', $addressFromList));
709 $addressToList = array();
710 $email = Option::get(
'sender',
'address_send_to_me');
713 $addressToList = explode(
',', $email);
714 $addressToList = array_unique($addressToList);
715 \TrimArr($addressToList,
true);
718 return $addressToList;
726 $emailList = Option::get(
'sender',
'address_send_to_me');
729 $addressToList = explode(
',', $emailList);
730 $addressToList = array_merge(array($email), $addressToList);
731 $addressToList = array_unique($addressToList);
732 trimArr($addressToList,
true);
733 Option::set(
'sender',
'address_send_to_me', implode(
',', $addressToList));
745 $resultList = array();
747 if($templateType && $templateType !==
'MAILING')
755 $filter[
'ID'] = $templateId;
757 $templateDb = static::getList(array(
758 'select' => array(
'ID',
'SUBJECT',
'MESSAGE'),
760 'order' => array(
'DATE_INSERT' =>
'DESC'),
763 while($template = $templateDb->fetch())
765 $resultList[] = array(
767 'ID' => $template[
'ID'],
768 'NAME' => $template[
'SUBJECT'],
770 'HTML' => $template[
'MESSAGE']
786 $letter =
new Letter($id);
787 return $letter->getMessage()->getConfiguration()->get(
'BODY');
815 return 'b_sender_mailing_attachment';
825 'data_type' =>
'integer',
829 'data_type' =>
'integer',
844 $entity = static::getEntity();
845 $connection = $entity->getConnection();
847 \CTimeZone::disable();
849 'DELETE FROM %s WHERE %s',
850 $connection->getSqlHelper()->quote($entity->getDbTableName()),
851 Query::buildFilterSql($entity, $filter)
853 $res = $connection->query($sql);
854 \CTimeZone::enable();
static getConnection($name="")
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
static deleteList(array $filter)
static onDelete(Entity\Event $event)
static onBeforeUpdate(Entity\Event $event)
static initPosting(?int $mailingChainId)
static deleteList(array $filter)
static getDefaultEmailFromList()
static isReadyToSend($id)
static setEmailFromToList($email)
static onAfterAdd(Entity\Event $event)
static validateEmailForm()
static onPresetTemplateList($templateType=null, $templateId=null)
static setEmailToMeList($email)
static canReSendErrorRecipients($id)
static getMessageById($id)
static getEmailToMeList()
static getEmailFromList()
static isManualSentPartly($id)
static onAfterUpdate(Entity\Event $event)
static checkEmail($value)
static onAfterDelete(Entity\Event $event)
static prepareReSendErrorRecipients($id)
static setStatusNew($mailingId)
static deleteList(array $filter)
static deleteList(array $filter)
static initGroupRecipients($postingId, $checkDuplicate=true)