Вариант, если нужно ограничить все триггерные рассылки по принадлежности юзера к группе пользователей
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('sender', 'OnBeforePostingSendRecipient', ['SenderEvents', 'OnBeforePostingSendRecipient']);
class SenderEvents {
const USER_GROUP_DILLER_ID = 1;
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters()[0];
$isUserDiller = self::userInGroup($parameters['FIELDS']['USER_ID'], self::USER_GROUP_DILLER_ID);
if($isUserDiller) {
$parameters['FIELDS']['EMAIL_TO'] = '';
}
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
private static function userInGroup(int $userId = 0, $userGroupsId = []) {
if($userId && $userGroupsId) {
$userGroupsId = (array) $userGroupsId;
$userGroups = CUser::GetUserGroup($userId);
return array_intersect($userGroups, $userGroupsId) ? true : false;
}
else {
return false;
}
}
}
Вариант, если нужно ограничить определенные триггеры, например "Забытая корзина"
class SenderEvents {
const USER_GROUP_DILLER_ID = 1;
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters()[0];
$mailingChainId = $parameters['MAILING_CHAIN_ID'];
$isUserDiller = self::userInGroup($parameters['FIELDS']['USER_ID'], self::USER_GROUP_DILLER_ID);
if($mailingChainId && $isUserDiller) {
$mailingTrigger = new \MailingTrigger($mailingChainId);
if($mailingTrigger->isTriggerBasketForgotten()) {
$parameters['FIELDS']['EMAIL_TO'] = '';
}
}
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
private static function userInGroup(int $userId = 0, $userGroupsId = []) {
if($userId && $userGroupsId) {
$userGroupsId = (array) $userGroupsId;
$userGroups = CUser::GetUserGroup($userId);
return array_intersect($userGroups, $userGroupsId) ? true : false;
}
else {
return false;
}
}
}
class MailingTrigger {
private $trigger;
public function __construct(int $mailingChainId) {
$this->setTrigger($mailingChainId);
}
public function getTrigger(int $mailingChainId) {
return $this->trigger;
}
private function setTrigger(int $mailingChainId) {
if(!isset($this->trigger)) {
$this->trigger = \Bitrix\Sender\MailingTriggerTable::getList([
'select' => ['ENDPOINT'],
'filter' => ['MAILING_CHAIN_ID' => $mailingChainId, 'IS_TYPE_START' => 1]
])->fetch();
}
}
public function getCode() {
return $this->trigger['ENDPOINT']['CODE'];
}
public function isTriggerBasketForgotten() {
$triggerBasketForgottenCode = \Bitrix\Sale\Sender\TriggerBasketForgotten::getCode();
return $this->getCode() == $triggerBasketForgottenCode ? true : false;
}
}